* Run the kernel's raw extraction for `file` inside a Worker with Node's * DEFAULT resourceLimits — exactly how ParseWorkerPool runs it. Resolves * with the worker's exit code and what it reported; a native overflow * would SIGSEGV/SIGILL this whole vitest process instead.
(file: string, source: string, language: Language)
| 194 | * would SIGSEGV/SIGILL this whole vitest process instead. |
| 195 | */ |
| 196 | function runInWorker(file: string, source: string, language: Language): Promise<{ exitCode: number; outcome: string }> { |
| 197 | const script = path.join(tmp, 'worker.cjs'); |
| 198 | fs.writeFileSync( |
| 199 | script, |
| 200 | [ |
| 201 | `const { parentPort, workerData } = require('worker_threads');`, |
| 202 | `const { tryKernelExtractRaw } = require(${JSON.stringify(DIST_KERNEL)});`, |
| 203 | `const raw = tryKernelExtractRaw(workerData.file, workerData.source, workerData.language);`, |
| 204 | `parentPort.postMessage(raw ? 'kernel:' + raw.counts.nodes : 'deferred');`, |
| 205 | ].join('\n') |
| 206 | ); |
| 207 | return new Promise((resolve, reject) => { |
| 208 | let outcome = 'no message'; |
| 209 | const w = new Worker(script, { workerData: { file, source, language } }); |
| 210 | w.on('message', (m: string) => { outcome = m; }); |
| 211 | w.on('error', reject); |
| 212 | w.on('exit', (exitCode) => resolve({ exitCode, outcome })); |
| 213 | }); |
| 214 | } |
| 215 | |
| 216 | it("defers the reporter's deep.c instead of crashing the worker", async () => { |
| 217 | const r = await runInWorker('deep.c', deepBraces(BRACES_DEPTH), 'c'); |
no test coverage detected