I got this problem:
Sometimes jest cannot find modules while running tests. it's totally random module each time, not the same one. First one or two test suits fails because of that, rest are passing. Sometimes everything is okay. I use babel.
jest config in package.json
"jest": {
"collectCoverageFrom": [
"src/**/*.js",
"src/**/*.jsx"
],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"moduleDirectories": [
"node_modules",
"src"
],
"moduleNameMapper": {
"\\.(css|less|scss)$": "babel-jest",
"\\.(jpg|jpeg|png|svg)$": "<rootDir>/fileMock.js"
},
"setupFiles": [
"./testsSetup.js"
],
"testURL": "http://localhost"
},
testSetup.js
const { configure } = require('enzyme')
const Adapter = require('enzyme-adapter-react-16')
configure({ adapter: new Adapter() })
i run tests with npm test
set to jest --color --coverage --notify
is there something i lack in my config or something wrong here? couldn't find an alike problem
I have similar issues from time to time - usually when switching from and to branches with lots of changes.
Clearing jest
's cache solved my issues.
./node_modules/.bin/jest --clearCache
More details on clearCache.
You could also check jest
's showconfig and manually delete cacheDirectory
location - same thing clearCache
does.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With