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

Running jest in a react-native project with symlinked node_modules doesn't work #22823

Closed
3 tasks done
nicojs opened this issue Dec 28, 2018 · 2 comments
Closed
3 tasks done
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@nicojs
Copy link

nicojs commented Dec 28, 2018

Environment

$ npx react-native info

  React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
      Memory: 4.68 GB / 15.88 GB
    Binaries:
      Yarn: 1.12.3 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

Description

Running yarn test in a react-native project where the node_modules are symlinked doesn't seem to work:

$ yarn test
yarn run v1.12.3
$ node ./node_modules/jest/bin/jest.js
 FAIL  components/__tests__/StyledText-test.js
  ● Test suite failed to run

    Cannot find module 'setupDevtools' from 'setup.js'

      at Resolver.resolveModule (../node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (../node_modules/react-native/jest/setup.js:3:6)

We want this to work, because this is how Stryker's sandboxes work. They create a temp folder inside your project, copy all source files into the sandbox dir and symlink the node_modules. Original issue here: stryker-mutator/stryker-js#717

Reproducible Demo

I've prepared a small git repository to demonstrate the problem. I've created this repository with expo init (choosing the more extensive "tab" setup). After that I've installed the latest version of react-native: yarn add react-native. After that I've created an example "sandbox" directory with a copy of all sources.
https://github.com/nicojs/jest-react-native-symlink-test

You can use these commands to reproduce the issue:

git clone https://github.com/nicojs/jest-react-native-symlink-test
cd jest-react-native-symlink-test
yarn install
yarn symlink # <-- this will symlink the node_modules under the sandbox directory
cd sandbox
yarn test
@bartolkaruza
Copy link

I think it is a known issue/design decision for Jest jestjs/jest#1477 not to follow symlinks. Checkout the workarounds at that issue for possible solutions to your problem (roots config).

@cpojer cc for the sake of it :)

@rickhanlonii
Copy link
Member

Hey @nicojs, thanks for filing!

This is being tracked in Jest in jestjs/jest#5356, there's a proposal PR in jestjs/jest#7549

@facebook facebook locked as resolved and limited conversation to collaborators Dec 31, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants