What is the problem this feature will solve?
Some codebases use nested errors (via Error.cause) to provide contextual info for fixing them. In such codebases, code can throw errors with data attached to them, with layers of causes:
import test from 'node:test';
class ErrorWithData extends Error {
constructor(message?: string, data?: unknown, options?: ErrorOptions) {
super(message, options)
}
}
test('Foo', () => {
throw new ErrorWithData(
'Failed to handle message',
{ messageId: '42' },
{
cause: new Error('Because some library error', {
cause: new ErrorWithData('Operations failed', { statusCodes: [200, 200, 400] }),
}),
},
);
});
Today, node:test already can format those errors, but it folds some data:
✖ failing tests:
test at src/foo.spec.ts:1:78
✖ Foo (0.21025ms)
Error: Failed to handle message
at TestContext.<anonymous> (/Users/akorotenko/src/exn/Global_XChange/apps/az-fn-delivery-ms/src/foo.spec.ts:5:9)
at Test.runInAsyncScope (node:async_hooks:214:14)
... 2 lines matching cause stack trace ...
at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17) {
data: { messageId: '42' },
[cause]: Error: Because some library error
at TestContext.<anonymous> (/Users/akorotenko/src/exn/Global_XChange/apps/az-fn-delivery-ms/src/foo.spec.ts:9:14)
at Test.runInAsyncScope (node:async_hooks:214:14)
... 2 lines matching cause stack trace ...
at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17) {
[cause]: Error: Operations failed
at TestContext.<anonymous> (/Users/akorotenko/src/exn/Global_XChange/apps/az-fn-delivery-ms/src/foo.spec.ts:10:16)
at Test.runInAsyncScope (node:async_hooks:214:14)
at Test.run (node:internal/test_runner/test:1047:25)
at Test.start (node:internal/test_runner/test:944:17)
at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17) {
data: [Object]
}
}
}
I'd want [Object] to be expanded
What is the feature you are proposing to solve the problem?
Either allow users of node:test to configure this depth, without editing code (--test CLI option would be great), or default to Infinity depth, if you think all developers would benefit from it in tests
CLI option would be preferred over some test.setInspectDepth() or something, since in large codebase, one likely wants to have this behavior for all tests. Having to add this line in each file would be a nuisance
What alternatives have you considered?
No response
What is the problem this feature will solve?
Some codebases use nested errors (via Error.cause) to provide contextual info for fixing them. In such codebases, code can throw errors with data attached to them, with layers of causes:
Today, node:test already can format those errors, but it folds some data:
I'd want [Object] to be expanded
What is the feature you are proposing to solve the problem?
Either allow users of node:test to configure this depth, without editing code (
--testCLI option would be great), or default toInfinitydepth, if you think all developers would benefit from it in testsCLI option would be preferred over some
test.setInspectDepth()or something, since in large codebase, one likely wants to have this behavior for all tests. Having to add this line in each file would be a nuisanceWhat alternatives have you considered?
No response