Support test artifacts from istanbul/mocha for node.js projects

nodejs

#1

This was a problem for me, but @drazisil pointed me at https://www.npmjs.com/package/mocha-junit-reporter and that solved all my problems. THANKS!


#2

I have this working with gulp and https://github.com/drazisil/node-bitcoin-rpc

Relevant parts:

circle.yml:

machine:
  node:
    version: v0.11.13
  environment:
    COVERALLS_REPO_TOKEN: "xxx"
    CIRCLE_ARTIFACTS: "~/node-p2pool/coverage"
general:
  artifacts:
    - "coverage" # relative to the user's home directory

Gulpfile.js:

gulp.task('test', ['pre-test'], function (cb) {
  return gulp.src(['./test/**/*.js'])
  .pipe(mocha({ reporter: 'spec' }))
  .pipe(istanbul.writeReports()) // stores reports in "coverage" directory
})

I actually switched to Circle from Travis due to an ad on coveralls, so then I had to figure this out. Hope it helps! :smiley:


#3

Well, I have managed to grab all the coverage reports and put them in the artifacts location, but CircleCI is not able to tell me test pass/fail #s. Does your solution do that?


#4

Yes.

For the above code my artifacts tab looks like this:

The index.html is here: https://circle-artifacts.com/gh/drazisil/node-bitcoin-rpc/27/artifacts/0/home/ubuntu/node-bitcoin-rpc/coverage/lcov-report/index.html


#5

I’m looking at your run: https://circleci.com/gh/drazisil/node-bitcoin-rpc/27

CircleCI doesn’t know how many tests your code ran. I have a java project using junit and on the Test Results tab, it says “Your build ran 9 tests in junit with 0 failures.” My feature request is to do the same thing for node.js projects using istanbul.


#7

I’ve added https://www.npmjs.com/package/mocha-junit-reporter to get the junit output.

The output is https://circle-artifacts.com/gh/drazisil/node-bitcoin-rpc/31/artifacts/0/home/ubuntu/node-bitcoin-rpc/test-results.xml

The files are at https://github.com/drazisil/node-bitcoin-rpc/tree/test-junit-reports

Affected files:

  • Gulpfile.js
  • circle.js

#8

mocha-junit-reporter is just what I needed! Many thanks! Is it possible to resolve my Feature Request as not needed?


#9

I think probably by choosing the fixed/solution link next to the post that fixed it. Happy to help! :smiley:


#10

As a final post, for those who are interested, I adjusted the instructions so CircleCi now sees and reports the junit results in the test metadata tab

https://circleci.com/gh/drazisil/node-bitcoin-rpc/37

Using:

  • Gulp
  • Mocha
  • mocha-junit-reporter
  • gulp-mocha
  • gulp-istanbul

circle.yml section:

general:
  artifacts:
    - "coverage" # relative to the user's home directory
    - $CIRCLE_TEST_REPORTS

Gulp Tasks:

gulp.task('pre-test', function () {
  return gulp.src(['lib/**/*.js'])
    // Covering files
    .pipe(istanbul())
    // Force `require` to return covered files
    .pipe(istanbul.hookRequire())
})

gulp.task('test', ['pre-test'], function (cb) {
  return gulp.src([
    './test/**/*.js'
  ])
  .pipe(mocha({
    reporter: 'mocha-junit-reporter',
    reporterOptions: {
        mochaFile: process.env.CIRCLE_TEST_REPORTS + '/junit/results.xml'
    }
}))
  .pipe(istanbul.writeReports()) // stores reports in "coverage" directory
})

#11