(
procs: ReadonlyArray<{
readonly cmd: string;
readonly args: ReadonlyArray<string>;
readonly cwd: string;
readonly env?: Record<string, string | undefined>;
/** Append stdout+stderr here (long-lived boots need inspectable logs). */
readonly logFile?: string;
}>,
options: { readonly label: string },
)
| 66 | }; |
| 67 | |
| 68 | export const bootProcesses = ( |
| 69 | procs: ReadonlyArray<{ |
| 70 | readonly cmd: string; |
| 71 | readonly args: ReadonlyArray<string>; |
| 72 | readonly cwd: string; |
| 73 | readonly env?: Record<string, string | undefined>; |
| 74 | /** Append stdout+stderr here (long-lived boots need inspectable logs). */ |
| 75 | readonly logFile?: string; |
| 76 | }>, |
| 77 | options: { readonly label: string }, |
| 78 | ): MonitoredBootedProcesses => { |
| 79 | const children: ChildProcess[] = []; |
| 80 | let tearingDown = false; |
| 81 | const unexpectedExits: Array<Promise<never>> = []; |
| 82 | for (const proc of procs) { |
| 83 | const log = proc.logFile ? openSync(proc.logFile, "a") : undefined; |
| 84 | const child = spawn(proc.cmd, [...proc.args], { |
| 85 | cwd: proc.cwd, |
| 86 | env: { ...process.env, ...proc.env }, |
| 87 | stdio: |
| 88 | log !== undefined ? ["ignore", log, log] : process.env.E2E_VERBOSE ? "inherit" : "ignore", |
| 89 | // Own process group, so teardown can signal the whole tree — `bunx vite` |
| 90 | // is a wrapper whose actual server child would otherwise outlive the |
| 91 | // kill and squat the port into the NEXT invocation's waitForHttp. |
| 92 | detached: true, |
| 93 | }); |
| 94 | if (log !== undefined) closeSync(log); |
| 95 | unexpectedExits.push( |
| 96 | new Promise<never>((_resolve, reject) => { |
| 97 | child.once("error", (cause) => { |
| 98 | if (tearingDown) return; |
| 99 | // oxlint-disable-next-line executor/no-promise-reject -- boundary: adapt the child-process error event to the startup race |
| 100 | reject( |
| 101 | new BootProcessExitError( |
| 102 | [proc.cmd, ...proc.args].join(" "), |
| 103 | child.exitCode, |
| 104 | child.signalCode, |
| 105 | `${readLogTail(proc.logFile)}\n${String(cause)}`.trim(), |
| 106 | ), |
| 107 | ); |
| 108 | }); |
| 109 | child.once("exit", (code, signal) => { |
| 110 | if (tearingDown) return; |
| 111 | const error = new BootProcessExitError( |
| 112 | [proc.cmd, ...proc.args].join(" "), |
| 113 | code, |
| 114 | signal, |
| 115 | readLogTail(proc.logFile), |
| 116 | ); |
| 117 | console.error(`[e2e:${options.label}] ${error.message}`); |
| 118 | // oxlint-disable-next-line executor/no-promise-reject -- boundary: adapt the child-process exit event to the startup race |
| 119 | reject(error); |
| 120 | }); |
| 121 | }), |
| 122 | ); |
| 123 | children.push(child); |
| 124 | } |
| 125 |
no test coverage detected