Open XantreDev opened 6 months ago
We cannot use AsyncLocalStorage
in core since it's a Node.js API. Vitest runner also runs in the browser and should have the same API surface. The best we can do is wait until the context API is standardized.
As a workaround, you can wrap it
functions yourself. You can also extend Vitest runner with runner
option or use a custom task function.
Another thing I wanted to mention is that using { expect }
from a concurrent test is required only and exclusively for snapshot testing and expect.assertions
methods.
Normally, expect
doesn't need to know the current test - it just throws an error based on the input.
So in most cases we can just use global expect. Interesting I will try to explore how to implement it in userland
Automatic expect tracking for concurrent tests
It's cumbersome and error prone to accept
expect
for each concurrent test Automatic tracking is also allows to make tests faster by using.concurrent
wrapper, without code modificationsSuggested solution
We can add opt in option to use AsyncLocalStorage for node.
Alternative
Zone.js can be also used for async context tracking, since it monkeypatches a lot of stuff - it less reliable
Additional context
No response
Validations