Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CR
  • Loading branch information
MoLow committed Nov 6, 2022
commit c17bb82dfe655ffd3ac7a93e4cf4cdbe91ab5bf1
4 changes: 2 additions & 2 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class Test extends AsyncResource {
await afterEach();
this.pass();
} catch (err) {
await afterEach();
await PromisePrototypeThen(PromiseResolve(afterEach()), noop, noop);
if (isTestFailureError(err)) {
if (err.failureType === kTestTimeoutFailure) {
this.cancel(err);
Expand Down Expand Up @@ -767,7 +767,7 @@ class Suite extends Test {

this.pass();
} catch (err) {
await afterEach();
await PromisePrototypeThen(PromiseResolve(afterEach()), noop, noop);
if (isTestFailureError(err)) {
this.fail(err);
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/message/test_runner_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ describe('afterEach when test fails', () => {
it('2', () => {});
});

describe('afterEach throws and test fails', () => {
afterEach(() => { throw new Error('afterEach'); });
it('1', () => { throw new Error('test'); });
it('2', () => {});
});

test('test hooks', async (t) => {
const testArr = [];
t.beforeEach((t) => testArr.push('beforeEach ' + t.name));
Expand Down Expand Up @@ -124,3 +130,9 @@ test('afterEach when test fails', async (t) => {
await t.test('1', () => { throw new Error('test'); });
await t.test('2', () => {});
});

test('afterEach throws and test fails', async (t) => {
afterEach(() => { throw new Error('afterEach'); });
await t.test('1', () => { throw new Error('test'); });
await t.test('2', () => {});
});
108 changes: 101 additions & 7 deletions test/message/test_runner_hooks.out
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,53 @@ not ok 6 - afterEach when test fails
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
...
# Subtest: afterEach throws and test fails
# Subtest: 1
not ok 1 - 1
---
duration_ms: *
failureType: 'testCodeFailure'
error: 'test'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 7 - afterEach throws and test fails
---
duration_ms: *
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
...
# Subtest: test hooks
# Subtest: 1
ok 1 - 1
Expand Down Expand Up @@ -250,7 +297,7 @@ not ok 6 - afterEach when test fails
duration_ms: *
...
1..3
ok 7 - test hooks
ok 8 - test hooks
---
duration_ms: *
...
Expand Down Expand Up @@ -294,7 +341,7 @@ ok 7 - test hooks
*
...
1..2
not ok 8 - t.beforeEach throws
not ok 9 - t.beforeEach throws
---
duration_ms: *
failureType: 'subtestsFailed'
Expand Down Expand Up @@ -341,7 +388,7 @@ not ok 8 - t.beforeEach throws
*
...
1..2
not ok 9 - t.afterEach throws
not ok 10 - t.afterEach throws
---
duration_ms: *
failureType: 'subtestsFailed'
Expand Down Expand Up @@ -374,17 +421,64 @@ not ok 9 - t.afterEach throws
duration_ms: *
...
1..2
not ok 10 - afterEach when test fails
not ok 11 - afterEach when test fails
---
duration_ms: *
failureType: 'subtestsFailed'
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
...
1..10
# tests 10
# Subtest: afterEach throws and test fails
# Subtest: 1
not ok 1 - 1
---
duration_ms: *
failureType: 'testCodeFailure'
error: 'test'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
---
duration_ms: *
failureType: 'hookFailed'
error: 'failed running afterEach hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 12 - afterEach throws and test fails
---
duration_ms: *
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
...
1..12
# tests 12
# pass 2
# fail 8
# fail 10
# cancelled 0
# skipped 0
# todo 0
Expand Down