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

I’m setting up my server side for NodeJS application which I’m integrating with Travis. I’m using Mocha and NYC with Palo Alto Networks to help with my tests. However, while these tests run fine locally, this is what occurs within Travis:

> 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

thanks for any help!

Hello @Spineswitch,

History and experience would tell me that you have not added the right path in your .gitignore file specifically when using NYC. This is classic behavior with Travis when not done so.

Try pushing to master on GitHub, and check if it actually pushes the node_modules folder, if it doesn’t then you’re home free.

1 Like

This did it exactly @Montana, thank you.

No problem.

1 Like