You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test-runner: Assert stack trace is stripped when used within test #48840
❯ npm run expected
> expected
> node expected.js
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
0 !== 1
at err (file:///Users/ethanarrowood/Documents/github/node-test-runner-assert-stack-trace/expected.js:5:16)
at file:///Users/ethanarrowood/Documents/github/node-test-runner-assert-stack-trace/expected.js:11:9
at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
at async DefaultModuleLoader.import (node:internal/modules/esm/loader:246:24)
at async loadESM (node:internal/process/esm_loader:40:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)
Actual:
❯ npm run actual
> actual
> node --test --test-reporter=./reporter.cjs test.js
Error [ERR_TEST_FAILURE]: Expected values to be strictly equal:
0 !== 1
How often does it reproduce? Is there a required condition?
Any assert failure within a test block causes issue.
What is the expected behavior? Why is that the expected behavior?
I expect to get the complete stack trace from assert in my test reporter
But also, this may not be a bug and is instead working as intended. I've noticed that the original error is available as error.cause. This solves the original issue; albeit a little confusing. Maybe all that is necessary is a documentation update.
The ERR_TEST_FAILURE error type is mostly a wrapper that the test runner uses. The built in reporter unwraps it here. Your reporter should probably do something similar.
Changing the error type to unwrap it in core would be a breaking change at this point (but could technically still be done). I think the docs are wrong too, as they currently state:
Activity
Ethan-Arrowood commentedon Jul 19, 2023
Also happens with
Ethan-Arrowood commentedon Jul 19, 2023
I think it might be this line:
node/lib/internal/errors.js
Line 1612 in c301404
causing the problem
Ethan-Arrowood commentedon Jul 19, 2023
But also, this may not be a bug and is instead working as intended. I've noticed that the original error is available as
error.cause. This solves the original issue; albeit a little confusing. Maybe all that is necessary is a documentation update.cjihrig commentedon Jul 19, 2023
The
ERR_TEST_FAILUREerror type is mostly a wrapper that the test runner uses. The built in reporter unwraps it here. Your reporter should probably do something similar.Changing the error type to unwrap it in core would be a breaking change at this point (but could technically still be done). I think the docs are wrong too, as they currently state:
But this appears to be the wrapped error.
Ethan-Arrowood commentedon Jul 19, 2023
Yeah sounds good. I'm at the same conclusion now myself after tinkering with it in core a bit. I will send a docs update to close out this issue