Skip to content

Commit

Permalink
fix: removed tap bail and added snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Aug 29, 2023
1 parent 5b69804 commit 6678a3b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 8 deletions.
9 changes: 2 additions & 7 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ class Test extends AsyncResource {
this.endTime = hrtime();
this.passed = false;
this.error = err;
if (bail) {
if (bail && !this.root.bailedOut) {
this.bailedOut = true;
this.root.bailedOut = true;
this.root.postRun();
}
Expand Down Expand Up @@ -582,12 +583,6 @@ class Test extends AsyncResource {
}

async run() {
if (bailedOut) {
if (this.parent !== null) {
this.parent.postRun();
}
return;
}
if (this.parent !== null) {
this.parent.activeSubtests++;
}
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/test-runner/output/bail-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Flags: --test-bail --test-reporter=tap
'use strict';
const common = require('../../../common');
const assert = require('assert');
const test = require('node:test');

test('keep error', (t) => {
assert.strictEqual(0, 1);
});

test('dont show', common.mustNotCall((t) => {
assert.strictEqual(0, 2);
}));
32 changes: 32 additions & 0 deletions test/fixtures/test-runner/output/bail-error.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TAP version 13
not ok 1 - keep error
---
duration_ms: *
location: '/test/fixtures/test-runner/output/bail-error.js:(LINE):1'
failureType: 'testCodeFailure'
error: |-
Expected values to be strictly equal:

0 !== 1

code: 'ERR_ASSERTION'
name: 'AssertionError'
expected: 1
actual: 0
operator: 'strictEqual'
stack: |-
*
*
*
*
*
...
1..2
# tests 2
# suites 0
# pass 0
# fail 1
# cancelled 1
# skipped 0
# todo 0
# duration_ms *
2 changes: 1 addition & 1 deletion test/fixtures/test-runner/output/bail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --test --test-bail
// Flags: --test-bail --test-reporter=tap
'use strict';
const common = require('../../../common');
const test = require('node:test');
Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/test-runner/output/bail.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
TAP version 13
# Subtest: nested
# Subtest: first
ok 1 - first
---
duration_ms: *
...
not ok 2 - second
---
duration_ms: *
location: '/test/fixtures/test-runner/output/bail.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
1..3
not ok 1 - nested
---
duration_ms: *
location: '/test/fixtures/test-runner/output/bail.js:(LINE):1'
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
...
1..2
# tests 5
# suites 0
# pass 1
# fail 2
# cancelled 2
# skipped 0
# todo 0
# duration_ms *
2 changes: 2 additions & 0 deletions test/parallel/test-runner-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const tests = [
replaceTestDuration,
),
},
{ name: 'test-runner/output/bail.js', tty: true },
{ name: 'test-runner/output/bail-error.js', tty: true },
]
.filter(Boolean)
.map(({ name, tty, transform }) => ({
Expand Down

0 comments on commit 6678a3b

Please sign in to comment.