I created a src/node_modules directory so I can have shared code I re-use throughout my project.
So rather than doing
import MyComponent from '../../../../shared/MyComponent';
I could write
import MyComponent from 'shared/MyComponent';
This works great, except when I add a test MyComponent.test.js. It isn't "seen" by Jest.
Not sure if this is a supported use case, it might just be a nice-to-have.
i suspect this is expected behavior, since 'node_modules' is actually one of the folders jest is configured to ignore since
It makes sense if this is intended behavior, but to be clear, the node_modules directory I created is under src so it only has files I've added.
there is however another node_modules in the root of your project, and that name is usually ignored by most tools for testing/linting/indexing because of the large number of dependencies usually installed in there. webpack has a configuration option for specifying the 'root' folder of your project so that all imports from / start at src/, i'll investigate and make a PR because i also need this but have been lazy to add it :)
Just submitted a PR so that we can do import MyComponent from 'components/MyComponet' or import MyComponent from 'MyComponent' if MyComponent is in src :D crossing fingers hoping its accepted
Let's do this (support for src/node_modules). A PR would be welcome.
I have a similar issue. I'm attempting to run jest from inside the src/node_modules directory.
Eg.
cd ./src/node_modules/my-package
jest
I'm able to run tests after I move my-package to somewhere else.
I think one key thing to keep in mind is that whenever there is a node_modules folder without a package.json at the same-level, it is most likely user-generated.
At our organization, the "top-level" of our git package source is located under a src/ directory during our build process, so this would break testing during the build phase since the third-party node_modules would also be installed under this src/ directory from package.json at that same level.
Closing in favor of https://github.com/facebookincubator/create-react-app/issues/1333.
We'll likely support Yarn Workspaces and/or Lerna with a top-level packages directory instead of src/node_modules.
Most helpful comment
Closing in favor of https://github.com/facebookincubator/create-react-app/issues/1333.
We'll likely support Yarn Workspaces and/or Lerna with a top-level
packagesdirectory instead ofsrc/node_modules.