-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
35 lines (32 loc) · 859 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable no-undef */
import { spawn, spawnSync } from 'node:child_process'
import { join } from 'node:path'
import kill from 'tree-kill'
async function runFastApi() {
let server
try {
const pythonPath = join(process.cwd(), 'project/python/fastapi')
server = spawn('uv', ['run', 'uvicorn', 'main:app'], {
stdio: 'inherit',
cwd: pythonPath,
env: {
...process.env,
PYTHONPATH: pythonPath,
},
})
await new Promise((resolve) => setTimeout(resolve, 2000))
const result = spawnSync('pnpm', ['vitest', '--run', '--globals'], {
stdio: 'inherit',
shell: true,
})
if (result.status !== 0) console.error('test failed')
} finally {
if (server) {
kill(server.pid, 'SIGTERM')
}
}
}
await runFastApi().catch((err) => {
console.error(err)
process.exit(1)
})