(
command: string,
args: Array<string>,
opts: {
cwd: string
env?: NodeJS.ProcessEnv
},
)
| 37 | } |
| 38 | |
| 39 | function runCommand( |
| 40 | command: string, |
| 41 | args: Array<string>, |
| 42 | opts: { |
| 43 | cwd: string |
| 44 | env?: NodeJS.ProcessEnv |
| 45 | }, |
| 46 | ) { |
| 47 | return new Promise<void>((resolvePromise, rejectPromise) => { |
| 48 | const child = spawn(command, args, { |
| 49 | cwd: opts.cwd, |
| 50 | env: { |
| 51 | ...process.env, |
| 52 | ...opts.env, |
| 53 | }, |
| 54 | stdio: 'pipe', |
| 55 | }) |
| 56 | |
| 57 | let stdout = '' |
| 58 | let stderr = '' |
| 59 | |
| 60 | child.stdout.on('data', (chunk) => { |
| 61 | stdout += String(chunk) |
| 62 | }) |
| 63 | |
| 64 | child.stderr.on('data', (chunk) => { |
| 65 | stderr += String(chunk) |
| 66 | }) |
| 67 | |
| 68 | child.on('error', (err) => { |
| 69 | rejectPromise(err) |
| 70 | }) |
| 71 | |
| 72 | child.on('close', (code) => { |
| 73 | if (code === 0) { |
| 74 | resolvePromise() |
| 75 | return |
| 76 | } |
| 77 | rejectPromise( |
| 78 | new Error( |
| 79 | `${command} ${args.join(' ')} failed with code ${code}\n` + |
| 80 | `stdout:\n${stdout}\n\n` + |
| 81 | `stderr:\n${stderr}`, |
| 82 | ), |
| 83 | ) |
| 84 | }) |
| 85 | }) |
| 86 | } |
| 87 | |
| 88 | function waitForServer(url: string, timeoutMs = 90_000) { |
| 89 | const started = Date.now() |
no outgoing calls
no test coverage detected