Skip to content

Commit

Permalink
Pull latest changes from nodejs/node (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow authored Aug 22, 2022
1 parent 20a463a commit 9b04919
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/internal/test_runner/tap_stream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/5fadc389b8a9a32809adda8245ad32928623409b/lib/internal/test_runner/tap_stream.js
// https://github.com/nodejs/node/blob/0d46cf6af8977d1e2e4c4886bf0f7e0dbe76d21c/lib/internal/test_runner/tap_stream.js

'use strict'

Expand Down Expand Up @@ -171,7 +171,7 @@ function jsToYaml (indent, name, value) {
}

if (isErrorObj) {
const { kTestCodeFailure } = lazyLoadTest()
const { kTestCodeFailure, kHookFailure } = lazyLoadTest()
const {
cause,
code,
Expand All @@ -185,10 +185,12 @@ function jsToYaml (indent, name, value) {

// If the ERR_TEST_FAILURE came from an error provided by user code,
// then try to unwrap the original error message and stack.
if (code === 'ERR_TEST_FAILURE' && failureType === kTestCodeFailure) {
errMsg = cause?.message ?? errMsg
if (code === 'ERR_TEST_FAILURE' && (failureType === kTestCodeFailure || failureType === kHookFailure)) {
errStack = cause?.stack ?? errStack
errCode = cause?.code ?? errCode
if (failureType === kTestCodeFailure) {
errMsg = cause?.message ?? errMsg
}
}

result += jsToYaml(indent, 'error', errMsg)
Expand Down
13 changes: 11 additions & 2 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// https://github.com/nodejs/node/blob/5e1873e91d8ccefc5576912c24795d229455166d/lib/internal/test_runner/test.js
// https://github.com/nodejs/node/blob/0d46cf6af8977d1e2e4c4886bf0f7e0dbe76d21c/lib/internal/test_runner/test.js

'use strict'

Expand Down Expand Up @@ -694,4 +694,13 @@ class Suite extends Test {
}
}

module.exports = { kDefaultIndent, kSubtestsFailed, kTestCodeFailure, Test, Suite, ItTest }
module.exports = {
ItTest,
kCancelledByParent,
kDefaultIndent,
kHookFailure,
kSubtestsFailed,
kTestCodeFailure,
Suite,
Test
}
96 changes: 96 additions & 0 deletions test/message/test_runner_hooks.out
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ not ok 2 - before throws
failureType: 'hookFailed'
error: 'failed running before hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
...
# Subtest: after throws
# Subtest: 1
Expand All @@ -74,6 +84,16 @@ not ok 3 - after throws
failureType: 'hookFailed'
error: 'failed running after hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
...
# Subtest: beforeEach throws
# Subtest: 1
Expand All @@ -85,6 +105,15 @@ not ok 3 - after throws
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand All @@ -93,6 +122,17 @@ not ok 3 - after throws
failureType: 'hookFailed'
error: 'failed running beforeEach hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 4 - beforeEach throws
Expand All @@ -112,6 +152,15 @@ not ok 4 - beforeEach throws
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand All @@ -120,6 +169,17 @@ not ok 4 - beforeEach throws
failureType: 'hookFailed'
error: 'failed running afterEach hook'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 5 - afterEach throws
Expand Down Expand Up @@ -171,6 +231,15 @@ ok 6 - test hooks
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand All @@ -181,6 +250,15 @@ ok 6 - test hooks
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 7 - t.beforeEach throws
Expand All @@ -200,6 +278,15 @@ not ok 7 - t.beforeEach throws
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand All @@ -210,6 +297,15 @@ not ok 7 - t.beforeEach throws
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 8 - t.afterEach throws
Expand Down

0 comments on commit 9b04919

Please sign in to comment.