1

I'm trying to generate the code coverage report for our builds in Jenkins - Locally when I execute the command

npm run coverage 
  "scripts": {
    "test": "cross-env mocha test -t 5000 --recursive --exit --reporter mochawesome",
    "coverage":"nyc --reporter=html --reporter=text ./node_modules/.bin/mocha test -t 5000 --recursive --exit"
  },

it will run the tests and then give me the code coverage results

enter image description here

Now when the same code runs in jenkins I get this error

/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/path-to-regexp/index.js:63 path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?')) ^

TypeError: Cannot read property 'length' of undefined at pathtoRegexp (/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/path-to-regexp/index.js:63:49) at new Layer (/var/lib/jenkins/jobs/api-ci-develop/workspace/back-end/node_modules/express/lib/router/layer.js:45:17)

apparently is doing something with the node_module folder and I'm not sure how to avoid that. I exclude the folder and files in the nyc config

  "nyc": {
    "branches": 5,
    "lines": 25,
    "functions": 13,
    "statements": 25,
    "check-coverage": true,
    "exclude": [
      "**/services/plaidService.js",
      "**/node_modules/**",
      "**/node_modules/plaid/lib/PlaidClient.js"
    ]
  },

Any ideas what should I do to avoid the node_modules folder to be checked?

Gerard Roche
  • 6,162
  • 4
  • 43
  • 69

0 Answers0