Skip to content

Commit 6678a3b

Browse files
fix: removed tap bail and added snapshots
1 parent 5b69804 commit 6678a3b

File tree

6 files changed

+83
-8
lines changed

6 files changed

+83
-8
lines changed

lib/internal/test_runner/test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ class Test extends AsyncResource {
503503
this.endTime = hrtime();
504504
this.passed = false;
505505
this.error = err;
506-
if (bail) {
506+
if (bail && !this.root.bailedOut) {
507+
this.bailedOut = true;
507508
this.root.bailedOut = true;
508509
this.root.postRun();
509510
}
@@ -582,12 +583,6 @@ class Test extends AsyncResource {
582583
}
583584

584585
async run() {
585-
if (bailedOut) {
586-
if (this.parent !== null) {
587-
this.parent.postRun();
588-
}
589-
return;
590-
}
591586
if (this.parent !== null) {
592587
this.parent.activeSubtests++;
593588
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Flags: --test-bail --test-reporter=tap
2+
'use strict';
3+
const common = require('../../../common');
4+
const assert = require('assert');
5+
const test = require('node:test');
6+
7+
test('keep error', (t) => {
8+
assert.strictEqual(0, 1);
9+
});
10+
11+
test('dont show', common.mustNotCall((t) => {
12+
assert.strictEqual(0, 2);
13+
}));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
TAP version 13
2+
not ok 1 - keep error
3+
---
4+
duration_ms: *
5+
location: '/test/fixtures/test-runner/output/bail-error.js:(LINE):1'
6+
failureType: 'testCodeFailure'
7+
error: |-
8+
Expected values to be strictly equal:
9+
10+
0 !== 1
11+
12+
code: 'ERR_ASSERTION'
13+
name: 'AssertionError'
14+
expected: 1
15+
actual: 0
16+
operator: 'strictEqual'
17+
stack: |-
18+
*
19+
*
20+
*
21+
*
22+
*
23+
...
24+
1..2
25+
# tests 2
26+
# suites 0
27+
# pass 0
28+
# fail 1
29+
# cancelled 1
30+
# skipped 0
31+
# todo 0
32+
# duration_ms *

test/fixtures/test-runner/output/bail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --test --test-bail
1+
// Flags: --test-bail --test-reporter=tap
22
'use strict';
33
const common = require('../../../common');
44
const test = require('node:test');
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
TAP version 13
2+
# Subtest: nested
3+
# Subtest: first
4+
ok 1 - first
5+
---
6+
duration_ms: *
7+
...
8+
not ok 2 - second
9+
---
10+
duration_ms: *
11+
location: '/test/fixtures/test-runner/output/bail.js:(LINE):5'
12+
failureType: 'cancelledByParent'
13+
error: 'test did not finish before its parent and was cancelled'
14+
code: 'ERR_TEST_FAILURE'
15+
...
16+
1..3
17+
not ok 1 - nested
18+
---
19+
duration_ms: *
20+
location: '/test/fixtures/test-runner/output/bail.js:(LINE):1'
21+
failureType: 'subtestsFailed'
22+
error: '2 subtests failed'
23+
code: 'ERR_TEST_FAILURE'
24+
...
25+
1..2
26+
# tests 5
27+
# suites 0
28+
# pass 1
29+
# fail 2
30+
# cancelled 2
31+
# skipped 0
32+
# todo 0
33+
# duration_ms *

test/parallel/test-runner-output.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ const tests = [
8888
replaceTestDuration,
8989
),
9090
},
91+
{ name: 'test-runner/output/bail.js', tty: true },
92+
{ name: 'test-runner/output/bail-error.js', tty: true },
9193
]
9294
.filter(Boolean)
9395
.map(({ name, tty, transform }) => ({

0 commit comments

Comments
 (0)