jest.config.js within monorepo setup doesn't load when run from rootDir
See original GitHub issueDo you want to request a feature or report a bug? It seems a bug or a missing mention in the documentation.
What is the current behavior?
I’ve the below monorepo setup and when I run jest within each of the packages folder, jest picks up the jest.config.js within each of them and works perfectly. But when I try to run them from the project’s rootDir
, the tests fail because the setupFiles
aren’t being used(I think the jest.config.js is infact not being respected). Is there a way I could get this fixed?
.
├── package.json
├── lerna.json
├── jestBaseConfig.js # Base jest configuration file which will be used in jest.config.js of each package
├── packages
│ ├── api
│ │ ├── jest.config.js
│ │ ├── package.json
│ │ ├── src
│ │ └── test
│ ├── components
│ │ ├── jest.config.js
│ │ ├── package.json
│ │ ├── src
│ │ └── test
│ └── utils
│ │ ├── jest.config.js
│ │ ├── package.json
│ │ ├── src
│ │ └── test
// Jest configuration for api
const jestBase = require('../../jestBaseConfig.js');
module.exports = {
...jestBase,
coverageThreshold: {
global: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
},
testEnvironment: 'node',
setupFiles: [
require.resolve('./tests-setup/setupEnv.js'),
],
};
I also tried using the projects
property as below in the root directory’s package.json and it doesn’t seem to work as well.
// rootDir's package.json
...
"jest": {
"projects": [
"<rootDir>/packages/kh-api/jest.config.js",
"<rootDir>/packages/kh-components/jest.config.js",
"<rootDir>/packages/kh-utils/jest.config.js"
]
}
...
What is the expected behavior?
jest should pick up jest.config.js
within each package folder and run the setupFiles
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system. jest: v22.1.2 yarn: 1.3.2 OS: macOS High Sierra
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:14
Top GitHub Comments
Why is this closed exactly?
The point of having projects support is because those projects probably have different settings. One
jest.config.js
file at the root doesn’t cover a scenario where a project has tests next to source files and another project as a separate tests folder for example. (Angular or Vue front-end and some other back-end services)I actually stumbled upon this because I want VSCode to launch
jest
for the currently opened file, but can’t because I can’t telljest
which configuration file to use for the currently opened project. I can only runjest
for all of the projects because that’s what the root Jest config has configured.P.S.: Just found this related open issue, so I’ll move the discussion there https://github.com/facebook/jest/issues/5921
check a running project with multi config here https://github.com/entria/entria-fullstack