-
-
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
Persist require.cache after globalSetup #6066
Comments
Jest implements its own |
So there is absolutely no way to achieve this with jest, not even any workarounds? |
Correct. It's meant to be used to e.g. setup a database (not a database connection) or start a browser (but not connect to it). Those things should be done per test (e.g. |
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. |
What is the current behaviour?
When requiring and bootstrapping a node module (singleton in my case) during the
globalSetup
likerequire('some-node-module')
it will be gone if I try to get the same instance in a test viarequire('some-node-module')
.Outside of jest this behaviour works perfectly fine since node.js caches any require call which makes it easy to provide the same instance of a module between multiple modules.
What is the expected behaviour?
After calling
require('some-node-module')
in theglobalSetup
all tests should have access to instance ofrequire('some-node-module')
.Please provide your exact Jest configuration
Run
npx envinfo --preset jest
in your project directory and paste theresults here
Notes
I found that jest ignores the node.js
require.cache
but is there some way to enable therequire.cache
for tests?The text was updated successfully, but these errors were encountered: