Mochajs test metadata support



mocha is a popular node testing library. It would be helpful to automatically pull test results.


Came to say the same thing.


Here’s a quick little lib I made for running the suite locally and in circle.

import cp from 'child_process';
import fs from 'fs';
const options = [];

if (process.env.CIRCLECI) {
  const mochaOutput = `${process.env.CIRCLE_TEST_REPORTS}/mocha`;
  const mochaFileOutput = `${mochaOutput}/tests.xml`;
  console.log('Saving test results to', mochaFileOutput);
  options.push('--reporter mocha-junit-reporter');
  options.push(`--reporter-options mochaFile=${mochaFileOutput}`);

const cmd = `mocha ${options.join(' ')}`;

console.log('running', cmd);
cp.execSync(cmd, { stdio: 'inherit' });

Native support would be great, but this works ok.


FWIW we use the mocha jenkins reporter for this… it spits out JUnit xml, the std output format is not super great but it works.


thanks. I wanted something that I could read on my local machine and something that worked on circle ci. This checks process.env.CIRCLECI.