Full stack traces from tests
I've noticed that stack traces emitted from tests are limited to 7ish lines. However, many errors start deeper and it's tough to find the error line from test failure reports. Is there a way to tune the number of lines emitted from the test ERRORS section?
Or ideally, could stack traces be truncated in a way that emits stack frames in files hosted in a
Deno.cwd()
dir/subdir (i.e. user's code)?5 Replies
Here is a full
error.stack
trace when I catch the error and re-throw it:
Here is the error from the test output:
I noticed that the code to abbreviate errors is in fn abbreviate_test_error(js_error: &JsError) -> JsError {
in deno/cli/tools/test/fmt.rs
. It appears to support filtering user code errors, but I wonder why it's not working for me....The documentation indicates that starting from Deno 1.21,
deno test
has been improved to filter out stack frames that are coming from Deno’s internal code and show the line of code where the error originates. This means that the stack traces for thrown errors in tests should now be more informative and focused on the user's code rather than internal Deno code.
Here's an example from the documentation showing the improved error reporting:
As you can see, the stack trace is concise and points directly to the user's code where the error was thrown.
The documentation does not mention a way to tune the number of lines emitted from the test ERRORS section or a method to truncate stack traces based on files in a specific directory like Deno.cwd()
. However, the improvements made should already provide a better testing experience by focusing on the user's code.
If you find that the stack traces are still not providing enough context for debugging, it might be worth providing feedback to the Deno team as they have expressed interest in further improving the test reporter in future releases. 🦕@smart You can set the stack trace limit by a custom value in your code:
Thanks I'll give that a try!
Hmm that's not in the typespec for me... This is a Node.js feature?
And when I add
// @ts-ignore
and set it anyway, it doesn't impact the deno test
strack trace truncation.