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
test infinate loop
  • Loading branch information
MoLow committed Jul 25, 2022
commit 1a466b570f9225f5e9701da0f83d2687077aa6c2
7 changes: 7 additions & 0 deletions test/fixtures/test-runner/never_ending_sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const test = require('node:test');

test('never ending test', () => {
while (true) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @tniessen :)


}
});
Comment thread
MoLow marked this conversation as resolved.
Outdated
Comment thread
MoLow marked this conversation as resolved.
Outdated
35 changes: 25 additions & 10 deletions test/parallel/test-runner-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { spawnSync, spawn } = require('child_process');
const { once } = require('events');
const { finished } = require('stream/promises');

async function runAndKill(file) {
let stdout = '';
child = spawn(process.execPath, ['--test', file]);
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => {
if (!stdout.length) child.kill('SIGINT');
stdout += chunk;
})
await Promise.all([once('exit'), finished(child.stdout)]);
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
return stdout;
}

if (process.argv[2] === 'child') {
const test = require('node:test');
Expand Down Expand Up @@ -30,16 +46,15 @@ if (process.argv[2] === 'child') {
assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);

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);
runAndKill(fixtures.path('test-runner', 'never_ending_sync.js')).then(common.mustCall(async (stdout) => {
if (common.isWindows) {
common.printSkipMessage('signals are not supported in windows');
} else {
assert.match(stdout, /not ok 1/);
assert.match(stdout, /# cancelled 1\n/);
}
}));
runAndKill(fixtures.path('test-runner', 'never_ending_async.js')).then(common.mustCall(async (stdout) => {
if (common.isWindows) {
common.printSkipMessage('signals are not supported in windows');
} else {
Expand Down