Skip to content

Commit 524eaf5

Browse files
MoLowdanielleadams
authored andcommitted
test_runner: fix reconstruction of errors extracted from YAML
PR-URL: #46872 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 0f33bb0 commit 524eaf5

7 files changed

+26
-1
lines changed

lib/internal/test_runner/reporter/tap.js

+6
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ function jsToYaml(indent, name, value) {
195195
actual,
196196
operator,
197197
stack,
198+
name,
198199
} = value;
199200
let errMsg = message ?? '<unknown error>';
201+
let errName = name;
200202
let errStack = stack;
201203
let errCode = code;
202204
let errExpected = expected;
@@ -209,6 +211,7 @@ function jsToYaml(indent, name, value) {
209211
if (code === 'ERR_TEST_FAILURE' && kUnwrapErrors.has(failureType)) {
210212
errStack = cause?.stack ?? errStack;
211213
errCode = cause?.code ?? errCode;
214+
errName = cause?.name ?? errName;
212215
if (isAssertionLike(cause)) {
213216
errExpected = cause.expected;
214217
errActual = cause.actual;
@@ -225,6 +228,9 @@ function jsToYaml(indent, name, value) {
225228
if (errCode) {
226229
result += jsToYaml(indent, 'code', errCode);
227230
}
231+
if (errName && errName !== 'Error') {
232+
result += jsToYaml(indent, 'name', errName);
233+
}
228234

229235
if (errIsAssertion) {
230236
result += jsToYaml(indent, 'expected', errExpected);

lib/internal/test_runner/yaml_to_js.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ function reConstructError(parsedYaml) {
4242
} else {
4343
// eslint-disable-next-line no-restricted-syntax
4444
cause = new Error(parsedYaml.error);
45+
}
46+
const name = parsedYaml.name ?? 'Error';
47+
cause.stack = `${name}: ${parsedYaml.error}\n${stack}`;
48+
49+
if (!isAssertionError && !isTestFailure) {
4550
cause.code = parsedYaml.code;
4651
}
47-
cause.stack = stack;
4852

4953
if (isTestFailure) {
5054
error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType);

test/message/test_runner_abort.out

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ TAP version 13
4343
failureType: 'testAborted'
4444
error: 'This operation was aborted'
4545
code: 20
46+
name: 'AbortError'
4647
stack: |-
4748
*
4849
*
@@ -62,6 +63,7 @@ TAP version 13
6263
failureType: 'testAborted'
6364
error: 'This operation was aborted'
6465
code: 20
66+
name: 'AbortError'
6567
stack: |-
6668
*
6769
*
@@ -81,6 +83,7 @@ TAP version 13
8183
failureType: 'testAborted'
8284
error: 'This operation was aborted'
8385
code: 20
86+
name: 'AbortError'
8487
stack: |-
8588
*
8689
*
@@ -100,6 +103,7 @@ not ok 1 - promise timeout signal
100103
failureType: 'testAborted'
101104
error: 'The operation was aborted due to timeout'
102105
code: 23
106+
name: 'TimeoutError'
103107
stack: |-
104108
*
105109
*
@@ -113,6 +117,7 @@ not ok 2 - promise abort signal
113117
failureType: 'testAborted'
114118
error: 'This operation was aborted'
115119
code: 20
120+
name: 'AbortError'
116121
stack: |-
117122
*
118123
*
@@ -168,6 +173,7 @@ not ok 2 - promise abort signal
168173
failureType: 'testAborted'
169174
error: 'This operation was aborted'
170175
code: 20
176+
name: 'AbortError'
171177
stack: |-
172178
*
173179
*
@@ -187,6 +193,7 @@ not ok 2 - promise abort signal
187193
failureType: 'testAborted'
188194
error: 'This operation was aborted'
189195
code: 20
196+
name: 'AbortError'
190197
stack: |-
191198
*
192199
*
@@ -206,6 +213,7 @@ not ok 2 - promise abort signal
206213
failureType: 'testAborted'
207214
error: 'This operation was aborted'
208215
code: 20
216+
name: 'AbortError'
209217
stack: |-
210218
*
211219
*
@@ -225,6 +233,7 @@ not ok 3 - callback timeout signal
225233
failureType: 'testAborted'
226234
error: 'The operation was aborted due to timeout'
227235
code: 23
236+
name: 'TimeoutError'
228237
stack: |-
229238
*
230239
*
@@ -238,6 +247,7 @@ not ok 4 - callback abort signal
238247
failureType: 'testAborted'
239248
error: 'This operation was aborted'
240249
code: 20
250+
name: 'AbortError'
241251
stack: |-
242252
*
243253
*

test/message/test_runner_abort_suite.out

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ not ok 1 - describe timeout signal
6767
failureType: 'testAborted'
6868
error: 'The operation was aborted due to timeout'
6969
code: 23
70+
name: 'TimeoutError'
7071
stack: |-
7172
*
7273
*
@@ -80,6 +81,7 @@ not ok 2 - describe abort signal
8081
failureType: 'testAborted'
8182
error: 'This operation was aborted'
8283
code: 20
84+
name: 'AbortError'
8385
stack: |-
8486
*
8587
*

test/message/test_runner_describe_it.out

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ not ok 14 - async assertion fail
122122
true !== false
123123

124124
code: 'ERR_ASSERTION'
125+
name: 'AssertionError'
125126
expected: false
126127
actual: true
127128
operator: 'strictEqual'

test/message/test_runner_output.out

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ not ok 13 - async assertion fail
126126
true !== false
127127

128128
code: 'ERR_ASSERTION'
129+
name: 'AssertionError'
129130
expected: false
130131
actual: true
131132
operator: 'strictEqual'

test/message/test_runner_output_cli.out

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ not ok 13 - async assertion fail
126126
true !== false
127127

128128
code: 'ERR_ASSERTION'
129+
name: 'AssertionError'
129130
expected: false
130131
actual: true
131132
operator: 'strictEqual'

0 commit comments

Comments
 (0)