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

Enable jest mocking to work properly with npm3. #554

Closed
jezen opened this issue Oct 16, 2015 · 15 comments
Closed

Enable jest mocking to work properly with npm3. #554

jezen opened this issue Oct 16, 2015 · 15 comments
Labels

Comments

@jezen
Copy link

jezen commented Oct 16, 2015

Seeing this issue. Not sure where to begin with it.

Using Jest CLI v0.5.10
 FAIL  __tests__/editor/js/views/ElementsPanel/components/Libraries.react.test.js (1.97s)
● LibrariesComponent › it encountered a declaration exception
  - TypeError: /Users/jgt/Sites/app/node_modules/react-addons-test-utils/index.js: /Users/jgt/Sites/app/node_modules/react/lib/ReactTestUtils.js: /Users/jgt/Sites/app/node_modules/react/lib/React.js: /Users/jgt/Sites/app/node_modules/react/lib/ReactDOM.js: /Users/jgt/Sites/app/node_modules/react/lib/ReactDefaultInjection.js: /Users/jgt/Sites/app/node_modules/react/lib/BeforeInputEventPlugin.js: Cannot read property 'topCompositionEnd' of undefined
        at Object.<anonymous> (node_modules/react/lib/BeforeInputEventPlugin.js:65:33)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Object.<anonymous> (node_modules/react/lib/ReactDefaultInjection.js:14:30)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Object.<anonymous> (node_modules/react/lib/ReactDOM.js:18:29)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Object.<anonymous> (node_modules/react/lib/React.js:14:16)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Object.<anonymous> (node_modules/react/lib/ReactTestUtils.js:17:13)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Object.<anonymous> (node_modules/react-addons-test-utils/index.js:1:115)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at Loader.requireModuleOrMock (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:923:17)
        at Suite.<anonymous> (__tests__/editor/js/views/ElementsPanel/components/Libraries.react.test.js:4:19)
        at env.describe_ (evalmachine.<anonymous>:40:25)
        at env.describe (evalmachine.<anonymous>:27:19)
        at Object.<anonymous> (__tests__/editor/js/views/ElementsPanel/components/Libraries.react.test.js:3:1)
        at Object.runContentWithLocalBindings (node_modules/jest-cli/src/lib/utils.js:527:17)
        at Loader._execModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:239:9)
        at Loader.requireModule (node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:902:12)
        at jasmineTestRunner (node_modules/jest-cli/src/jasmineTestRunner/jasmineTestRunner.js:284:16)
        at node_modules/jest-cli/src/TestRunner.js:379:12
@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

Are you using npm3?

@jezen
Copy link
Author

jezen commented Oct 16, 2015

@cpojer

$ npm --version
$ 3.3.4

@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

Also see: facebook/react#5183

We don't have a good solution for this yet, unfortunately.

@cpojer cpojer changed the title Cannot read property 'topCompositionEnd' of undefined Enable jest mocking to work properly with npm3. Oct 16, 2015
@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

Manually unmocking fbjs as well as react should work for now.

@zpao
Copy link
Contributor

zpao commented Oct 16, 2015

Workarounds for React:

  1. Disable automocking entirely (suggested because fuck mocking)
  2. Disable mocking for node_modules/{react,fbjs}

@Nic128
Copy link

Nic128 commented Oct 16, 2015

Good to know 'fbjs' was the culprit. For me, even 'babel' and 'core-js' needed to be in that unmocked list.

@jezen
Copy link
Author

jezen commented Oct 16, 2015

For those confused:

I made this error go away by making my package.json look like this:

  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react",
      "<rootDir>/node_modules/fbjs",
      "<rootDir>/node_modules/react-dom",
      "<rootDir>/node_modules/react-addons-test-utils"
    ]
  },

@jermspeaks
Copy link

Thanks @jezen, I made those changes and now the tests are working fine.

@cpojer
Copy link
Member

cpojer commented Nov 13, 2015

fyi the tentative plan is to wait for Haste 2 in #599 and then I'll fix unmock patterns to be deep-unmocks when they are inside of node_modules.

@nicolasbrugneaux
Copy link

any idea of the timeline of when it'll be merged back to master? :) great job in this PR!!

@cpojer
Copy link
Member

cpojer commented Dec 2, 2015

should be out sometime by the end of this year, that's the plan at least :)

@cpojer
Copy link
Member

cpojer commented Feb 22, 2016

Will be fixed in 0.9.0. I'll publish a new version of jest-cli@next that solves this problem.

@cpojer cpojer closed this as completed Feb 22, 2016
ghost pushed a commit that referenced this issue Feb 22, 2016
Summary:This fixes unmock resolution for node_modules when using npm3. The way this is solved is by checking whether the parent dependency is unmocked and both modules are within a `node_modules` folder.

This has taken a while, mainly because it required #599 to be merged. I also added some more caching that makes test runs even faster. The react-native test suite now completes in about 6s (down from 7.5-8s). There might be more in the near future ;)

This fixes #554, #730, facebook/react#5183, facebook/relay#832 and will be part of 0.9.0. I'll publish 0.9.0-fb3 today with this fix.
Closes #732

Differential Revision: D2959610

fb-gh-sync-id: c374b7a2bcdfddf768905356a08948d9156eb028
shipit-source-id: c374b7a2bcdfddf768905356a08948d9156eb028
creature added a commit to creature/react-ratchet that referenced this issue Feb 24, 2016
@cpojer
Copy link
Member

cpojer commented Mar 6, 2016

0.9.0 has been published and this issue is now properly fixed :)

george-carlin referenced this issue in george-carlin/abroaders May 30, 2016
update version numbers of packages, and add some extra
config to 'jest' that fixes an error that started
occuring after the upgrade. See:

https://github.com/facebook/jest/issues/554\#issuecomment-148836979
@kunalgupta1983
Copy link

getting following issue while running tests
node_modules\bootstrap\dist\css\bootstrap.min.css:5
//! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css
*/html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjus
t:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgrou
p,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{displa
y:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height
:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hove
r{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{fo
nt-style:italic}h1{margin:.67em 0;font-size:2em}mark{color:#000;background:#ff0}
small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertic
al-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){ov
erflow:hidden}figure{margin:1em 40px}hr{height:0;-webkit-box-sizing:content-box;
-moz-box-sizing
SyntaxError: Unexpected token {

  at transformAndBuildScript (node_modules\jest-cli\node_modules\jest-runtim

e\build\transform.js:320:12)

@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants