Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
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
LlamaIndexTS
Commits
d159bdd5
Commit
d159bdd5
authored
1 year ago
by
Marcus Schiesser
Browse files
Options
Downloads
Patches
Plain Diff
refactor: cleaned e2e test code
parent
0f2c6096
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/create-llama/e2e/basic.spec.ts
+4
-119
4 additions, 119 deletions
packages/create-llama/e2e/basic.spec.ts
packages/create-llama/e2e/utils.ts
+118
-0
118 additions, 0 deletions
packages/create-llama/e2e/utils.ts
with
122 additions
and
119 deletions
packages/create-llama/e2e/basic.spec.ts
+
4
−
119
View file @
d159bdd5
/* eslint-disable turbo/no-undeclared-env-vars */
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
{
TemplateEngine
,
TemplateFramework
,
TemplateType
,
TemplateUI
,
}
from
"
../templates
"
;
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
"
|
""
;
import
{
createTestDir
,
runApp
,
runCreateLlama
,
type
AppType
}
from
"
./utils
"
;
const
templateTypes
:
TemplateType
[]
=
[
"
streaming
"
];
const
templateFrameworks
:
TemplateFramework
[]
=
[
"
express
"
];
const
templateEngines
:
TemplateEngine
[]
=
[
"
simple
"
];
const
templateUIs
:
TemplateUI
[]
=
[
"
html
"
];
const
MODEL
=
"
gpt-3.5-turbo
"
;
for
(
const
templateType
of
templateTypes
)
{
for
(
const
templateFramework
of
templateFrameworks
)
{
...
...
@@ -44,7 +28,9 @@ for (const templateType of templateTypes) {
test
(
`try create-llama
${
templateType
}
${
templateFramework
}
${
templateEngine
}
${
templateUI
}
${
appType
}
`
,
async
({
page
,
})
=>
{
const
cwd
=
await
createTestDir
();
const
name
=
runCreateLlama
(
cwd
,
templateType
,
templateFramework
,
templateEngine
,
...
...
@@ -53,7 +39,7 @@ for (const templateType of templateTypes) {
);
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
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
...
...
@@ -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.
packages/create-llama/e2e/utils.ts
0 → 100644
+
118
−
0
View file @
d159bdd5
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