Lost of context between tests when using dynamic ESM import
See original GitHub issue🐛 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
System:
OS: Linux 4.15 Ubuntu 20.04 LTS (Focal Fossa)
CPU: (2) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Binaries:
Node: 14.15.1 - /usr/local/bin/node
npm: 6.14.9 - /usr/local/bin/npm
npmPackages:
jest: ^26.6.3 => 26.6.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:12 (1 by maintainers)
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
I think this is a bug in Node, but we should track it still and verify once upstream is fixed