-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 not running tests in src/node_modules #2145
Comments
I think this is the offending section: https://github.com/facebook/jest/blob/cd4d97b30d73dbb2350dc77a409e39d8b8caca90/packages/jest-haste-map/src/index.js#L681-L692 |
Hey @modernserf
|
Yes, Jest excludes node_modules by default. You can adjust |
@cpojer did you look at the example repo? I'm using
and its still ignoring src/node_modules. |
I believe this is because haste ignores files in all node_modules directories, so files in |
Ahh, I'm sorry, yeah you are right! I didn't realize this before, but yes, what @shanewilson says should work for now. I believe to fix this without changing the "haste" config, you'd have to turn this switch to true: https://github.com/facebook/jest/blob/master/packages/jest-haste-map/src/index.js#L207 – if @shanewilson's workaround doesn't work, can you try turning this option to true and reporting back? If that works, we can probably expose it as well as part of the "haste" object – you could send a PR for that :) I also encourage you to give lerna a try: https://github.com/lerna/lerna – it has worked really well for us! Are you using Jest at Buzzfeed? |
Thanks! -- the haste config works for now, as does manually setting Regarding BuzzFeed: Each team has a fair amount of control over their own stack, but many of the newer internal tools (including the ones I work on) are using React/Jest/Webpack/Babel; some of our prototypes are even built with create-react-app. |
Ok I see, yeah that makes sense. I encourage you to just go with @shanewilson's workaround then. Also, cool that you are using Jest! :) |
Discussion continued here: facebook/create-react-app#1081 (comment) |
Related, you need to make sure that files in I had the same issue, as I'm trying to use Fix: // .jestrc
"transformIgnorePatterns": [
"<rootDir>/(node_modules)/"
] The default regex should have |
Here is an example repo that demonstrates https://github.com/kirkstrobeck/jest-issue-5039 |
Original CRA issue was closed, because using |
I have the problem too. We have a package Not sure how "standard" that approach is, but |
This issue prevents some decoupling that proves useful when building integration tests that can be shared across multiple of my The approach I took was to write my integration tests in a new project, and |
It would be really nice to have this supported properly. For me neither the workaround nor any other suggestion made it working. 🙄 What I'm trying to do: having directory tree
a-package.json
running jestwhat I do simply:
results
results using the workaroundset as part of
results using the workaround & testPathIgnorePatternsie I have the following jest config within
Still without any luck. This time the test has been found and properly loaded however:
I'm reporting all the above just to add more context/info on the problem and its possible cause. I have a ton of dependencies within whyI'm sharing common modules across apps within a monorepo and I cant use symlinks to do the job (thus Lerna isnt an option). The native nodejs require/resolve process works just fine for directory trees as described above, thus I'm able to require/import common modules into apps without 'magic' tricks. All fine until the point which I needed some tests for the common modules of mine which of course are placed within the common modules rendering them under what I think I needJest to be able to run as it runs normally - excluding update: please excuse me if the above doesnt makes sense or isnt helpful / related to the current github issue |
Adding all of these items to my module.exports = {
haste: {
providesModuleNodeModules: ['.*']
},
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
transformIgnorePatterns: ['<rootDir>/node_modules/'],
modulePathIgnorePatterns: ['<rootDir>/node_modules/']
}; |
Not working on 26.0.1, even with mentioned workarounds. Is there any plans to fix this? |
To work around it now, I made a wrapper file: const Runtime = require('jest-runtime');
const origCreateHasteMap = Runtime.createHasteMap;
Runtime.createHasteMap = function(...args) {
const ret = origCreateHasteMap.call(this, ...args);
ret._options.retainAllFiles = true;
return ret;
};
module.exports = require('jest/bin/jest'); And I run that file instead of the main Jest executable. I'd much rather have a config option if the maintainers are amenable to a pull request... P.S. I also configured my
|
xandris solution works fine, but I would like to know, if this is a bug and this suppose to work in near future or these tests are excluded by design. |
@kuka-radovan I stopped using that style of monorepo and now recommend npm 7 or yarn workspaces to do inter-module linking rather than relying on the |
Oof....5 years later and My workaround is use is creating a custom HasteMap implementation. const { default: HasteMap } = require("jest-haste-map");
class CustomHasteMap extends HasteMap {
_ignore(filePath) {
const ignorePattern = this._options.ignorePattern;
const ignoreMatched =
ignorePattern instanceof RegExp
? ignorePattern.test(filePath)
: ignorePattern && ignorePattern(filePath);
return ignoreMatched;
}
}
module.exports = CustomHasteMap; Then in jest configuration I set |
Resolves jestjs#2145 and jestjs#11781. Prevent haste map from automatically discarding node_modules files. By default, node_modules is still excluded via the testPathIgnorePatterns option. However, users can now use that option to allow node_modules without hacks.
Resolves jestjs#2145 and jestjs#11781. Prevent haste map from automatically discarding node_modules files. By default, node_modules is still excluded via the testPathIgnorePatterns option. However, users can now use that option to allow node_modules without hacks.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
What is the current behavior?
Jest reports "No tests found" even when there are tests
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can
npm install
andnpm test
.Example repo.
What is the expected behavior?
Tests in
src/node_modules
are runRun Jest again with
--debug
and provide the full configuration it prints. Please mention your node and npm version and operating system.Node v6.5.0
npm v3.10.3
See facebook/create-react-app#1042 and facebook/create-react-app#607 for related issues.
The text was updated successfully, but these errors were encountered: