1

My unit tests for my React project pass perfectly fine on local but fail on Jenkins. I get this error message on Jenkins:

Error: Cannot find module '../../../../src/components/Sidebar/MenuList.jsx'

The file does exist and is imported in my test file like so:

import { MenuList } from '../../../../src/components/Sidebar/MenuList.jsx';

And exported in my MenuList.jsx file:

export class MenuList extends Component { ... }

I am using Mocha/Enzyme/Sinon for testing + Istanbul for coverage.

Lauraponi
  • 319
  • 2
  • 12

1 Answers1

2

Since you have a mac and im guessing jenkins is a linux based. Check the file names. meaning check that the names are case sensitive.

Your problem is that the mac is not case sensitive while the jenkins (im guessing) is in a linux host which is. so say you have a file name like this

import a from '../MyCoolDir'

and the dir name is '../myCoolDir' it will work on mac but not on your jenkins. since the linux host will not be able to find the file becase it does not have the exact name

Youll probably want to take a look at this to configure git too How do I commit case-sensitive only filename changes in Git?

Hope it helps

jstuartmilne
  • 4,398
  • 1
  • 20
  • 30
  • 1
    Aw waow, thanks so much. It was the problem. I also had a test coverage that wasn't right with istanbul, and that solved this too. Hours of useless head scratching :'. Thanks! – Lauraponi Dec 21 '17 at 12:26