Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Create Llama
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Create Llama
Commits
7364f71a
Commit
7364f71a
authored
1 year ago
by
Marcus Schiesser
Browse files
Options
Downloads
Patches
Plain Diff
refactor: cleaned e2e test code
parent
52ec6c9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
e2e/basic.spec.ts
+4
-119
4 additions, 119 deletions
e2e/basic.spec.ts
e2e/utils.ts
+118
-0
118 additions, 0 deletions
e2e/utils.ts
with
122 additions
and
119 deletions
e2e/basic.spec.ts
+
4
−
119
View file @
7364f71a
/* eslint-disable turbo/no-undeclared-env-vars */
/* eslint-disable turbo/no-undeclared-env-vars */
import
{
expect
,
test
}
from
"
@playwright/test
"
;
import
{
expect
,
test
}
from
"
@playwright/test
"
;
import
{
ChildProcess
,
exec
}
from
"
child_process
"
;
import
{
execSync
}
from
"
node:child_process
"
;
import
crypto
from
"
node:crypto
"
;
import
{
mkdir
}
from
"
node:fs/promises
"
;
import
{
fileURLToPath
}
from
"
node:url
"
;
import
waitPort
from
"
wait-port
"
;
import
type
{
import
type
{
TemplateEngine
,
TemplateEngine
,
TemplateFramework
,
TemplateFramework
,
TemplateType
,
TemplateType
,
TemplateUI
,
TemplateUI
,
}
from
"
../templates
"
;
}
from
"
../templates
"
;
import
{
createTestDir
,
runApp
,
runCreateLlama
,
type
AppType
}
from
"
./utils
"
;
let
cwd
:
string
;
test
.
beforeEach
(
async
()
=>
{
cwd
=
fileURLToPath
(
new
URL
(
`.cache/
${
crypto
.
randomUUID
()}
`
,
import
.
meta
.
url
),
);
await
mkdir
(
cwd
,
{
recursive
:
true
});
});
type
AppType
=
"
--frontend
"
|
"
--no-frontend
"
|
""
;
const
templateTypes
:
TemplateType
[]
=
[
"
streaming
"
];
const
templateTypes
:
TemplateType
[]
=
[
"
streaming
"
];
const
templateFrameworks
:
TemplateFramework
[]
=
[
"
express
"
];
const
templateFrameworks
:
TemplateFramework
[]
=
[
"
express
"
];
const
templateEngines
:
TemplateEngine
[]
=
[
"
simple
"
];
const
templateEngines
:
TemplateEngine
[]
=
[
"
simple
"
];
const
templateUIs
:
TemplateUI
[]
=
[
"
html
"
];
const
templateUIs
:
TemplateUI
[]
=
[
"
html
"
];
const
MODEL
=
"
gpt-3.5-turbo
"
;
for
(
const
templateType
of
templateTypes
)
{
for
(
const
templateType
of
templateTypes
)
{
for
(
const
templateFramework
of
templateFrameworks
)
{
for
(
const
templateFramework
of
templateFrameworks
)
{
...
@@ -44,7 +28,9 @@ for (const templateType of templateTypes) {
...
@@ -44,7 +28,9 @@ for (const templateType of templateTypes) {
test
(
`try create-llama
${
templateType
}
${
templateFramework
}
${
templateEngine
}
${
templateUI
}
${
appType
}
`
,
async
({
test
(
`try create-llama
${
templateType
}
${
templateFramework
}
${
templateEngine
}
${
templateUI
}
${
appType
}
`
,
async
({
page
,
page
,
})
=>
{
})
=>
{
const
cwd
=
await
createTestDir
();
const
name
=
runCreateLlama
(
const
name
=
runCreateLlama
(
cwd
,
templateType
,
templateType
,
templateFramework
,
templateFramework
,
templateEngine
,
templateEngine
,
...
@@ -53,7 +39,7 @@ for (const templateType of templateTypes) {
...
@@ -53,7 +39,7 @@ for (const templateType of templateTypes) {
);
);
const
port
=
Math
.
floor
(
Math
.
random
()
*
10000
)
+
10000
;
const
port
=
Math
.
floor
(
Math
.
random
()
*
10000
)
+
10000
;
const
cps
=
await
runApp
(
name
,
appType
,
port
);
const
cps
=
await
runApp
(
cwd
,
name
,
appType
,
port
);
// test frontend
// test frontend
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
...
@@ -66,104 +52,3 @@ for (const templateType of templateTypes) {
...
@@ -66,104 +52,3 @@ for (const templateType of templateTypes) {
}
}
}
}
}
}
async
function
runApp
(
name
:
string
,
appType
:
AppType
,
port
:
number
,
):
Promise
<
ChildProcess
[]
>
{
const
cps
=
[];
try
{
switch
(
appType
)
{
case
"
--no-frontend
"
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/backend`
,
port
),
);
break
;
case
"
--frontend
"
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/backend`
,
port
+
1
,
),
);
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/frontend`
,
port
),
);
break
;
default
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
`
,
port
));
break
;
}
}
catch
(
e
)
{
cps
.
forEach
((
cp
)
=>
cp
.
kill
());
throw
e
;
}
return
cps
;
}
async
function
createProcess
(
command
:
string
,
cwd
:
string
,
port
:
number
)
{
const
cp
=
exec
(
command
,
{
cwd
,
env
:
{
...
process
.
env
,
PORT
:
`
${
port
}
`
,
},
});
if
(
!
cp
)
throw
new
Error
(
`Can't start process
${
command
}
in
${
cwd
}
`
);
await
waitPort
({
host
:
"
localhost
"
,
port
,
timeout
:
1000
*
60
,
});
return
cp
;
}
function
runCreateLlama
(
templateType
:
string
,
templateFramework
:
string
,
templateEngine
:
string
,
templateUI
:
string
,
appType
:
AppType
,
)
{
const
createLlama
=
fileURLToPath
(
new
URL
(
"
../dist/index.js
"
,
import
.
meta
.
url
),
);
const
name
=
[
templateType
,
templateFramework
,
templateEngine
,
templateUI
,
appType
,
].
join
(
"
-
"
);
const
command
=
[
"
node
"
,
createLlama
,
name
,
"
--template
"
,
templateType
,
"
--framework
"
,
templateFramework
,
"
--engine
"
,
templateEngine
,
"
--ui
"
,
templateUI
,
"
--model
"
,
MODEL
,
"
--open-ai-key
"
,
"
testKey
"
,
// TODO: pass in OPEN_AI_KEY from CI env if needed for tests
appType
,
"
--eslint
"
,
"
--use-npm
"
,
].
join
(
"
"
);
console
.
log
(
`running command '
${
command
}
' in
${
cwd
}
`
);
execSync
(
command
,
{
stdio
:
"
inherit
"
,
cwd
,
});
return
name
;
}
This diff is collapsed.
Click to expand it.
e2e/utils.ts
0 → 100644
+
118
−
0
View file @
7364f71a
import
{
ChildProcess
,
exec
,
execSync
}
from
"
child_process
"
;
import
crypto
from
"
node:crypto
"
;
import
{
mkdir
}
from
"
node:fs/promises
"
;
import
{
fileURLToPath
}
from
"
node:url
"
;
import
waitPort
from
"
wait-port
"
;
export
type
AppType
=
"
--frontend
"
|
"
--no-frontend
"
|
""
;
const
MODEL
=
"
gpt-3.5-turbo
"
;
export
async
function
runApp
(
cwd
:
string
,
name
:
string
,
appType
:
AppType
,
port
:
number
,
):
Promise
<
ChildProcess
[]
>
{
const
cps
=
[];
try
{
switch
(
appType
)
{
case
"
--no-frontend
"
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/backend`
,
port
),
);
break
;
case
"
--frontend
"
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/backend`
,
port
+
1
,
),
);
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
/frontend`
,
port
),
);
break
;
default
:
cps
.
push
(
await
createProcess
(
"
npm run dev
"
,
`
${
cwd
}
/
${
name
}
`
,
port
));
break
;
}
}
catch
(
e
)
{
cps
.
forEach
((
cp
)
=>
cp
.
kill
());
throw
e
;
}
return
cps
;
}
async
function
createProcess
(
command
:
string
,
cwd
:
string
,
port
:
number
)
{
const
cp
=
exec
(
command
,
{
cwd
,
env
:
{
...
process
.
env
,
PORT
:
`
${
port
}
`
,
},
});
if
(
!
cp
)
throw
new
Error
(
`Can't start process
${
command
}
in
${
cwd
}
`
);
await
waitPort
({
host
:
"
localhost
"
,
port
,
timeout
:
1000
*
60
,
});
return
cp
;
}
export
function
runCreateLlama
(
cwd
:
string
,
templateType
:
string
,
templateFramework
:
string
,
templateEngine
:
string
,
templateUI
:
string
,
appType
:
AppType
,
)
{
const
createLlama
=
fileURLToPath
(
new
URL
(
"
../dist/index.js
"
,
import
.
meta
.
url
),
);
const
name
=
[
templateType
,
templateFramework
,
templateEngine
,
templateUI
,
appType
,
].
join
(
"
-
"
);
const
command
=
[
"
node
"
,
createLlama
,
name
,
"
--template
"
,
templateType
,
"
--framework
"
,
templateFramework
,
"
--engine
"
,
templateEngine
,
"
--ui
"
,
templateUI
,
"
--model
"
,
MODEL
,
"
--open-ai-key
"
,
"
testKey
"
,
appType
,
"
--eslint
"
,
"
--use-npm
"
,
].
join
(
"
"
);
console
.
log
(
`running command '
${
command
}
' in
${
cwd
}
`
);
execSync
(
command
,
{
stdio
:
"
inherit
"
,
cwd
,
});
return
name
;
}
export
async
function
createTestDir
()
{
const
cwd
=
fileURLToPath
(
new
URL
(
`.cache/
${
crypto
.
randomUUID
()}
`
,
import
.
meta
.
url
),
);
await
mkdir
(
cwd
,
{
recursive
:
true
});
return
cwd
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment