Skip to content

Commit 00c70e1

Browse files
MoLowtargos
authored andcommitted
test_runner: dont set exit code on todo tests
PR-URL: #48929 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 7e714e6 commit 00c70e1

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

lib/internal/main/test_runner.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ if (shardOption) {
5757
}
5858

5959
run({ concurrency, inspectPort, watch: getOptionValue('--watch'), setup: setupTestReporters, shard })
60-
.once('test:fail', () => {
61-
process.exitCode = 1;
60+
.on('test:fail', (data) => {
61+
if (data.todo === undefined || data.todo === false) {
62+
process.exitCode = 1;
63+
}
6264
});

lib/internal/test_runner/harness.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ let reportersSetup;
189189
function getGlobalRoot() {
190190
if (!globalRoot) {
191191
globalRoot = createTestTree();
192-
globalRoot.reporter.once('test:fail', () => {
193-
process.exitCode = 1;
192+
globalRoot.reporter.on('test:fail', (data) => {
193+
if (data.todo === undefined || data.todo === false) {
194+
process.exitCode = 1;
195+
}
194196
});
195197
reportersSetup = setupTestReporters(globalRoot);
196198
}

lib/internal/test_runner/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ class Test extends AsyncResource {
311311
this.harness = null; // Configured on the root test by the test harness.
312312
this.mock = null;
313313
this.cancelled = false;
314-
this.skipped = !!skip;
315-
this.isTodo = !!todo;
314+
this.skipped = skip !== undefined && skip !== false;
315+
this.isTodo = todo !== undefined && todo !== false;
316316
this.startTime = null;
317317
this.endTime = null;
318318
this.passed = false;
@@ -667,7 +667,7 @@ class Test extends AsyncResource {
667667
subtest.#cancel(pendingSubtestsError);
668668
subtest.postRun(pendingSubtestsError);
669669
}
670-
if (!subtest.passed) {
670+
if (!subtest.passed && !subtest.isTodo) {
671671
failed++;
672672
}
673673
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { describe, test } = require('node:test');
2+
3+
describe('suite should pass', () => {
4+
test.todo('should fail without harming suite', () => {
5+
throw new Error('Fail but not badly')
6+
});
7+
});
8+
9+
test.todo('should fail without effecting exit code', () => {
10+
throw new Error('Fail but not badly')
11+
});
12+
13+
test('empty string todo', { todo: '' }, () => {
14+
throw new Error('Fail but not badly')
15+
});

test/parallel/test-runner-exit-code.js

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ if (process.argv[2] === 'child') {
5050
assert.strictEqual(child.status, 0);
5151
assert.strictEqual(child.signal, null);
5252

53+
54+
child = spawnSync(process.execPath, [
55+
'--test',
56+
fixtures.path('test-runner', 'todo_exit_code.js'),
57+
]);
58+
assert.strictEqual(child.status, 0);
59+
assert.strictEqual(child.signal, null);
60+
const stdout = child.stdout.toString();
61+
assert.match(stdout, /# tests 3/);
62+
assert.match(stdout, /# pass 0/);
63+
assert.match(stdout, /# fail 0/);
64+
assert.match(stdout, /# todo 3/);
65+
5366
child = spawnSync(process.execPath, [__filename, 'child', 'fail']);
5467
assert.strictEqual(child.status, 1);
5568
assert.strictEqual(child.signal, null);

0 commit comments

Comments
 (0)