Giter Site home page Giter Site logo

jest-hoisting-bug-demo's Introduction

jest-hoisting-bug-demo

React Native Lerna Jest Hoist Bug

Found: React Native cannot resolve dependencies when attempting to run Jest tests in a hoisted monorepo

Dependency Version
Node v8.9.1
NPM 5.5.1
Lerna 2.4.0
react-native-cli 2.0.1
react-native 0.53.3

Create repo

mkdir test
cd test
lerna init
cd packages
react-native init Foo
react-native init Bar

Verify that tests run unhoisted

at this point the init Foo/Bar has done an install without lerna and deps are installed in each package

cd Foo
ls -l node_modules
(observe that Foo has local dependencies all installed with no hoisting)
npm run test
(Foo tests pass)
cd ../Bar
ls -l node_modules
(observe that Bar has local dependencies all installed with no hoisting)
npm run test
(Bar tests pass)

Verify that things are being hoisted

(from package root)
rm -rf packages/Foo/node_modules
rm -rf packages/Bar/node_modules
(add   "hoist": true, to your lerna.json)
lerna bootstrap
ls -l node_modules
ls -l packages/Foo/node_modules
ls -l packages/Bar/node_modules
(observe that everything has been hoisted as expected)

Observe that tests are now broken

cd packages/Foo
npm run test
(observe the following error)
> [email protected] test /Volumes/code/jest-hoisting-bug-demo/packages/Foo
> jest

โ— Validation Error:

  Module <rootDir>/node_modules/react-native/jest/assetFileTransformer.js in the transform option was not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

full npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/iojs', '/usr/local/bin/npm', 'run', 'test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle [email protected]~pretest: [email protected]
6 info lifecycle [email protected]~test: [email protected]
7 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~test: PATH: ***
9 verbose lifecycle [email protected]~test: CWD: /Volumes/code/jest-hoisting-bug-demo/packages/Foo
10 silly lifecycle [email protected]~test: Args: [ '-c', 'jest' ]
11 silly lifecycle [email protected]~test: Returned: code: 1  signal: null
12 info lifecycle [email protected]~test: Failed to exec test script
13 verbose stack Error: [email protected] test: `jest`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:280:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /Volumes/code/jest-hoisting-bug-demo/packages/Foo
16 verbose Darwin 17.4.0
17 verbose argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "run" "test"
18 verbose node v8.9.1
19 verbose npm  v5.5.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test: `jest`
22 error Exit status 1
23 error Failed at the [email protected] test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

jest-hoisting-bug-demo's People

Stargazers

Rishabh Sharma avatar Sibelius Seraphini avatar

Watchers

James Cloos avatar Kevin Jonson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.