UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

51 lines 1.78 kB
import path from 'path'; import { promises as fsPromises } from 'fs'; import { commonTokens, tokens } from '@stryker-mutator/api/plugin'; import { fileUtils } from '../utils/file-utils.js'; export class EventRecorderReporter { log; options; static inject = tokens(commonTokens.logger, commonTokens.options); allWork = []; createBaseFolderTask; index = 0; constructor(log, options) { this.log = log; this.options = options; this.createBaseFolderTask = fileUtils.cleanFolder(this.options.eventReporter.baseDir); } writeToFile(methodName, data) { const filename = path.join(this.options.eventReporter.baseDir, `${this.format(this.index++)}-${methodName}.json`); this.log.debug(`Writing event ${methodName} to file ${filename}`); return fsPromises.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' }); } format(input) { let str = input.toString(); for (let i = 10000; i > 1; i = i / 10) { if (i > input) { str = '0' + str; } } return str; } work(eventName, data) { this.allWork.push(this.createBaseFolderTask.then(() => this.writeToFile(eventName, data))); } onDryRunCompleted(event) { this.work('onDryRunCompleted', event); } onMutationTestingPlanReady(event) { this.work('onMutationTestingPlanReady', event); } onMutantTested(result) { this.work('onMutantTested', result); } onMutationTestReportReady(report) { this.work('onMutationTestReportReady', report); } async wrapUp() { await this.createBaseFolderTask; await Promise.all(this.allWork); } } //# sourceMappingURL=event-recorder-reporter.js.map