MCPcopy Index your code
hub / github.com/nodejs/node / runAndKill

Function runAndKill

test/parallel/test-runner-exit-code.js:9–29  ·  view source on GitHub ↗
(file, expectedTestName)

Source from the content-addressed store, hash-verified

7const { finished } = require('stream/promises');
8
9async function runAndKill(file, expectedTestName) {
10 if (common.isWindows) {
11 common.printSkipMessage(`signals are not supported in windows, skipping ${file}`);
12 return;
13 }
14 let stdout = '';
15 const child = spawn(process.execPath, ['--test', '--test-reporter=tap', file]);
16 child.stdout.setEncoding('utf8');
17 child.stdout.on('data', (chunk) => {
18 if (!stdout.length) child.kill('SIGINT');
19 stdout += chunk;
20 });
21 const [code, signal] = await once(child, 'exit');
22 await finished(child.stdout);
23 assert(stdout.startsWith('TAP version 13\n'));
24 // Verify interrupted test message
25 assert(stdout.includes(`Interrupted while running: ${expectedTestName}`),
26 `Expected output to contain interrupted test name`);
27 assert.strictEqual(signal, null);
28 assert.strictEqual(code, 1);
29}
30
31if (process.argv[2] === 'child') {
32 const test = require('node:test');

Callers 1

Calls 8

killMethod · 0.80
includesMethod · 0.80
spawnFunction · 0.70
onceFunction · 0.70
finishedFunction · 0.70
assertFunction · 0.50
setEncodingMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…