Run a script through the real relaunch; its relaunched copy ends as `how` says (a signal, or an exit code).
(how: string)
| 159 | |
| 160 | /** Run a script through the real relaunch; its relaunched copy ends as `how` says (a signal, or an exit code). */ |
| 161 | function relaunchEndingWith(how: string): { status: number | null; signal: string | null; stderr: string } { |
| 162 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-relaunch-signal-')); |
| 163 | try { |
| 164 | const harness = path.join(dir, 'harness.cjs'); |
| 165 | fs.writeFileSync(harness, [ |
| 166 | `const { relaunchWithWasmRuntimeFlagsIfNeeded } = require(${JSON.stringify(path.resolve(__dirname, '../dist/extraction/wasm-runtime-flags.js'))});`, |
| 167 | 'if (process.env.CODEGRAPH_WASM_RELAUNCHED) {', |
| 168 | ' const how = process.env.CG_TEST_RELAUNCHED_ENDS;', |
| 169 | " if (how.startsWith('SIG')) process.kill(process.pid, how); else process.exit(Number(how));", |
| 170 | '}', |
| 171 | 'relaunchWithWasmRuntimeFlagsIfNeeded(__filename);', |
| 172 | "process.stdout.write('not relaunched');", |
| 173 | ].join('\n')); |
| 174 | const env: NodeJS.ProcessEnv = { ...process.env, CG_TEST_RELAUNCHED_ENDS: how }; |
| 175 | delete env.CODEGRAPH_WASM_RELAUNCHED; |
| 176 | delete env.CODEGRAPH_NO_RELAUNCH; |
| 177 | const res = spawnSync(process.execPath, [harness], { encoding: 'utf8', env }); |
| 178 | return { status: res.status, signal: res.signal, stderr: res.stderr }; |
| 179 | } finally { |
| 180 | fs.rmSync(dir, { recursive: true, force: true }); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | it('passes an exit code through unchanged, with nothing on stderr', () => { |
| 185 | const res = relaunchEndingWith('3'); |
no test coverage detected