I am currently tackling an issue where I am seeking to identify the specific test cases that fail when running a test suite for any javascript/node.js application. Finding a programmatic solution is crucial for this task.
For instance, let's consider the test output shown above. In this scenario, I aim to develop an external JavaScript script that can pinpoint the exact test case that failed.
At present, my concept revolves around executing npm test
in a child process of JavaScript and capturing its output from the standard output stream. The idea is to parse the output and extract the necessary details, as illustrated below:
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++;
});
Despite this being a viable approach, it may seem quite rigid. My preference would be to adopt a more versatile method that works across various test modules beyond just Mocha.
Your assistance on this matter would be highly valued! Thank you.