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

NPM Test - No Tests Found #6595

Closed
svencowart opened this issue Mar 7, 2019 · 2 comments
Closed

NPM Test - No Tests Found #6595

svencowart opened this issue Mar 7, 2019 · 2 comments

Comments

@svencowart
Copy link

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

testing, test configuration, jest, jest configuration, overriding pattern

Environment

System:
OS: macOS 10.14.3
CPU: x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 10.15.1 - /usr/local/bin/node
npm: 6.8.0 - /usr/local/bin/npm
Browsers:
Chrome: 72.0.3626.121
Safari: 12.0.3
npmPackages:
react: ^16.8.4 => 16.8.4
react-dom: ^16.8.4 => 16.8.4
react-scripts: ^2.1.8 => 2.1.8
npmGlobalPackages:
create-react-app: 2.1.8

Steps to Reproduce

(Write your steps here:)

  1. mkdir node_modules
  2. cd node_modules
  3. create-react-app test
  4. cd test
  5. npm test
  6. (optional) enter "a" after test runner is up.

Expected Behavior

The test in App.test.js should have ran.

Actual Behavior

Step 5 output: No tests found related to files changed since last commit.
Step 6 output:

No tests found
No files found in /Users/svencowart/dev/node_modules/test.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Pattern:  - 0 matches

PS: I totally understand that it cannot find any tests because the project is within the node_modules folder; however, this is something beyond my control. It seems though if I run npm test within a project regardless of what parent directory is, it should find those tests but ignore the node_modules that are child directories of the project.

@bugzpodder
Copy link

This is probably a limitation with Jest: jestjs/jest#1995
Regardless, even this can be worked around, I am just not seeing how this feature would be useful to anyone else. I recommend tweaking your setup, or tweaking the way how your project runs tests.

@svencowart
Copy link
Author

svencowart commented Mar 8, 2019

I was able to resolve this issue by using react-app-rewired and configuring jest inside of package.json.

For anyone with similar issues, here is what I did:
Configuring jest within package.json: (make sure the path you specify is the path starting one directory down from the node_modules folder that contains your react project and points to the directory containing your application - e.g. my application is inside of node_modules/my-application/client so the past I add is my-application/client.)

"jest": {
  "haste": {
    "providesModuleNodeModules": [
      "my-application/client"
    ]
  }
}

The contents of my config-overrides.js file:

module.exports = {
  webpack: (config, env) => config,
  jest: config => {
    config.testPathIgnorePatterns = [];
    config.transformIgnorePatterns[0] = `<rootDir>${
      config.transformIgnorePatterns[0]
    }`;
    return config;
  },
  devServer: configFn => configFn,
  paths: (paths, env) => paths,
};

@bugzpodder It seems the real issue is that react-scripts does not support changing the jest configuration for testPathIgnorePatterns and transformIgnorePatterns so I need to rely on react-app-rewired for such changes. However, this could be very intentional so I'll close this issue since my original ticket is resolved.

@lock lock bot locked and limited conversation to collaborators Mar 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants