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