Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest sometimes cannot find modules

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

like image 330
Przemek Lewandowski Avatar asked Aug 08 '18 22:08

Przemek Lewandowski


1 Answers

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!

like image 186
bamse Avatar answered Oct 04 '22 03:10

bamse