UNPKG

1.85 kBJavaScriptView Raw
1import path from 'path';
2import { promises as fsPromises } from 'fs';
3import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
4import { fileUtils } from '../utils/file-utils.js';
5export class EventRecorderReporter {
6 constructor(log, options) {
7 this.log = log;
8 this.options = options;
9 this.allWork = [];
10 this.index = 0;
11 this.createBaseFolderTask = fileUtils.cleanFolder(this.options.eventReporter.baseDir);
12 }
13 writeToFile(methodName, data) {
14 const filename = path.join(this.options.eventReporter.baseDir, `${this.format(this.index++)}-${methodName}.json`);
15 this.log.debug(`Writing event ${methodName} to file ${filename}`);
16 return fsPromises.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' });
17 }
18 format(input) {
19 let str = input.toString();
20 for (let i = 10000; i > 1; i = i / 10) {
21 if (i > input) {
22 str = '0' + str;
23 }
24 }
25 return str;
26 }
27 work(eventName, data) {
28 this.allWork.push(this.createBaseFolderTask.then(() => this.writeToFile(eventName, data)));
29 }
30 onDryRunCompleted(event) {
31 this.work('onDryRunCompleted', event);
32 }
33 onMutationTestingPlanReady(event) {
34 this.work('onMutationTestingPlanReady', event);
35 }
36 onMutantTested(result) {
37 this.work('onMutantTested', result);
38 }
39 onMutationTestReportReady(report) {
40 this.work('onMutationTestReportReady', report);
41 }
42 onAllMutantsTested(results) {
43 this.work('onAllMutantsTested', results);
44 }
45 async wrapUp() {
46 await this.createBaseFolderTask;
47 await Promise.all(this.allWork);
48 }
49}
50EventRecorderReporter.inject = tokens(commonTokens.logger, commonTokens.options);
51//# sourceMappingURL=event-recorder-reporter.js.map
\No newline at end of file