Skip to content
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

Add an option for config file path in package.json #8134

Closed
DavidBabel opened this issue Mar 16, 2019 · 8 comments
Closed

Add an option for config file path in package.json #8134

DavidBabel opened this issue Mar 16, 2019 · 8 comments

Comments

@DavidBabel
Copy link

DavidBabel commented Mar 16, 2019

🚀 Feature Proposal

For now, when we want to configure jest we have three choices :

  • put the jest config in package.json
  • put the jest config in jest.config.js at root
    In both this previous choices, you can easily run your tests with a simple jest command.
  • put the jest config in whatYouWant.js anywhere in your project
    With this last choice you have to run jest -c ./path/to/whatYouWant.js

Motivation

The idea is to run a simple jest command in any of the three cases.

Example

The idea should be to add a new option in package.json. It may be something like defaultConfigFile:

{
  "name": "myModule",
  "jest" : {
    "defaultConfigFile": "./path/to/whatYouWant.js"
  }
}

In this case, it's the only option in package.json, which override the default config file search at root. The rest of the config stays in your whatYouWant.js

Pitch

Why does this feature belong in the Jest core platform?

Because it's a native configuration proposal.

@SimenB
Copy link
Member

SimenB commented Mar 17, 2019

Having config be able to reside in configuration and not just in code seems reasonable to me.

Linking in #7185

@DavidBabel
Copy link
Author

Thanks

@carlosm2011
Copy link

Has this been implemented yet?

@lk77
Copy link

lk77 commented Apr 14, 2020

Hello,

any news on this ?

my jest config file is not in the root directory but inside tests/unit, and it's annoying.

@D-Pow
Copy link

D-Pow commented Sep 23, 2021

For me, adding the preset field to my package.json seems to have worked to do exactly that. It made my custom config file globally accessible for all npm scripts as well as IDE-initiated tests, which previously used to fail unless I manually specified where jest.config was located.

"jest": {
  "preset": "./config/jest/jest.config.mjs"
}

@Turbotailz
Copy link

Thanks @D-Pow this was exactly what I needed to get WebStorm to use my config for default run configurations

@DavidBabel
Copy link
Author

Thanks @D-Pow for the hint. I resolve this issue.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants