-
-
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
Lost of context between tests when using dynamic ESM import #10944
Comments
I wonder if this is the same as #9430 (comment) which I was never able to fix... It might be we need to do more stuff synchronously, at least that's what I got out of from the feedback on the upstream issue I created in Node. Similar to that issue, running with Will try to get to this soonish 👍 Although if anybody else wants to take a look that'd be great. |
Just tried to adjust Jest options with https://gitlab.com/matthieu88160/stryker-issue/-/jobs/907736980 |
Yeah, it'll keep failing sporadically. Will need to track it down and fix, it was more an observation than something to remedy the situation |
Maybe a lead for this problem: It seems the NodeEnvironment teardown method triggers the loss of context. When removing the line that triggers the context to be null or when removing the call in runTestInternal then the test is executed (when teardown is called then the failure occurred before the class import). I still have an issue with this:
|
I think this issue is caused by |
I can confirm the issue and the fact the scenario will fail even when no caching. |
Same issue here, is there some work around that you have used? What i get here is that in jest-runtime index.js line 532, const context = this._environment.getVmContext(); this function is returning null, for second test file. |
Not for now, I sadly not have time to work on it for a while.
Exactly, it was found in the initial observation. Maybe caused by the Jest tear-down process but this has to be confirmed. |
This may depend on how many tests suites you have, but I found setting I found the problem always appeared if I only had one worker, and the more workers I had, the less often it showed. |
Same issue here
were able to follow some of the instructions in the doc. after adding --experimental-vm-modules to the node jest command manually, the test passed. as I mentioned here, |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
I think this is a bug in Node, but we should track it still and verify once upstream is fixed |
Just had a user on my repo report the same problem, related to dynamic imports in my package. |
I don't think this is an issue in Jest anymore. There were issues in Node core If anybody have a reproduction, please open a new issue - I'd be happy to take a look |
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. |
🐛 Bug Report
When using dynamic imports from a class and then make use of this class in two separate test files, the VM environment context seems to be lost in one of the two files.
This lead to an Invariant error in node_modules/jest-runtime/build/index.js:2004:11 without error message due to null condition (the context is used here as a condition).
This comportment creates a test result where one test suite is successful and the other one is failing.
Already opened a thread on stack overflow for this https://stackoverflow.com/questions/65256785/nodejs-import-issue-with-jest
To Reproduce
Steps to reproduce the behavior:
Create a class with a method that will make use of the dynamic ESM
import()
keyword and execute loading test in two separate testing files.Full code with failing pipeline is available on this public Gitlab repository : https://gitlab.com/matthieu88160/stryker-issue
Expected behavior
The two test suites should succeed.
Link to repl or repo (highly encouraged)
https://stackoverflow.com/questions/65256785/nodejs-import-issue-with-jest
https://gitlab.com/matthieu88160/stryker-issue
envinfo
The text was updated successfully, but these errors were encountered: