0

I've tried every combination of settings and overriding defaults, I cannot get Jest to look within my node_modules folder.

{
    "testEnvironment": "node",
    "testMatch": ["**.test.js"],
    "testPathIgnorePatterns": []
}

Why wouldn't this work?

When I run jest with this config, with tests available in the node_modules folder, I get:

 211 files checked.
  testMatch: **.test.js - 0 matches
  testPathIgnorePatterns:  - 0 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches
J.Todd
  • 707
  • 1
  • 12
  • 34
  • Is it known that there really are .test.js files? Why would you want to do this btw? It's a can full of worms. – Estus Flask Mar 17 '21 at 08:05
  • @EstusFlask Moving files to node_modules for a more direct require path is the consensus for avoiding `require('../../../../../my-function.js')` hell. https://stackoverflow.com/questions/10860244/how-to-make-node-js-require-absolute-instead-of-relative If your main files aren't stored in the root directory of your project, it's the only reliable solution. – J.Todd Mar 17 '21 at 16:43
  • I can't say what's the problem with testMatch here, but this is XY problem, the thing you're trying to do is never done this way. If a set of functionality deserves to have its own package, the package should be responsible for running its own tests. You can orchestrate test runs from parent project (that's how it's done in monorepos). And depending on the environment, there are path aliases so there may be no need for separate package. Notice that the question you linked mentions Webpack, where you're not limited to physical node_modules. – Estus Flask Mar 17 '21 at 17:02

0 Answers0