/
json-reporter.spec.ts
71 lines (61 loc) · 2.34 KB
/
json-reporter.spec.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as path from 'path';
import { mutationTestReportSchema } from '@stryker-mutator/api/report';
import { testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';
import * as sinon from 'sinon';
import JsonReporter from '../../../src/reporters/json-reporter';
import * as JsonReporterUtil from '../../../src/reporters/reporter-util';
describe(JsonReporter.name, () => {
let writeFileStub: sinon.SinonStub;
let sut: JsonReporter;
beforeEach(() => {
writeFileStub = sinon.stub(JsonReporterUtil, 'writeFile');
sut = testInjector.injector.injectClass(JsonReporter);
});
describe('onMutationTestReportReady', () => {
it('should use configured file path', async () => {
const fileName = 'foo/bar/myReport.json';
const expectedPath = path.normalize(fileName);
testInjector.options.jsonReporter = {
fileName,
};
actReportReady();
await sut.wrapUp();
expect(testInjector.logger.debug).calledWith(`Using relative path ${expectedPath}`);
});
it('should use default base directory when no override is configured', async () => {
const expectedPath = path.normalize('reports/mutation/mutation.json');
actReportReady();
await sut.wrapUp();
expect(testInjector.logger.debug).calledWith(`Using relative path ${expectedPath}`);
});
it('should write the mutation report to disk', async () => {
const report: mutationTestReportSchema.MutationTestResult = {
files: {},
schemaVersion: '1.0',
thresholds: {
high: 80,
low: 60,
},
};
sut.onMutationTestReportReady(report);
await sut.wrapUp();
expect(writeFileStub).calledWith(path.resolve('reports', 'mutation', 'mutation.json'), JSON.stringify(report));
});
});
describe('wrapUp', () => {
it('should resolve when everything is OK', () => {
actReportReady();
return expect(sut.wrapUp()).eventually.undefined;
});
it('should reject when "writeFile" rejects', () => {
const expectedError = new Error('writeFile');
writeFileStub.rejects(expectedError);
actReportReady();
return expect(sut.wrapUp()).rejectedWith(expectedError);
});
});
function actReportReady() {
sut.onMutationTestReportReady({ files: {}, schemaVersion: '', thresholds: { high: 0, low: 0 } });
}
});