Skip to content

Commit 5ccfb8d

Browse files
cjihrigRafaelGSS
authored andcommitted
test_runner: unwrap error message in TAP reporter
The TAP reporter unwraps errors that come from user code. It was not properly unwrapping the error message when the failure originated from a test hook. This lead to difficult to debug errors when TAP output was used. This commit updates the TAP reporter to properly unwrap the error message. Fixes: #48941 PR-URL: #48942 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 60d6141 commit 5ccfb8d

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

lib/internal/test_runner/reporter/tap.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function jsToYaml(indent, name, value, seen) {
171171
}
172172

173173
if (isErrorObj) {
174-
const { kTestCodeFailure, kUnwrapErrors } = lazyLoadTest();
174+
const { kUnwrapErrors } = lazyLoadTest();
175175
const {
176176
cause,
177177
code,
@@ -198,15 +198,14 @@ function jsToYaml(indent, name, value, seen) {
198198
errStack = cause?.stack ?? errStack;
199199
errCode = cause?.code ?? errCode;
200200
errName = cause?.name ?? errName;
201+
errMsg = cause?.message ?? errMsg;
202+
201203
if (isAssertionLike(cause)) {
202204
errExpected = cause.expected;
203205
errActual = cause.actual;
204206
errOperator = cause.operator ?? errOperator;
205207
errIsAssertion = true;
206208
}
207-
if (failureType === kTestCodeFailure) {
208-
errMsg = cause?.message ?? errMsg;
209-
}
210209
}
211210

212211
result += jsToYaml(indent, 'error', errMsg, seen);

test/fixtures/test-runner/output/hooks.snapshot

+14-14
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ not ok 2 - before throws
5656
duration_ms: *
5757
type: 'suite'
5858
failureType: 'hookFailed'
59-
error: 'failed running before hook'
59+
error: 'before'
6060
code: 'ERR_TEST_FAILURE'
6161
stack: |-
6262
*
@@ -86,7 +86,7 @@ not ok 3 - after throws
8686
duration_ms: *
8787
type: 'suite'
8888
failureType: 'hookFailed'
89-
error: 'failed running after hook'
89+
error: 'after'
9090
code: 'ERR_TEST_FAILURE'
9191
stack: |-
9292
*
@@ -105,7 +105,7 @@ not ok 3 - after throws
105105
---
106106
duration_ms: *
107107
failureType: 'hookFailed'
108-
error: 'failed running beforeEach hook'
108+
error: 'beforeEach'
109109
code: 'ERR_TEST_FAILURE'
110110
stack: |-
111111
*
@@ -124,7 +124,7 @@ not ok 3 - after throws
124124
---
125125
duration_ms: *
126126
failureType: 'hookFailed'
127-
error: 'failed running beforeEach hook'
127+
error: 'beforeEach'
128128
code: 'ERR_TEST_FAILURE'
129129
stack: |-
130130
*
@@ -153,7 +153,7 @@ not ok 4 - beforeEach throws
153153
---
154154
duration_ms: *
155155
failureType: 'hookFailed'
156-
error: 'failed running afterEach hook'
156+
error: 'afterEach'
157157
code: 'ERR_TEST_FAILURE'
158158
stack: |-
159159
*
@@ -172,7 +172,7 @@ not ok 4 - beforeEach throws
172172
---
173173
duration_ms: *
174174
failureType: 'hookFailed'
175-
error: 'failed running afterEach hook'
175+
error: 'afterEach'
176176
code: 'ERR_TEST_FAILURE'
177177
stack: |-
178178
*
@@ -254,7 +254,7 @@ not ok 6 - afterEach when test fails
254254
---
255255
duration_ms: *
256256
failureType: 'hookFailed'
257-
error: 'failed running afterEach hook'
257+
error: 'afterEach'
258258
code: 'ERR_TEST_FAILURE'
259259
stack: |-
260260
*
@@ -315,7 +315,7 @@ ok 8 - test hooks
315315
---
316316
duration_ms: *
317317
failureType: 'hookFailed'
318-
error: 'failed running before hook'
318+
error: 'before'
319319
code: 'ERR_TEST_FAILURE'
320320
stack: |-
321321
*
@@ -334,7 +334,7 @@ ok 8 - test hooks
334334
---
335335
duration_ms: *
336336
failureType: 'hookFailed'
337-
error: 'failed running before hook'
337+
error: 'before'
338338
code: 'ERR_TEST_FAILURE'
339339
stack: |-
340340
*
@@ -362,7 +362,7 @@ not ok 9 - t.before throws
362362
---
363363
duration_ms: *
364364
failureType: 'hookFailed'
365-
error: 'failed running beforeEach hook'
365+
error: 'beforeEach'
366366
code: 'ERR_TEST_FAILURE'
367367
stack: |-
368368
*
@@ -381,7 +381,7 @@ not ok 9 - t.before throws
381381
---
382382
duration_ms: *
383383
failureType: 'hookFailed'
384-
error: 'failed running beforeEach hook'
384+
error: 'beforeEach'
385385
code: 'ERR_TEST_FAILURE'
386386
stack: |-
387387
*
@@ -409,7 +409,7 @@ not ok 10 - t.beforeEach throws
409409
---
410410
duration_ms: *
411411
failureType: 'hookFailed'
412-
error: 'failed running afterEach hook'
412+
error: 'afterEach'
413413
code: 'ERR_TEST_FAILURE'
414414
stack: |-
415415
*
@@ -428,7 +428,7 @@ not ok 10 - t.beforeEach throws
428428
---
429429
duration_ms: *
430430
failureType: 'hookFailed'
431-
error: 'failed running afterEach hook'
431+
error: 'afterEach'
432432
code: 'ERR_TEST_FAILURE'
433433
stack: |-
434434
*
@@ -506,7 +506,7 @@ not ok 12 - afterEach when test fails
506506
---
507507
duration_ms: *
508508
failureType: 'hookFailed'
509-
error: 'failed running afterEach hook'
509+
error: 'afterEach'
510510
code: 'ERR_TEST_FAILURE'
511511
stack: |-
512512
*

0 commit comments

Comments
 (0)