@stryker-mutator/mocha-runner
Version:
A plugin to use the mocha test runner in Stryker, the JavaScript mutation testing framework
54 lines • 2.36 kB
JavaScript
import { TestStatus } from '@stryker-mutator/api/test-runner';
import { Timer } from './timer.js';
export class StrykerMochaReporter {
constructor(runner) {
this.runner = runner;
this.timer = new Timer();
this.passedCount = 0;
this.tests = [];
this.registerEvents();
StrykerMochaReporter.currentInstance = this;
}
registerEvents() {
this.runner.on('start', () => {
var _a;
this.passedCount = 0;
this.timer.reset();
this.tests = [];
(_a = StrykerMochaReporter.log) === null || _a === void 0 ? void 0 : _a.debug('Starting Mocha test run');
});
this.runner.on('pass', (test) => {
const title = test.fullTitle();
const result = {
id: title,
name: title,
status: TestStatus.Success,
timeSpentMs: this.timer.elapsedMs(),
fileName: test.file,
};
this.tests.push(result);
this.passedCount++;
this.timer.reset();
});
this.runner.on('fail', (test, err) => {
var _a, _b, _c, _d, _e, _f;
const title = (_c = (_b = (_a = test.ctx) === null || _a === void 0 ? void 0 : _a.currentTest) === null || _b === void 0 ? void 0 : _b.fullTitle()) !== null && _c !== void 0 ? _c : test.fullTitle();
const result = {
id: title,
failureMessage: (_d = (err.message || err.stack)) !== null && _d !== void 0 ? _d : '<empty failure message>',
name: title,
status: TestStatus.Failed,
timeSpentMs: this.timer.elapsedMs(),
};
this.tests.push(result);
if ((_e = StrykerMochaReporter.log) === null || _e === void 0 ? void 0 : _e.isTraceEnabled()) {
(_f = StrykerMochaReporter.log) === null || _f === void 0 ? void 0 : _f.trace(`Test failed: ${test.fullTitle()}. Error: ${err.message}`);
}
});
this.runner.on('end', () => {
var _a;
(_a = StrykerMochaReporter.log) === null || _a === void 0 ? void 0 : _a.debug('Mocha test run completed: %s/%s passed', this.passedCount, this.tests.length);
});
}
}
//# sourceMappingURL=stryker-mocha-reporter.js.map