JamesE
JamesE

Reputation: 3923

Generating istanbul/nyc coverage reports with mocha

I am trying to generate an nyc/istanbul coverage report on my project (using mocha). I can get this to run from the command line with the following command:

npm test --reporter mocha-bamboo-reporter test/

which is essentially running

nyc mocha --recursive "mocha-bamboo-reporter" "test/"

The tricky part is that I need to run this in bamboo which doesn't seem to support chaining of/multiple commands in one task.

My bamboo config has a mocha test runner:

node_modules/mocha/bin/mocha --reporter mocha-bamboo-reporter --recursive

I have an istanbul/nyc instrument task:

./node_modules/nyc/bin/nyc.js instrument test/ .nyc_output

And then a coverage report task:

./node_modules/nyc/bin/nyc.js report

When this runs I get no data in the report file:

25-Apr-2018 14:27:28    ----------|----------|----------|----------|----------|-------------------|
25-Apr-2018 14:27:28    File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
25-Apr-2018 14:27:28    ----------|----------|----------|----------|----------|-------------------|
25-Apr-2018 14:27:28    All files |        0 |        0 |        0 |        0 |                   |
25-Apr-2018 14:27:28    ----------|----------|----------|----------|----------|-------------------|

Any help would be greatly appreciated.

Upvotes: 2

Views: 2183

Answers (1)

JamesE
JamesE

Reputation: 3923

Figured this out. The best way to do it was to create a custom script within my package.json file and then call that from Bamboo.

package.json

"scripts": {
    "test-ci": "nyc -a --reporter=clover mocha --recursive --reporter mocha-bamboo-reporter"

Bamboo - Node.js task

run-script test-ci

Upvotes: 2

Related Questions