node.jsmocha.jstravis-cinyc

Permission denied when running npm test via mocha and nyc on Travis-CI


I'm setting up my server side for NodeJS application which I'm integrating with Travis-CI. I'm using Mocha and NYC to help with my tests. However, while these tests run fine locally, I'm failing the tests when on Travis-CI.

Locally everything works fine with no errors.

Travis-CI output error:

> server@1.0.0 test /server
> nyc --reporter=lcov npm run run-test "--coverage"
sh: nyc: Permission denied
npm ERR! Test failed.  See above for more details.
The command "docker run repname/server npm test -- --coverage" exited with 1.

That's my .travis.yml file:

sudo: required
services:
  - docker
    
before_install:
  - docker build -t repname/server -f Dockerfile.dev .

script:
  - docker run repname/server npm test -- --coverage

I even tried some of other similar problems find on stack: Thats what I tried with no luck:

For NYC:

before_script: chmod 0555 ./node_modules/.bin/nyc

before_script: chmod 0777 ./node_modules/.bin/nyc

For Mocha:

before_script: chmod 0555 ./node_modules/.bin/mocha

before_script: chmod 0555 ./node_modules/.bin/mocha

Solution

  • I solved it. The problem was that I wasn't add the right path in .gitignore file. So when I push to master on github, it actually pushed the node_modules folder, which was not supposed to do.

    Keep that in mind when you try to build on Travis CI or any CI, don't put your module folder in your main repo.