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

Jest ignoring tests inside src/node_modules #1042

Closed
spadin opened this issue Nov 15, 2016 · 9 comments
Closed

Jest ignoring tests inside src/node_modules #1042

spadin opened this issue Nov 15, 2016 · 9 comments
Milestone

Comments

@spadin
Copy link
Contributor

spadin commented Nov 15, 2016

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.

@alphashuro
Copy link

i suspect this is expected behavior, since 'node_modules' is actually one of the folders jest is configured to ignore since

  1. you don't need to test dependencies installed in node_modules
  2. there are too many files in node_modules and reading all of them would hurt performance

@spadin
Copy link
Contributor Author

spadin commented Nov 15, 2016

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.

@alphashuro
Copy link

alphashuro commented Nov 15, 2016

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 :)

@alphashuro
Copy link

alphashuro commented Nov 15, 2016

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

@gaearon
Copy link
Contributor

gaearon commented Nov 20, 2016

Let's do this (support for src/node_modules). A PR would be welcome.

@ianschmitz
Copy link
Contributor

#544 should take care of supporting this case

@sparebytes
Copy link

sparebytes commented Mar 24, 2017

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.

@AaronHarris
Copy link

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.

@gaearon gaearon modified the milestones: 0.11.0, 0.10.0 May 8, 2017
@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

Closing in favor of #1333.

We'll likely support Yarn Workspaces and/or Lerna with a top-level packages directory instead of src/node_modules.

@gaearon gaearon closed this as completed Jan 8, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants