-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(runner): show stacktrace on test timeout error #7799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(runner): show stacktrace on test timeout error #7799
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
I just want to add that this is true only for Node (and probably Deno?), browsers evaluate stack in place (stack traces are much faster in browsers tho). This is why I wanted to reuse the error instead of overwriting the stack property |
That's true, but I was just thinking not wasting |
I created a benchmark to compare test collection time with and without
It looks like the extra cost |
const limit = Error.stackTraceLimit | ||
Error.stackTraceLimit = 15 | ||
const stackTraceError = new Error('STACK_TRACE_ERROR') | ||
Error.stackTraceLimit = limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this works like that. Since we don't access .stack
here, does stackTraceLimit
matter at all? Shouldn't it wrap .stack
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but it turns out this is actually fine based on this repro
// repro.js
console.log("[default Error.stackTraceLimit]", Error.stackTraceLimit)
function testThrow(depth) {
if (depth === 0) {
const original = Error.stackTraceLimit;
Error.stackTraceLimit = 1;
const error1 = new Error('1')
Error.stackTraceLimit = 2;
const error2 = new Error('2')
Error.stackTraceLimit = 3;
const error3 = new Error('3')
Error.stackTraceLimit = original;
return {
stack1: error1.stack,
stack2: error2.stack,
stack3: error3.stack,
}
}
return testThrow(depth - 1)
}
console.log(testThrow(10))
$ node repro.js
[default Error.stackTraceLimit] 10
{
stack1: 'Error: 1\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:7:20)',
stack2: 'Error: 2\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:9:20)\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:19:10)',
stack3: 'Error: 3\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:11:20)\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:19:10)\n' +
' at testThrow (file:///home/hiroshi/code/personal/reproductions/vitest-error-stack-perf/repro.js:19:10)'
}
The time depends on how big the stack is. The file stack is also cached for subsequent access (we don't need to parse the file and the source map multiple times). By the way, it's possible that the time is low because we already do the parsing somewhere In my tests I managed to trigger a 200ms stack access, for example, and we actually had an issue in Vitest itself that slowed down tests by 2 times when we had I just want to make sure we are all on the same page here with how Vitest deals with error stacks. In the browser, for example, we don't override the |
I think we are on the same page. My current understanding is that the error instantiation With further investigation, it's also possible that we can verify the cost of Btw, this is the version with multiple test files and collect duration seems larger (though overall test duration isn't affected much) 🤔 https://github.com/hi-ogawa/reproductions/tree/main/vitest-error-stack-perf2
|
v3.1.2 🐞 Bug Fixes Add global chai variable in vitest/globals (fix: #7474) - by @Jay-Karia in vitest-dev/vitest#7771 and vitest-dev/vitest#7474 (d9297) Prevent modifying test.exclude when same object passed in coverage.exclude - by @AriPerkkio in vitest-dev/vitest#7774 (c3751) Fix already hoisted mock - by @hi-ogawa in vitest-dev/vitest#7815 (773b1) Fix test.scoped inheritance - by @hi-ogawa in vitest-dev/vitest#7814 (db6c3) Remove pointer-events-none after resizing the left panel - by @alexprudhomme in vitest-dev/vitest#7811 (a7e77) Default to run mode when stdin is not a TTY - by @kentonv, @hi-ogawa and @sheremet-va in vitest-dev/vitest#7673 (6358f) Use happy-dom/jsdom types for envionmentOptions - by @hi-ogawa in vitest-dev/vitest#7795 (67430) browser: Fix transform error before browser server initialization - by @hi-ogawa in vitest-dev/vitest#7783 (5f762) Fix mocking from outside of root - by @hi-ogawa in vitest-dev/vitest#7789 (03f55) Scale iframe for non ui case - by @hi-ogawa in vitest-dev/vitest#6512 (c3374) coverage: await profiler calls - by @AriPerkkio in vitest-dev/vitest#7763 (795a6) Expose profiling timers - by @AriPerkkio in vitest-dev/vitest#7820 (5652b) deps: Update all non-major dependencies - in vitest-dev/vitest#7765 (7c3df) Update all non-major dependencies - in vitest-dev/vitest#7831 (15701) runner: Correctly call test hooks and teardown functions - by @sheremet-va in vitest-dev/vitest#7775 (3c00c) Show stacktrace on test timeout error - by @hi-ogawa in vitest-dev/vitest#7799 (df33b) ui: Load panel sizes from storage on initial load - by @userquin in vitest-dev/vitest#7265 (6555d) vite-node: Named export should overwrite export all - by @hi-ogawa in vitest-dev/vitest#7846 (5ba0d) Add ERR_MODULE_NOT_FOUND code error if module cannot be loaded - by @sheremet-va in vitest-dev/vitest#7776 (f9eac) 🏎 Performance browser: Improve browser parallelisation - by @sheremet-va in vitest-dev/vitest#7665 (816a5)
Description
#7502 added error stack for hooks, but I forgot to use it for test function. This still avoids unconditionally accessing
stackTraceError.stack
since that's where customprepareStackTrace
kicks in and it might be costly. It's only accessed either whenincludeTaskLocation
enabled or actually timeout error occurs.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.