--config [JSON] + projects doesn't seem to work
See original GitHub issue🐛 Bug Report
When passing serialized JSON for the --config
option that contains projects, I get the following error:
Error: Jest: Cannot use configuration as an object without a file path.
at readConfig (~/github/benmvp/benmvp-cli/node_modules/jest-config/build/index.js:139:13)
at projects.filter.map.root ~/github/benmvp/benmvp-cli/node_modules/jest-cli/build/cli/index.js:487:62)
....
The parsed JSON looks like:
{
"projects": [
{
"moduleFileExtensions": ["ts", "js"],
"transform": {
"^.+\\.(ts|js)$": "babel-jest"
},
"testMatch": [
"<rootDir>/src/**/*.ts"
],
"runner": "jest-runner-tsc",
"displayName": "typescript"
},
{
"moduleFileExtensions": ["ts", "js"],
"transform": {
"^.+\\.(ts|js)$": "babel-jest"
},
"testMatch": [
"<rootDir>/src/**/*.spec.ts"
],
"displayName": "test"
}
],
"rootDir": "."
}
To Reproduce
Just run:
npx jest --config '{"projects":[{"moduleFileExtensions":["ts","js"],"transform":{"^.+\\.(ts|js)$":"babel-jest"},"testMatch":["<rootDir>/src/**/*.ts"],"runner":"jest-runner-tsc","displayName":"typescript"},{"moduleFileExtensions":["ts","js"],"transform":{"^.+\\.(ts|js)$":"babel-jest"},"testMatch":["<rootDir>/src/**/*.spec.ts"],"displayName":"test"}],"rootDir":"."}'
Expected behavior
I expect to be able to run the projects just like if they were defined in a config file (which does work).
Link to repl or repo (highly encouraged)
See repro command. Happy to contribute a PR, I just don’t know what to fix. 😄
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Binaries:
Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.12.0/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Debugging
1/ I tried moving the JSON back to a .js
file and it works (my current workaround). I need the contents to be dynamic, which is why I want to pass JSON
2/ I did a whole bunch of code spelunking to try to get it to work. I narrowed down the problem to readConfigs
in jest-config
. It seems that after successfully parsing the JSON, it maps over each project to readConfig
on each (passing configPath
). The problem is that configPath
is null
so readConfig
complains. And the reason configPath
is null
is because when the JSON was originally parsed (also by readConfig
), I guess there is no configPath
to set so it remains null
. That’s as far as I got since I don’t understand the why of the code.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Hey @benmvp thanks for filing! Confirmed - I’ll take a look
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.