Jest: Cannot use configuration as an object without a file path
See original GitHub issueI’m getting the error described in this test:
I have no clue on what it means or what it wants me to do, I’m trying to use the multi project configuration to run eslint along with the normal tests.
May someone explain this error? I tried to set rootDir in my root config but it doesn’t seem to do anything
This is my config:
{
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
],
"setupFiles": [
"raf/polyfill",
"node_modules/react-scripts/config/polyfills.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "node_modules/react-app-rewired/scripts/utils/babelTransform.js",
"^.+\\.css$": "node_modules/react-scripts/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "node_modules/react-scripts/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules(?!/@foobar/react-components)[/\\\\].+\\.(js|jsx)$"
],
"moduleNameMapper": {
"^.+\\.(css|sss)$": "node_modules/@foobar/react-app-rewire-foobar/node_modules/identity-obj-proxy/src/index.js"
},
"moduleFileExtensions": [
"web.js",
"mjs",
"js",
"json",
"web.jsx",
"jsx",
"node"
],
"rootDir": ".",
"coverageThreshold": {
"global": {
"statements": 100,
"functions": 100,
"branches": 100,
"lines": 100
}
},
"coveragePathIgnorePatterns": [
"index\\.js$",
".*demo\\.jsx$",
"src/demo/*",
"src/components/Modal/*"
],
"projects": [
{
"displayName": "unit",
"rootDir": "."
},
{
"displayName": "lint",
"rootDir": ".",
"runner": "jest-runner-eslint",
"testMatch": [
"<rootDir>/**/*.{js,jsx}"
]
}
]
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Configuring Jest
You can use --config flag to pass an explicit path to the file. note. Keep in mind that the resulting configuration object must...
Read more >Jest + Typescript + Absolute paths (baseUrl) gives error
This error occurs because of using absolute paths in the import statements of our TypeScript/Nest.js/Angular projects while using Jest. Fixing ...
Read more >Configuring Jest compiled - w3resource
In this tutorial we will focus on configuring Jest. Jest's configuration can be defined inside the package.json file of your project, ...
Read more >Config Files - Babel.js
babelrc file, with no extension. package.json files, with a "babel" key. Project-wide configuration.
Read more >Run/Debug Configuration: Jest | IntelliJ IDEA Documentation
Use --require coffeescript/register to have CoffeeScript files compiled into JavaScript on the fly during run. This mode requires that the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue is that this error is cryptic and doesn’t help in any way to understand what’s going on… With or without a repro, this error should be improved to help the consumer to understand what’s the required action to fix it.
Hey, I just came across this error too. From digging around the links from @ranyitz I think I figured out why this occurs. Basically my situation is a fork of the test script in create-react-app. Which in essence is:
jest.run('--config ' + JSON.stringify(someConfig))
. So if I setprojects
insomeConfig
to bewhich admittedly now that I’m looking through it is not how this is supposed to be used I get the above error. Simply this is because of the following line, which is not defined in a parsed config. https://github.com/facebook/jest/blob/d6192817d59c4a0a84b0d31e3ac9b65f4f5b14f2/packages/jest-cli/src/cli/index.js#L230
I guess what I’m trying to do here is run the same config on multiple projects (a monorepo) and just append the
displayName
before for easier reporting.I’m just reading the two very different setups and assuming they could be used together, what I want is probably actually the following but with the ability to add
displayNames
to it. (Or just completely off the wrong end of this one).Hopefully, this helps anyone else who hits this particular situation.