Skip to content

Commit

Permalink
test_runner: fix global after not failing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Jul 25, 2023
1 parent a0f3ed8 commit 561b855
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
8 changes: 8 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ class Test extends AsyncResource {
this.parent.processReadySubtestRange(false);
this.parent.processPendingSubtests();
} else if (!this.reported) {
if (!this.passed && failed === 0 && this.error) {
this.reporter.fail(this.nesting, kFilename, this.testNumber, this.name, {
__proto__: null,
duration_ms: this.#duration(),
error: this.error

Check failure on line 662 in lib/internal/test_runner/test.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing trailing comma
}, undefined);
}

this.reported = true;
this.reporter.plan(this.nesting, kFilename, this.root.harness.counters.topLevel);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
const { it, after } = require('node:test');

after(() => {
throw new Error('this should fail the test')
});

it('this is a test', () => {
console.log('this is a test')
});
54 changes: 24 additions & 30 deletions test/fixtures/test-runner/output/hooks-with-no-global-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,36 @@ before(() => testArr.push('global before'));
after(() => {
testArr.push('global after');

try {
assert.deepStrictEqual(testArr, [
'global before',
'describe before',
assert.deepStrictEqual(testArr, [
'global before',
'describe before',

'describe beforeEach',
'describe it 1',
'describe afterEach',
'describe beforeEach',
'describe it 1',
'describe afterEach',

'describe beforeEach',
'describe test 2',
'describe afterEach',
'describe beforeEach',
'describe test 2',
'describe afterEach',

'describe nested before',
'describe nested before',

'describe beforeEach',
'describe nested beforeEach',
'describe nested it 1',
'describe afterEach',
'describe nested afterEach',
'describe beforeEach',
'describe nested beforeEach',
'describe nested it 1',
'describe afterEach',
'describe nested afterEach',

'describe beforeEach',
'describe nested beforeEach',
'describe nested test 2',
'describe afterEach',
'describe nested afterEach',
'describe beforeEach',
'describe nested beforeEach',
'describe nested test 2',
'describe afterEach',
'describe nested afterEach',

'describe nested after',
'describe after',
'global after',
]);
} catch (e) {
// TODO(rluvaton): remove the try catch after #48867 is fixed
console.error(e);
process.exit(1);
}
'describe nested after',
'describe after',
'global after',
]);
});

describe('describe hooks with no global tests', () => {
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-runner-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const tests = [
{ name: 'test-runner/output/describe_nested.js' },
{ name: 'test-runner/output/hooks.js' },
{ name: 'test-runner/output/hooks-with-no-global-test.js' },
{ name: 'test-runner/output/global-after-should-fail-the-test.js' },
{ name: 'test-runner/output/no_refs.js' },
{ name: 'test-runner/output/no_tests.js' },
{ name: 'test-runner/output/only_tests.js' },
Expand Down

0 comments on commit 561b855

Please sign in to comment.