-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Cannot find module 'react/addons' from test js #367
Comments
I'm having the same problem. Anyone else? |
+1 > Jest@1.0.0 test /Users/island205/github/ReactUnitTesting/Jest
> jest
Using Jest CLI v0.4.5
Waiting on 2 tests...
PASS __tests__/sum-test.js (0.037s)
Waiting on 1 test...
FAIL __tests__/fetchCurrentUser-test.js (0.05s)
● fetchCurrentUser › it calls into $.ajax with the correct params
- Error: Cannot find module 'jquery' from '/Users/island205/github/ReactUnitTesting/Jest/__tests__'
at Function.module.exports (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/node_modules/resolve/lib/sync.js:32:11)
at Loader._nodeModuleNameToPath (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:503:22)
at Loader._moduleNameToPath (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:471:19)
at Loader._getNormalizedModuleID (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:358:31)
at Loader._shouldMock (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:566:23)
at Loader.requireModuleOrMock (/Users/island205/github/ReactUnitTesting/Jest/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:934:12)
at Timer.listOnTimeout (timers.js:110:15)
1 test failed, 1 test passed (2 total)
Run time: 2.359s ➜ Jest node -v
v0.12.4
➜ Jest npm -v
2.10.1 |
I solved the issue changing the version of npm to 0.10. |
I don't consider this a fix as npm and iojs weren't even the same thing as of the writing of this issue. I had to upgrade npm for other reasons which then led to this problem. Going backwards doesn't solve the problem for me. |
I suspect you want to stop requiring 'react/addons' which is deprecated and instead start requiring '/react/addons/thespecificaddonyouwant' Solved a similar issue for me with jspm. |
My original problem stemmed from not having react in node_modules since I use jspm. System JS provides my mapping to the correct locations but I don't know how to properly use these things in conjunction when testing server-side. Any thoughts on this are appreciated. |
If you want to run node stuff you'll probably need to npm install react as well as jspm install. Node doesn't know anything about jspm installed modules. Possibly you can tell one how to find things in the other, but I haven't tried. |
@ProggerPete the problem with this is that all of my modules use import statements that go looking for things using the SystemJS loader. For instance, in my BuildingTable.jsx my import looks like: import React from 'react'
import Submodule from 'api/submodule'
import Util from 'util/MyUtil'
... So that when the imports resolve for my test runner it's trying to look inside of node_modules for things that don't exist. Granted I could install react under node_modules using In a browser environment I can load up SystemJS from my jspm_modules, resolve my config.js import script which handles all the "System.config" stuff for SystemJS including setting my baseURL, paths, map and then finally import my main app. I'm not sure really where-in the problem lies: do I have a ridiculous project setup? Most of my modules are inside of jspm_modules but I have other modules throughout my project that I like being able to reference like Each of those top level names reference areas of my project. Some may reference npm modules, some may reference app modules, some are bitbucket/github/vendor modules.... point being... MODULES EVERYWHERE. Luckily SystemJS saves the day by allowing me to properly map things to where they should be found. |
Having re-read my last comment I see this as more of an issue with my project setup and SystemJS than Jest now. |
Feel free to reopen if this is still an issue with the latest version of jest (0.7.1+). |
@cpojer are you saying Jest now works with ES6 modules via jspm/System.js? |
No, did I say anything like this? |
The OP distilled his issue in a recent comment, namely:
He then closed with this:
Your response:
That led me to believe that his issue, incompatibility with the SystemJS module loader, is expected to be resolved in Jest 0.7.1+. Obviously not the case, given your response. That said, do you know if this is on the roadmap? |
It is unlikely there'll be official support for this library unless it is a community contribution. |
Understood, thanks for clarifying. |
+1 I also have similar problem: but using Webpack, not SystemJS to bundle things. As @buddyp450, I have a separate folder for shared in-house developed modules next to To get that running I updated Webpack config to include additional directory and it works like a charm: However, it seems jest config is missing such feature, right? If I copy |
posting here in case others like me get here when searching for a solution to using Jest with a JSPM-based app. I've written a Gulp plugin to help run Jest with JSPM/SystemJS apps: gulp-jest-jspm. to use it, you dont even have to be using Gulp, you can simply use its getJestConfig() method to generate the config for you before you run Jest. |
@buddyp450 Did you come up with your own solution? |
@ArmorDarks no, sorry. This was from a short foray into evaluating jest that I took a while back ago. My tests currently do not use jest. |
@buddyp450 Thanks for reply! You mean, it's easier to use JSPM/SystemJS with other test runners? I thought that issue with deps resolution will be relatively same everywhere.... |
hi @ArmorDarks , |
@yoavniran Hi! We've seen your plugin, of course, thanks for it. We're still looking into it as possible solution, but since it doesn't fit in our current pipeline well, we really hope that #2445 will be merged soon and it will provide more practical way. Though, it will still require additional function, which will "transpile" SystemJS mappings to understandable for Jest ones, and some API's of |
@ArmorDarks My original thinking was to separate the logic to its own package but due to time constraints I didnt get to it and was waiting for the need to arise. If it will be useful for you Ill be happy to separate them into different packages. |
@yoavniran yeah, it would be logical to separate them. Because, well, it's kinda strange to require whole Gulp plugin to invoke its method in Grunt environment :) I think we should wait for #2445 PR to be merged first. So far it seems to be ignored for quite a while... |
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. |
Running
iojs ./node_modules/jest-cli/bin/jest.js
via script in package.json results in:My building test js:
Still very new to this so apologies if I'm missing something obvious.
My package.json:
Would really appreciate even a point in the right direction.. thanks!
The text was updated successfully, but these errors were encountered: