Skip to content
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

jest-runtime makes each module to have its own modules cache #4940

Closed
piranna opened this issue Nov 22, 2017 · 4 comments
Closed

jest-runtime makes each module to have its own modules cache #4940

piranna opened this issue Nov 22, 2017 · 4 comments

Comments

@piranna
Copy link
Contributor

piranna commented Nov 22, 2017

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Printing the content of require.cache in several files, they are shown as being isolated ones from others instead of being shared as Node.js require() function does. Jest-runtime has its own require function, and in fact this behaviour seems to be on purposse to prevent modules do side-effects, but in fact that side-effects is exactly what does the react-native-mock-render module, so it doesn't work at all.

What is the expected behavior?

require.cache being shared by all the modules as does Node.js implementation, so replacing entries on it affect the full Node.js instance.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

  "jest": {
    "collectCoverageFrom": [
      "*.js",
      "config/**/*.js",
      "scripts/*.js",
      "src/**/*.js"
    ],
    "preset": "jest-react-native",
    "setupTestFrameworkScriptFile": "./src/setupTests.js",
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "transformIgnorePatterns": [
      "node_modules/?!(react-router-native)"
    ]
  },

Jest: 21.2.1
Node.js: 9.2.0
npm: 5.5.1

@cpojer
Copy link
Member

cpojer commented Nov 23, 2017

Jest does not support require.cache. If you'd like to set a module, you can add it to setupFiles in a way that does jest.mock('module-name', () => { return moduleContents }, {virtual: true}).

@cpojer cpojer closed this as completed Nov 23, 2017
@piranna
Copy link
Contributor Author

piranna commented Nov 23, 2017

Jest does not support require.cache. If you'd like to set a module, you can add it to setupFiles in a way that does jest.mock('module-name', () => { return moduleContents }, {virtual: true}).

Thanks for the advice, I'll give it a try.

@piranna
Copy link
Contributor Author

piranna commented Nov 23, 2017

Confirmed, it works. Thank you! :-D

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants