Mochajs test metadata support

nodejs

#1

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


#2

Came to say the same thing.


#3

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`;
  fs.mkdirSync(mochaOutput);
  const mochaFileOutput = `${mochaOutput}/tests.xml`;
  console.log('Saving test results to', mochaFileOutput);
  options.push('--reporter mocha-junit-reporter');
  options.push(`--reporter-options mochaFile=${mochaFileOutput}`);
}

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

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

Native support would be great, but this works ok.


#4

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.


#5

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


#6