-
-
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 cannot find tests when projects are defined in configuration #6509
Comments
I have the same problem as you. All jest versions 23.0.0, 23.1.0, 23.20 don't detect my tests. |
The problem is that it doesn't recursively check all directories for tests in my project(s). I ended up working around it by using 2 separate jest configs and one as base. "scripts": {
"test": "npm run test:node && npm run test:jsdom",
"test:node": "jest --config=config/jest.node.config.js",
"test:jsdom": "jest --config=config/jest.jsdom.config.js"
} jest.base.config.js const path = require('path');
module.exports = {
rootDir: path.join(__dirname, '..'),
verbose: true,
moduleFileExtensions: [
'js',
'ts',
'tsx',
'json',
'node',
],
testPathIgnorePatterns: [
'/node_modules/',
],
collectCoverage: true,
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
}; jest.jsdom.config.js const baseConfig = require('./jest.base.config');
module.exports = {
...baseConfig,
testEnvironment: 'jsdom',
testMatch: [
'**/*.test.tsx'
],
setupTestFrameworkScriptFile: './setupTests.ts',
}; jest.node.config.js const baseConfig = require('./jest.base.config');
module.exports = {
...baseConfig,
testEnvironment: 'node',
testMatch: [
'**/*.test.ts'
],
}; OFFT: |
In my case jest checks recursively but still doesn't find any test files. The only difference between your and my config is that I use
Deleting it doesn't change anything. Maybe it's somehow connected with #6546 |
Yes, this is still an issue for me too. Right now, projects don't seem to be useful. I can run a command like:
When More documentation might help, but I'm sure there's something else skewed too. |
When I run test with jest I get an error that no test is found both my tests and js files are inside the static folder Here is my package json
Error
What could be the issue |
Any updates on this? |
@y4nnick I did manage to get this set up eventually. It was a royal pain though. My main Jest config looks like:
And within each package subdirectory I have a Jest config that looks more like:
I think it was the |
EDIT: I fixed it by adding a I got this issue, but only in CI (inside a docker container with NODE_ENV=test and --ci tag) Using CRA with TS. No idea why its not finding the test. They are clearly there |
{
rootDir: path.join(__dirname, '../..'),
testMatch: [..., path.join(__dirname, '../../**/?(*.)+(spec|test).[tj]s?(x)')],
} This fixed it for me. Issue seems to be that the recursion is relative to the rootDir path. Depends how nested your configuration file is, but basically you just need to set your root up as far as you need to go. |
After searching a while I found out that if you use:
but don't have one of those folders everything else is ignored too. |
@Naxos84 It worked here, thanks! |
Many thanks, man!!! |
I got it working by specifically defining Example:
|
I had the same issue, and after hours of suffering, I started from scratch by creating a brand new empty config file by doing:
That command created the most basic jest config file, like:
With that simple configuration, all started working. I'm in a react-native context, but I hope this helps. This is my jest.config.js:
... and my tsconfig.jest.json file:
|
In My Case simply removed "testMatch" from package.json |
Thanks !! I was quite frustrated with issue, and it resolved it quite nicely... |
Where could I put this : roots: ["/src/", "/tests/"], |
I suspect this might be a bug in how jest resolves the config file location, as least in mono repos where you have:
Where the root I added some tracing into https://github.com/facebook/jest/blob/main/packages/jest-config/src/resolveConfigPath.ts and found that it is trying to recurse up to the parent directories, but it fails to actually recurse upwards due to https://github.com/facebook/jest/blob/main/packages/jest-config/src/resolveConfigPath.ts#L60 not being the parent directory. Before and after changing that line to Before:
After:
As you can see, in the before the directory it tries to load configuration from doesn't change, despite attempting to recurse upwards. After the change, it correctly tries to load configuration from each of the parent directories. Note: the I'm going to try to write tests and a PR to fix the behaviour, though I'm not sure if this'll break things at all. Edit: clarified the found |
Just an update here, maybe I'm misunderstanding how Jest's projects setting is meant to work in mono-repos — i.e., the individual packages aren't meant to have a |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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
Basically I got a bunch of files for my Electron app, some of them require a node environment, and some of them jsdom, because I need to test out some features of my React components, e.g
componentDidMount
methods, but I can't define differentjest
configs for my folders, as shown per documentation in jest as it resolves to no tests found.To Reproduce
You can reproduce the error if you try to run the tests from https://github.com/marcus-sa/venobo/tree/ts
as you can see here
but it works fine if I do this:
The text was updated successfully, but these errors were encountered: