-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
206 lines (165 loc) · 5.29 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import * as github from '@actions/github';
import * as core from '@actions/core';
import { formatCommits, generateChangelog, run } from '.';
import {
changelogCommits,
chStoryUrl,
formattedFullCommits,
formattedCommitsAll,
formattedPrOnlyCommits,
fullChangelog,
fullCommits,
prOnlyCommits,
url,
} from './testData';
let inputs = {};
jest.mock('@actions/core');
jest.mock('@actions/github', () => ({
context: {},
getOctokit: jest.fn(),
}));
jest.spyOn(core, 'getInput').mockImplementation((name) => {
return inputs[name];
});
jest.spyOn(core, 'info').mockImplementation((msg) => msg);
jest.spyOn(core, 'setFailed').mockImplementation((msg) => msg);
github.context.ref = 'refs/tags/v20.0.0';
github.context.sha = '1234567890123456789012345678901234567890';
github.context.payload = { repository: { url } };
describe('Release', () => {
describe('formatCommits(commits, chStoryUrl)', () => {
test('when commit messages contain all regex groups', () => {
const commits = fullCommits;
const formattedCommits = formatCommits(commits, chStoryUrl);
const expectedCommits = formattedFullCommits;
expect(formattedCommits).toEqual(expectedCommits);
});
test('when commit messages contain prMsg and prNumber only', () => {
const commits = prOnlyCommits;
const formattedCommits = formatCommits(commits, chStoryUrl);
const expectedCommits = formattedPrOnlyCommits;
expect(formattedCommits).toEqual(expectedCommits);
});
test('when commit messages are of mixed types', () => {
const commits = [...fullCommits, ...prOnlyCommits];
const formattedCommits = formatCommits(commits, chStoryUrl);
const expectedCommits = formattedCommitsAll;
expect(formattedCommits).toEqual(expectedCommits);
});
});
describe('generateChangelog(formattedCommits)', () => {
test('returns a properly formatted changelog', () => {
const commits = changelogCommits;
const formattedCommits = formatCommits(commits, chStoryUrl);
const changelog = generateChangelog(formattedCommits);
const expectedChangelog = fullChangelog;
expect(changelog).toEqual(expectedChangelog);
});
});
describe('run()', () => {
test('should exit if no ghToken provided', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'true',
chStoryUrl,
prerelease: 'true',
previousTag: 'v20.0.0',
};
await run();
expect(core.setFailed).toHaveBeenCalledWith('Must provide ghToken');
});
test("should exit if tag isn't properly formatted", async () => {
github.context.ref = 'refs/heads/v20.0.1';
inputs = {
createChangelog: 'true',
chStoryUrl,
ghToken: '123',
prerelease: 'true',
previousTag: 'v20.0.0',
};
await run();
expect(core.setFailed).toHaveBeenCalledWith('Ref must be a tag');
});
describe('on createChangelog: true', () => {
beforeEach(() => {
// Reset inputs
inputs = {};
});
test('should exit if no chStoryUrl provided', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'true',
ghToken: '123',
prerelease: 'true',
previousTag: 'v20.0.0',
};
await run();
expect(core.setFailed).toHaveBeenCalledWith('Must provide chStoryUrl');
});
test('should exit if no ghToken provided', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'true',
chStoryUrl,
prerelease: 'true',
previousTag: 'v20.0.0',
};
await run();
expect(core.setFailed).toHaveBeenCalledWith('Must provide ghToken');
});
test('should exit if no previousTag provided', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'true',
chStoryUrl,
ghToken: '123',
prerelease: 'true',
};
await run();
expect(core.setFailed).toHaveBeenCalledWith(
'Must provide a previousTag to create a changelog'
);
});
});
describe('on prerelease: true', () => {
beforeEach(() => {
// Reset inputs
inputs = {};
});
test('should call core.info', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'true',
chStoryUrl,
ghToken: '123',
prerelease: 'true',
previousTag: 'v20.0.0',
};
await run();
expect(core.info).toHaveBeenCalledWith(
'Tag v20.0.0: Creating a prerelease...'
);
});
});
describe('on prerelease: false', () => {
beforeEach(() => {
// Reset inputs
inputs = {};
});
test('should call core.info', async () => {
github.context.ref = 'refs/tags/v20.0.0';
inputs = {
createChangelog: 'false',
chStoryUrl,
ghToken: '123',
prerelease: 'false',
previousTag: 'v20.0.0',
};
await run();
expect(core.info).toHaveBeenCalledWith(
'Tag v20.0.0: Creating a release...'
);
});
});
});
});