Skip to content

Commit 89e8bf9

Browse files
committed
test_runner: include stack trace of uncaughtException and unhandledRejection
1 parent 950a441 commit 89e8bf9

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

lib/internal/test_runner/tap_stream.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ function jsToYaml(indent, name, value) {
187187

188188
// If the ERR_TEST_FAILURE came from an error provided by user code,
189189
// then try to unwrap the original error message and stack.
190-
if (code === 'ERR_TEST_FAILURE' && (failureType === kTestCodeFailure || failureType === kHookFailure)) {
190+
if (code === 'ERR_TEST_FAILURE' && (
191+
failureType === kTestCodeFailure || failureType === kHookFailure ||
192+
failureType === 'uncaughtException' || failureType === 'unhandledRejection'
193+
)) {
191194
errStack = cause?.stack ?? errStack;
192195
errCode = cause?.code ?? errCode;
193196
if (failureType === kTestCodeFailure) {

test/message/test_runner_describe_it.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ not ok 49 - callback async throw
418418
code: 'ERR_TEST_FAILURE'
419419
stack: |-
420420
*
421+
*
421422
...
422423
# Subtest: callback async throw after done
423424
ok 50 - callback async throw after done

test/message/test_runner_output.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,16 @@ test('rejected thenable', () => {
371371
},
372372
};
373373
});
374+
375+
376+
test('uncaughtException', async () => {
377+
await new Promise(() => {
378+
setTimeout(() => { throw new Error('foo'); });
379+
});
380+
});
381+
382+
test('unhandledRejection', async () => {
383+
await new Promise(() => {
384+
setTimeout(() => Promise.reject(new Error('bar')));
385+
});
386+
});

test/message/test_runner_output.out

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ not ok 51 - callback async throw
463463
code: 'ERR_TEST_FAILURE'
464464
stack: |-
465465
*
466+
*
466467
...
467468
# Subtest: callback async throw after done
468469
ok 52 - callback async throw after done
@@ -601,8 +602,32 @@ not ok 62 - rejected thenable
601602
error: 'custom error'
602603
code: 'ERR_TEST_FAILURE'
603604
...
605+
# Subtest: uncaughtException
606+
not ok 63 - uncaughtException
607+
---
608+
duration_ms: *
609+
failureType: 'uncaughtException'
610+
error: 'foo'
611+
code: 'ERR_TEST_FAILURE'
612+
stack: |-
613+
*
614+
*
615+
*
616+
...
617+
# Subtest: unhandledRejection
618+
not ok 64 - unhandledRejection
619+
---
620+
duration_ms: *
621+
failureType: 'unhandledRejection'
622+
error: 'bar'
623+
code: 'ERR_TEST_FAILURE'
624+
stack: |-
625+
*
626+
*
627+
*
628+
...
604629
# Subtest: invalid subtest fail
605-
not ok 63 - invalid subtest fail
630+
not ok 65 - invalid subtest fail
606631
---
607632
duration_ms: *
608633
failureType: 'parentAlreadyFinished'
@@ -611,16 +636,16 @@ not ok 63 - invalid subtest fail
611636
stack: |-
612637
*
613638
...
614-
1..63
639+
1..65
615640
# Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
616641
# Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
617642
# Warning: Test "immediate throw - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from immediate throw fail" and would have caused the test to fail, but instead triggered an uncaughtException event.
618643
# Warning: Test "immediate reject - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from immediate reject fail" and would have caused the test to fail, but instead triggered an unhandledRejection event.
619644
# Warning: Test "callback called twice in different ticks" generated asynchronous activity after the test ended. This activity created the error "Error [ERR_TEST_FAILURE]: callback invoked multiple times" and would have caused the test to fail, but instead triggered an uncaughtException event.
620645
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
621-
# tests 63
646+
# tests 65
622647
# pass 27
623-
# fail 19
648+
# fail 21
624649
# cancelled 2
625650
# skipped 10
626651
# todo 5

0 commit comments

Comments
 (0)