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 · 3 comments

Comments

Projects
None yet
2 participants
@piranna

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

This comment has been minimized.

Contributor

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 Nov 23, 2017

@piranna

This comment has been minimized.

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 piranna referenced this issue Nov 23, 2017

Closed

Mock not working #23

@piranna

This comment has been minimized.

piranna commented Nov 23, 2017

Confirmed, it works. Thank you! :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment