mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
test_runner: include stack of uncaught exceptions
PR-URL: https://github.com/nodejs/node/pull/44614 Fixes: https://github.com/nodejs/node/issues/44611 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
226d90a95a
commit
5ab3bc9419
5 files changed
+49
-7
No files matched your search
@@ -173,7 +173,7 @@ function jsToYaml(indent, name, value) {
|
||||
}
|
||||
|
||||
if (isErrorObj) {
|
||||
const { kTestCodeFailure, kHookFailure } = lazyLoadTest();
|
||||
const { kTestCodeFailure, kUnwrapErrors } = lazyLoadTest();
|
||||
const {
|
||||
cause,
|
||||
code,
|
||||
@@ -187,7 +187,7 @@ 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 || failureType === kHookFailure)) {
|
||||
if (code === 'ERR_TEST_FAILURE' && kUnwrapErrors.has(failureType)) {
|
||||
errStack = cause?.stack ?? errStack;
|
||||
errCode = cause?.code ?? errCode;
|
||||
if (failureType === kTestCodeFailure) {
|
||||
|
||||
@@ -13,6 +13,7 @@ const {
|
||||
PromiseResolve,
|
||||
ReflectApply,
|
||||
SafeMap,
|
||||
SafeSet,
|
||||
SafePromiseAll,
|
||||
SafePromiseRace,
|
||||
Symbol,
|
||||
@@ -62,6 +63,9 @@ const rootConcurrency = isTestRunner ? MathMax(cpus().length - 1, 1) : 1;
|
||||
const kShouldAbort = Symbol('kShouldAbort');
|
||||
const kRunHook = Symbol('kRunHook');
|
||||
const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']);
|
||||
const kUnwrapErrors = new SafeSet()
|
||||
.add(kTestCodeFailure).add(kHookFailure)
|
||||
.add('uncaughtException').add('unhandledRejection');
|
||||
|
||||
|
||||
function stopTest(timeout, signal) {
|
||||
@@ -727,9 +731,9 @@ module.exports = {
|
||||
ItTest,
|
||||
kCancelledByParent,
|
||||
kDefaultIndent,
|
||||
kHookFailure,
|
||||
kSubtestsFailed,
|
||||
kTestCodeFailure,
|
||||
kUnwrapErrors,
|
||||
Suite,
|
||||
Test,
|
||||
};
|
||||
@@ -418,6 +418,7 @@ not ok 49 - callback async throw
|
||||
code: 'ERR_TEST_FAILURE'
|
||||
stack: |-
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: callback async throw after done
|
||||
ok 50 - callback async throw after done
|
||||
|
||||
@@ -371,3 +371,15 @@ test('rejected thenable', () => {
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
test('unfinished test with uncaughtException', async () => {
|
||||
await new Promise(() => {
|
||||
setTimeout(() => { throw new Error('foo'); });
|
||||
});
|
||||
});
|
||||
|
||||
test('unfinished test with unhandledRejection', async () => {
|
||||
await new Promise(() => {
|
||||
setTimeout(() => Promise.reject(new Error('bar')));
|
||||
});
|
||||
});
|
||||
@@ -463,6 +463,7 @@ not ok 51 - callback async throw
|
||||
code: 'ERR_TEST_FAILURE'
|
||||
stack: |-
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: callback async throw after done
|
||||
ok 52 - callback async throw after done
|
||||
@@ -601,8 +602,32 @@ not ok 62 - rejected thenable
|
||||
error: 'custom error'
|
||||
code: 'ERR_TEST_FAILURE'
|
||||
...
|
||||
# Subtest: unfinished test with uncaughtException
|
||||
not ok 63 - unfinished test with uncaughtException
|
||||
---
|
||||
duration_ms: *
|
||||
failureType: 'uncaughtException'
|
||||
error: 'foo'
|
||||
code: 'ERR_TEST_FAILURE'
|
||||
stack: |-
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: unfinished test with unhandledRejection
|
||||
not ok 64 - unfinished test with unhandledRejection
|
||||
---
|
||||
duration_ms: *
|
||||
failureType: 'unhandledRejection'
|
||||
error: 'bar'
|
||||
code: 'ERR_TEST_FAILURE'
|
||||
stack: |-
|
||||
*
|
||||
*
|
||||
*
|
||||
...
|
||||
# Subtest: invalid subtest fail
|
||||
not ok 63 - invalid subtest fail
|
||||
not ok 65 - invalid subtest fail
|
||||
---
|
||||
duration_ms: *
|
||||
failureType: 'parentAlreadyFinished'
|
||||
@@ -611,16 +636,16 @@ not ok 63 - invalid subtest fail
|
||||
stack: |-
|
||||
*
|
||||
...
|
||||
1..63
|
||||
1..65
|
||||
# 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.
|
||||
# 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.
|
||||
# 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.
|
||||
# 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.
|
||||
# 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.
|
||||
# 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.
|
||||
# tests 63
|
||||
# tests 65
|
||||
# pass 27
|
||||
# fail 19
|
||||
# fail 21
|
||||
# cancelled 2
|
||||
# skipped 10
|
||||
# todo 5
|
||||
|
||||
Reference in new issue
Block a user