question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest.config.js within monorepo setup doesn't load when run from rootDir

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:14

github_iconTop GitHub Comments

12reactions
alfaprojectcommented, Jan 14, 2019

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 tell jest which configuration file to use for the currently opened project. I can only run jest 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

11reactions
sibeliuscommented, Jan 17, 2019

check a running project with multi config here https://github.com/entria/entria-fullstack

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Projects in a Monorepo unable to find config files in projects
There is no src folder in the repo root, only inside the individual project folders. I'm also not referencing src\tsconfig.spec.json anywhere in ......
Read more >
Monorepo testing using jest projects - Orlando Bayo Adeyemi
Run tests globally from the root. Run tests from individual project directories. Let developers manage their own jest, babel, and typescript ...
Read more >
Configuring Jest
Configuring Jest. The Jest philosophy is to work great by default, but sometimes you just need more configuration power.
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
This is part two of our mono repo setup. In the first part, we created a ... This command will create a jest.config.js...
Read more >
Config Files - Babel.js
Configuration File Types. ... The first issue you'll likely run into is that by default, Babel expects to load babel.config.json files from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found