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 resolution within a mono repo

See original GitHub issue

Do you want to request a feature or report a bug? feature

I have a mono repo (just like Jest itself) that hosts multiple npm packages. I want to be able to run jest from anywhere within my repo and have it resolve to the jest.config.js file in the root of my repo.

Right now, if i run jest from within one of the package directories jest would try to resolve the config path and usually it ends up picking up one of the package.json files on the way to the root.

for example (repro on Jest repo itself): current behaivor:

cd jest/packages/jest-cli
jest # resolves to `jest/packages/jest-cli/packages.json and fails to run the test because it's not a valid config
cd jest/
jest # resolves to `jest/package.json` and runs tests correctly

expected behaviour:

cd jest/packages/jest-cli/
jest # ignore `jest/packages/jest-cli/packages.json` and resolve to `jest/packages.json`

I don’t know what’s the best way to make it work without introducing a wrapper shell script (like we do at fb)

would adding a config option to ignore nested package.json files be ok for this case?

like:

// jest.config.js
module.exports = {
  ignoreNestedPackageJson: true,
};

the config resolution process will look like:

  1. traverse the directory tree up until a config file with ignoreNestedPackageJson is found
  2. if # 1 is not found, resolve to the closest config

cc @captbaritone

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:18
  • Comments:6

github_iconTop GitHub Comments

1reaction
alfaprojectcommented, Jan 14, 2019

Currently I solved my particular issue by using this VSCode launch task:

{
  "type": "node",
  "request": "launch",
  "name": "Debug current file",
  "program": "${workspaceFolder}/node_modules/.bin/jest",
  "args": [
    "--runInBand",
    "--config",
    "`${workspaceFolder}/node_modules/.bin/find-up --cwd=${fileDirname} jest.config.js`",
    "${file}"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
}
0reactions
github-actions[bot]commented, Apr 27, 2022

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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Monorepo testing using jest projects - Orlando Bayo Adeyemi
Run tests from individual project directories. Let developers manage their own jest, babel, and typescript configurations, i.e. shared common ...
Read more >
Where to configure jest in a monorepo?
Just install the jest package in the root. Then, add projects [array<string | ProjectConfig>] configuration in jest.config.js file:.
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
In the first part, we created a mono repo with Lerna and TypeScript. ... This command will create a jest.config.js file in our...
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, ...
Read more >
Using with monorepo | ts-jest - GitHub Pages
To use ts-jest in a project with monorepo structure, you'll need to use Jest projects configuration. When using Jest projects configuration, ...
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