-
-
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 24 seems to also run a top level test despite having projects set in package.json #7733
Comments
I could not reproduce this by creating the minimal package/directory structure to match your description - Jest only ran on |
I want to hijack this issue, because I've run into the same problem (I think?). My reproduction repository is here: https://github.com/victorandree/jest-7733 For me, this also doesn't work with jest@23.6.0 (see https://github.com/victorandree/jest-7733/tree/jest23). Maybe this isn't expected behavior but I can't understand what the point of |
A single project is buggy, see #7496 |
Ok, I see. I updated |
I have this issue as well, here's my Jest config: const Config = {
projects: ['<rootDir>/packages/*'],
}
module.exports = Config To get around it I can't just add
As a workaround, I can enumerate each package individually but that's quite verbose and brittle. |
@SimenB We encountered a similar issue and tracked it down to an empty leftover directory that matched the |
This was exactly what happened to us! Thanks for sharing the repro. I was able to go back to using |
I have a reproduction repo showing these issues: https://github.com/freshollie/jest-7733 |
That seems expected - jest works by walking up the FS until it finds config. We could maybe do something more clever here? |
Is there any reason jest can't ignore files which are not already being run under projects? It seems very not obvious when you have test files being run twice. Edit: If jest is being run from the root, could it not just ignore any folders going down the directory structure which contain some sort of |
I was having a similar issue with Jest running the test in each package AND also form the root of the monorepo. Changing my projects config to specify the Jest configuration of each package solve it. Ex: module.exports = {
// specifying the jest configuration of each package will force Jest to NOT run test from Root too,
// but instead just run tests in packages and use root as the folder to dump the coverage report
projects: ['<rootDir>/packages/*/jest.config.js'],
}; |
@gdlm91 I tried that and I am still seeing the same thing happen where it will run everything from the top level. I put a console.log statement in the sub package jest.config.js and it is not even being run. However, if I run it from the cli and set the e.x.
|
@seawatts , I took @freshollie repo and applied the fix I mentioned, and seems to work fine. You can check it out here: https://github.com/gdlm91/jest-7733 Or I might be missing the real problem... |
Thanks @gdlm91 I also got it working as well I think what got it working for me was adding // ./jest.config.js
const baseConfig = require('./jest.config.base');
module.exports = {
...baseConfig,
projects: ['<rootDir>/packages/*/jest.config.js'],
}; // ./jest.config.base.js
module.exports = {
...{your other props},
testMatch: [`<rootDir>/src/**/*.test.{ts,tsx}`],
collectCoverageFrom: [`<rootDir>/src/**/*.{ts,tsx}`],
} and then in each sub directory I just have // ./packages/sub-project/jest.config.js
const base = require('../../jest.config.base');
module.exports = {
...base,
displayName: 'My Sub Directory'
} This allows me to run jest at the top level as well as in each sub directory. e.x. # base directory
$ jest # Runs all tests in every project and stores coverage data in `./coverage`
# -- OR --
$ cd ./packages/sub-project
$ jest # Only runs sub-project tests and stores coverage in `./packages/sub-project/coverage
|
@seawatts's setup worked for me as well. My mistake from before was that I was not splitting out the "root config" from the "base config", and then accidentally bringing in // jest.config.js
module.exports = {
projects: ['modules/*/jest.config.ts', './jest.config.js']
// other stuff
}
// module/package/jest.config.ts
const baseConfig = require('../../jest.config')
export default {
...baseConfig, // this also set projects at module level, which seriously confused jest
// other stuff
} Note that running $ cd ./modules/package
$ jest only works if you also have $ cd ./modules/package
$ ../../node_modules/.bin/jest Not great, but gets the job done. |
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. |
💥 Regression Report
A clear and concise description of what the regression is.
Last working version
Worked up to version: 23.6
Stopped working in version: 24
To Reproduce
I am not sure if this is completely consistent, but; given a monorepo where the top level
package.json
jest config is just:and there is otherwise no top level config (all config is inside monorepo packages), jest seems to run an independent instance on the top level that will likely fail to build anything due to not finding the necessary config nested inside (for example, the
transform
config, or themoduleNameMapper
).This seems related to #7268.
Directly using the
--projects
option in the command line prevents this top level configless runner from running, but--projects
itself does not accept globs.Manually enumerating each possible package with an additional
--projects
per package (--projects foo --projects bar --projects bar
, etc) also behaves correctly. It's only loading the projects config frompackage.json
that seems to be broken.I could tell that there were two runners when I tried giving the path to a test file as an argument -- for example,
jest app/foo/foo.test.js
. There would be two status lines printed for the same file, one would FAIL due to missing config, the other would PASS.Expected behavior
Jest should only run tests for the given projects.
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: