Skip to content

Jest ignoring tests inside src/node_modules #1042

Closed

Description

@spadin

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.

Activity

  1. alphashuro commented on Nov 15, 2016

    @alphashuro

    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
  2. spadin commented on Nov 15, 2016

    @spadin
    ContributorAuthor

    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.

  3. alphashuro commented on Nov 15, 2016

    @alphashuro

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

  4. alphashuro commented on Nov 15, 2016

    @alphashuro

    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

  5. modified the milestone: 0.8.0 on Nov 20, 2016
  6. gaearon commented on Nov 20, 2016

    @gaearon
    Contributor

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

  7. added this to the 0.9.0 milestone on Nov 20, 2016
  8. modified the milestones: , 0.9.0 on Jan 23, 2017
  9. ianschmitz commented on Mar 14, 2017

    @ianschmitz
    Contributor

    #544 should take care of supporting this case

  10. sparebytes commented on Mar 24, 2017

    @sparebytes

    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.

  11. AaronHarris commented on May 1, 2017

    @AaronHarris

    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.

  12. modified the milestones: , on May 8, 2017
  13. gaearon commented on Jan 8, 2018

    @gaearon
    Contributor

    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.

  14. locked and limited conversation to collaborators on Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions