-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathrelease-notes.spec.ts
184 lines (178 loc) · 5 KB
/
release-notes.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
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
import fs from 'fs-extra';
import got from '../../../../lib/util/got';
import {
addReleaseNotes,
getReleaseNotes,
getReleaseNotesMd,
} from '../../../../lib/workers/pr/changelog/release-notes';
const ghGot: jest.Mock<Promise<{ body: unknown }>> = got as never;
const angularJsChangelogMd = fs.readFileSync(
'test/workers/pr/_fixtures/angular.js.md',
'utf8'
);
const jestChangelogMd = fs.readFileSync(
'test/workers/pr/_fixtures/jest.md',
'utf8'
);
const jsYamlChangelogMd = fs.readFileSync(
'test/workers/pr/_fixtures/js-yaml.md',
'utf8'
);
const contentsResponse = [
{ name: 'lib' },
{ name: 'CHANGELOG.md' },
{ name: 'README.md' },
];
jest.mock('../../../../lib/util/got');
describe('workers/pr/release-notes', () => {
describe('addReleaseNotes()', () => {
it('returns input if invalid', async () => {
const input = { a: 1 };
expect(await addReleaseNotes(input as never)).toEqual(input);
});
});
describe('getReleaseNotes()', () => {
it('should return null for release notes without body', async () => {
ghGot.mockResolvedValueOnce({
body: [{ tag_name: 'v1.0.0' }, { tag_name: 'v1.0.1' }],
});
const res = await getReleaseNotes(
'some/repository',
'1.0.0',
'some',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBeNull();
});
it.each([[''], ['v'], ['other-']])(
'gets release notes with body',
async prefix => {
ghGot.mockResolvedValueOnce({
body: [
{ tag_name: `${prefix}1.0.0` },
{
tag_name: `${prefix}1.0.1`,
body:
'some body #123, [#124](https://github.com/some/yet-other-repository/issues/124)',
},
],
});
const res = await getReleaseNotes(
'some/other-repository',
'1.0.1',
'other',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toMatchSnapshot();
}
);
});
describe('getReleaseNotesMd()', () => {
it('handles not found', async () => {
const res = await getReleaseNotesMd(
'chalk',
'2.0.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBeNull();
});
it('handles files mismatch', async () => {
ghGot.mockResolvedValueOnce({
body: [{ name: 'lib' }, { name: 'README.md' }],
});
const res = await getReleaseNotesMd(
'chalk',
'2.0.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBeNull();
});
it('handles wrong format', async () => {
ghGot
.mockResolvedValueOnce({ body: contentsResponse })
.mockResolvedValueOnce({
body: {
content: Buffer.from('not really markdown').toString('base64'),
},
});
const res = await getReleaseNotesMd(
'some/repository1',
'1.0.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBeNull();
});
it('handles bad markdown', async () => {
ghGot
.mockResolvedValueOnce({ body: contentsResponse })
.mockResolvedValueOnce({
body: {
content: Buffer.from(`#\nha\nha\n#\nha\nha`).toString('base64'),
},
});
const res = await getReleaseNotesMd(
'some/repository2',
'1.0.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).toBeNull();
});
it('parses angular.js', async () => {
ghGot
.mockResolvedValueOnce({ body: contentsResponse })
.mockResolvedValueOnce({
body: {
content: Buffer.from(angularJsChangelogMd).toString('base64'),
},
});
const res = await getReleaseNotesMd(
'angular/angular.js',
'1.6.9',
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
});
it('parses jest', async () => {
ghGot
.mockResolvedValueOnce({ body: contentsResponse })
.mockResolvedValueOnce({
body: {
content: Buffer.from(jestChangelogMd).toString('base64'),
},
});
const res = await getReleaseNotesMd(
'facebook/jest',
'22.0.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
});
it('parses js-yaml', async () => {
ghGot
.mockResolvedValueOnce({ body: contentsResponse })
.mockResolvedValueOnce({
body: {
content: Buffer.from(jsYamlChangelogMd).toString('base64'),
},
});
const res = await getReleaseNotesMd(
'nodeca/js-yaml',
'3.10.0',
'https://github.com/',
'https://api.github.com/'
);
expect(res).not.toBeNull();
expect(res).toMatchSnapshot();
});
});
});