Reputation: 355
Is there a way to check the number of executed tests in the Runner class? There are this ".then(failedCount => {" but this one only shows how many failed tests there are. I want to print the number of failed tests out of the total number of tests run, e.g. "2 / 10 test cases failed" where 2=failedCount and 10=totalNumberOfTestCases run.
Upvotes: 2
Views: 745
Reputation: 2903
You can redirect output from the JSON reporter to a Writable Stream instance and then retrieve the desired information from the report. Check the following example (requires Node.js 8+)
const createTestCafe = require('testcafe');
(async () => {
const testCafe = await createTestCafe();
let reportData = '';
await testCafe
.createRunner()
.src('test.js')
.browsers('chrome')
.reporter('spec')
.reporter('json', { write: data => reportData += data.toString() })
.run();
const report = JSON.parse(reportData);
console.log(`${report.total - report.passed}/${report.total} tests failed`);
await testCafe.close();
})();
Upvotes: 2