Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
MoLow committed Jul 25, 2022
commit 693bbaaede468c4d30439dbb2620f5c514f97439
6 changes: 6 additions & 0 deletions test/fixtures/test-runner/never_ending.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const test = require('node:test');
const { setTimeout } = require('timers/promises');

test('never ending test', () => {
return setTimeout(100_000_000);
});
36 changes: 18 additions & 18 deletions test/parallel/test-runner-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { spawnSync } = require('child_process');
const { setTimeout } = require('timers/promises');
const { spawnSync, spawn } = require('child_process');

if (process.argv[2] === 'child') {
const test = require('node:test');
Expand All @@ -17,12 +16,6 @@ if (process.argv[2] === 'child') {
test('failing test', () => {
assert.strictEqual(true, false);
});
} else if (process.argv[3] === 'never_ends') {
assert.strictEqual(process.argv[3], 'never_ends');
test('never ending test', () => {
return setTimeout(100_000_000);
});
process.kill(process.pid, 'SIGINT');
} else assert.fail('unreachable');
} else {
let child = spawnSync(process.execPath, [__filename, 'child', 'pass']);
Expand All @@ -37,14 +30,21 @@ if (process.argv[2] === 'child') {
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);

child = spawnSync(process.execPath, [__filename, 'child', 'never_ends']);
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
if (common.isWindows) {
common.printSkipMessage('signals are not supported in windows');
} else {
const stdout = child.stdout.toString();
assert.match(stdout, /not ok 1 - never ending test/);
assert.match(stdout, /# cancelled 1/);
}
let stdout = '';
child = spawn(process.execPath, ['--test', fixtures.path('test-runner', 'never_ending.js')]);
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => {
if (!stdout.length) child.kill('SIGINT');
stdout += chunk;
})
child.once('exit', common.mustCall(async (code, signal) => {
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
if (common.isWindows) {
common.printSkipMessage('signals are not supported in windows');
} else {
assert.match(stdout, /not ok 1/);
assert.match(stdout, /# cancelled 1\n/);
}
}));
}