samedi 8 février 2020

Externally determine which test cases fail - Javascript

I am working on an problem for which i need to detect which test cases fail for any javascript/node.js application, when that application's test suite is run. I need to determine this in a programmatic manner.

Mocha testsuite output result

Consider an example of test output above, for this example I would like to write an external javascript script that can tell me which particular test case failed.

Currently the only solution in my mind is; executing npm test in a javascript child process and read its output from the stdout stream, parse the output and extract necessary information, something like this.

const { spawn } = require('child_process');
const chalk = require('chalk');
const child = spawn('npm.cmd',['test']);

line = 0
child.stdout.on('data', (data) => {
  console.log(`${chalk.bgBlue('line = ' + line)} , data = ${data}`);
  line++;
});

However, this would be a very strict approach. I would like a more generic way of going about it, that can work for a variety of test modules(not just mocha).

Help would be appreciated !

Aucun commentaire:

Enregistrer un commentaire