This repository was archived by the owner on Feb 10, 2025. It is now read-only.
forked from mikepenz/action-junit-report-legacy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.test.js
134 lines (115 loc) · 4.22 KB
/
action.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const core = require('@actions/core');
const github = require('@actions/github');
const nock = require('nock');
const action = require('./action');
const {
finishedWithFailures,
finishedSuccess,
nothingFound,
nothingFoundSuccess,
masterSuccess
} = require('./action.test.fixtures');
jest.setTimeout(20000);
let inputs = {};
describe('action should work', () => {
beforeAll(() => {
// https://github.com/actions/checkout/blob/v2.1.0/__test__/input-helper.test.ts
jest.spyOn(core, 'getInput').mockImplementation(name => {
return inputs[name];
});
jest.spyOn(core, 'error').mockImplementation(jest.fn());
jest.spyOn(core, 'warning').mockImplementation(jest.fn());
jest.spyOn(core, 'info').mockImplementation(jest.fn());
jest.spyOn(core, 'debug').mockImplementation(jest.fn());
github.context.payload.pull_request = {
html_url: 'https://github.com/mikepenz/action-junit-report',
head: { sha: 'sha123' }
};
jest.spyOn(github.context, 'repo', 'get').mockImplementation(() => {
return {
owner: 'mikepenz',
repo: 'action-junit-report'
};
});
});
beforeEach(() => {
// Reset inputs
inputs = {
report_paths: '**/surefire-reports/TEST-*.xml',
github_token: 'GITHUB_TOKEN',
check_name: 'Test Report',
fails_if_no_test_results: 'true'
};
});
afterAll(() => {
jest.restoreAllMocks();
});
it('should parse surefire reports and send a check run to GitHub', async () => {
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/mikepenz/action-junit-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();
expect(request).toStrictEqual(finishedWithFailures);
});
it('should send all ok if no tests were broken', async () => {
inputs.report_paths = '**/surefire-reports/TEST-*AllOkTest.xml';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/mikepenz/action-junit-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();
expect(request).toStrictEqual(finishedSuccess);
});
it('should send failure if no test results were found', async () => {
inputs.report_paths = '**/xxx/*.xml';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/mikepenz/action-junit-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();
expect(request).toStrictEqual(nothingFound);
});
it('should send success if no test results were found but fails_if_no_test_results is false', async () => {
inputs.report_paths = '**/xxx/*.xml';
inputs.fails_if_no_test_results = 'false';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/mikepenz/action-junit-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();
expect(request).toStrictEqual(nothingFoundSuccess);
});
it('should send reports to sha if no pr detected', async () => {
inputs.report_paths = '**/surefire-reports/TEST-*AllOkTest.xml';
github.context.payload.pull_request = undefined;
github.context.sha = 'masterSha123';
github.context.ref = 'refs/heads/master';
let request = null;
const scope = nock('https://api.github.com')
.post('/repos/mikepenz/action-junit-report/check-runs', body => {
request = body;
return body;
})
.reply(200, {});
await action();
scope.done();
expect(request).toStrictEqual(masterSuccess);
});
});