-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: AsyncLocalStorage context loss when using enterWith #13653
Comments
It's looking like this is mainly a Node.js issue, and I've got a simple non-Jest repro 1. The problem can also go away in Jest if you comment out this line -- this allows the The tl;dr: is if you:
On the Node.js side this kind of feels like a documentation issue, but also a bug in the sense that it works some of the time (depending on other stores). Based on how/where the various async operations are created, it seems like setting ALS context in a For anyone else who comes across this issue, if you want to have some automatic ALS setup for each test, Footnotes
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
29.3.1
Steps to reproduce
npm install
npm run test
Expected behavior
The tests should pass
Actual behavior
One or more tests will typically fail due to
AsyncLocalStorage
context lossAdditional context
This bug is similar to #11435 and nodejs/node#38781, but appears to have a different root cause, as it affects the latest versions of Jest and Node.js.
The tests in question (1, 2) set a store via
AsyncLocalStorage#enterWith
in abeforeEach
, and attempt to retrieve it viaAsyncLocalStorage#getStore
during the test, e.g.Observations:
runInBand
ormaxWorkers
(though in a real app's test suite it's much worse withmaxWorkers
). Based on my reading of the Jest codebase, the tests should pass, since the test execution follows thebeforeEach
hooks via a promise chain, andenterWith
should "[persist] the store through any following asynchronous calls"Based on the above, it seems the bug may be due to the interplay between Node.js's promise hooks and Jest's vm global/context injection (e.g. perhaps the Promise provided to the VM is not the "right" one, and thus the hooks don't work correctly when it is used?)
Environment
The text was updated successfully, but these errors were encountered: