GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: dont set exit code on todo tests · nodejs/node@00c70e1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • main
      • test_runner.js
    • test_runner
      • harness.js
      • test.js
  • test
    • fixtures/test-runner
      • todo_exit_code.js
    • parallel
      • test-runner-exit-code.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/main/test_runner.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/test_runner.js
+4-2Lines changed: 4 additions & 2 deletions
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
});
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+4-2Lines changed: 4 additions & 2 deletions
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
}
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+3-3Lines changed: 3 additions & 3 deletions
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
}
Collapse file

‎test/fixtures/test-runner/todo_exit_code.js‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
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+
});
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-runner-exit-code.js
+13Lines changed: 13 additions & 0 deletions
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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.