Skip to content

Commit 9136667

Browse files
MoLowRafaelGSS
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 52c9490 commit 9136667

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
@@ -58,6 +58,8 @@ if (shardOption) {
5858
}
5959

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

lib/internal/test_runner/harness.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ let reportersSetup;
191191
function getGlobalRoot() {
192192
if (!globalRoot) {
193193
globalRoot = createTestTree();
194-
globalRoot.reporter.once('test:fail', () => {
195-
process.exitCode = kGenericUserError;
194+
globalRoot.reporter.on('test:fail', (data) => {
195+
if (data.todo === undefined || data.todo === false) {
196+
process.exitCode = kGenericUserError;
197+
}
196198
});
197199
reportersSetup = setupTestReporters(globalRoot);
198200
}

lib/internal/test_runner/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ class Test extends AsyncResource {
282282
this.harness = null; // Configured on the root test by the test harness.
283283
this.mock = null;
284284
this.cancelled = false;
285-
this.skipped = !!skip;
286-
this.isTodo = !!todo;
285+
this.skipped = skip !== undefined && skip !== false;
286+
this.isTodo = todo !== undefined && todo !== false;
287287
this.startTime = null;
288288
this.endTime = null;
289289
this.passed = false;
@@ -634,7 +634,7 @@ class Test extends AsyncResource {
634634
subtest.#cancel(pendingSubtestsError);
635635
subtest.postRun(pendingSubtestsError);
636636
}
637-
if (!subtest.passed) {
637+
if (!subtest.passed && !subtest.isTodo) {
638638
failed++;
639639
}
640640
}
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
@@ -47,6 +47,19 @@ if (process.argv[2] === 'child') {
4747
assert.strictEqual(child.status, 0);
4848
assert.strictEqual(child.signal, null);
4949

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

0 commit comments

Comments
 (0)