-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
93 lines (76 loc) · 2.41 KB
/
index.test.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const { run } = require('./index');
const core = require('@actions/core');
jest.mock('./xmlParser', () => ({
readFile: () => [],
}));
const result = {
testStrength: 75,
threshold: 80,
pass: false,
};
jest.mock('./computation', () => ({
computeResult: () => result,
}));
jest.mock('./reporter', () => ({
reportMutationTesting: () => {},
}));
const coreSetFailedSpy = jest.spyOn(core, 'setFailed');
describe('run', () => {
afterEach(() => {
delete process.env['INPUT_XML-REPORT-PATH'];
delete process.env['INPUT_THRESHOLD'];
delete process.env['INPUT_FAIL-WORKFLOW'];
});
test('Call everything with success', async () => {
// given
process.env['INPUT_XML-REPORT-PATH'] = './test.xml';
process.env['INPUT_THRESHOLD'] = '75';
process.env['INPUT_FAIL-WORKFLOW'] = 'false';
process.env['INPUT_MAX-ANNOTATIONS'] = '5';
// when
await run();
// then
expect(coreSetFailedSpy).toBeCalledTimes(0);
});
test('Call everything with failure and step set to failed', async () => {
// given
process.env['INPUT_XML-REPORT-PATH'] = './test.xml';
process.env['INPUT_THRESHOLD'] = '75';
process.env['INPUT_FAIL-WORKFLOW'] = 'true';
process.env['INPUT_MAX-ANNOTATIONS'] = '5';
// when
await run();
// then
expect(coreSetFailedSpy).toHaveBeenCalledWith(
`Test strength is not good enough: ${result.testStrength}% (required was ${result.threshold}%)`
);
});
test('Invalid threshold input', async () => {
// given
const threshold = '500';
process.env['INPUT_XML-REPORT-PATH'] = './test.xml';
process.env['INPUT_THRESHOLD'] = threshold;
process.env['INPUT_FAIL-WORKFLOW'] = 'true';
process.env['INPUT_MAX-ANNOTATIONS'] = '5';
// when
await run();
// then
expect(coreSetFailedSpy).toHaveBeenCalledWith(
`Threshold must be a number between 0 and 100. Invalid value: ${threshold}`
);
});
test('Invalid max-annotations input', async () => {
// given
const maxAnnotations = '100';
process.env['INPUT_XML-REPORT-PATH'] = './test.xml';
process.env['INPUT_THRESHOLD'] = '80';
process.env['INPUT_FAIL-WORKFLOW'] = 'true';
process.env['INPUT_MAX-ANNOTATIONS'] = maxAnnotations;
// when
await run();
// then
expect(coreSetFailedSpy).toHaveBeenCalledWith(
`GitHub API does not allow to create more than 50 annotations. Invalid value: ${maxAnnotations}`
);
});
});