/
json-reporter.ts
36 lines (26 loc) · 1.32 KB
/
json-reporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as path from 'path';
import { StrykerOptions } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
import { mutationTestReportSchema, Reporter } from '@stryker-mutator/api/report';
import fileUrl = require('file-url');
import * as ReporterUtil from './reporter-util';
const INDENTION_LEVEL = 0;
export const RESOURCES_DIR_NAME = 'strykerResources';
export default class JsonReporter implements Reporter {
private mainPromise: Promise<void> | undefined;
constructor(private readonly options: StrykerOptions, private readonly log: Logger) {}
public static readonly inject = tokens(commonTokens.options, commonTokens.logger);
public onMutationTestReportReady(report: mutationTestReportSchema.MutationTestResult) {
this.mainPromise = this.generateReport(report);
}
public wrapUp() {
return this.mainPromise;
}
private async generateReport(report: mutationTestReportSchema.MutationTestResult) {
const filePath = path.normalize(this.options.jsonReporter.fileName);
this.log.debug(`Using relative path ${filePath}`);
await ReporterUtil.writeFile(path.resolve(filePath), JSON.stringify(report, null, INDENTION_LEVEL));
this.log.info(`Your report can be found at: ${fileUrl(filePath)}`);
}
}