forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease-post.test.js
More file actions
370 lines (290 loc) · 10.6 KB
/
Copy pathrelease-post.test.js
File metadata and controls
370 lines (290 loc) · 10.6 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
'use strict';
const test = require('tape');
const nock = require('nock');
const proxyquire = require('proxyquire').noCallThru();
const path = require('path');
test('explicitVersion(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
t.test('resolves when given a string argument', (t) => {
releasePost.explicitVersion('4.1.1').then((version) => {
t.equal(version, '4.1.1');
t.end();
});
});
t.test('rejects when given an falsy argument', (t) => {
releasePost.explicitVersion().then(null, (err) => {
t.equal(err.constructor, Error);
t.equal(err.message, 'Invalid "version" argument');
t.end();
});
});
t.end();
});
test('verifyDownloads(<version>)', (t) => {
const downloads = () => {
return [
{
title: 'Source Code',
url: 'https://nodejs.org/dist/v4.1.1/node-v4.1.1.tar.gz'
},
{
title: 'ARMv6 32-bit Binary',
url: 'https://nodejs.org/dist/v4.1.1/node-v4.1.1-linux-armv6l.tar.gz'
}
];
};
const releasePost = proxyquire('../../scripts/release-post', {
'./helpers/downloads': downloads
});
t.test('resolves to "<binary title>: url" when HEAD request succeed', (t) => {
const nodejsorg = nock('https://direct.nodejs.org')
.head('/dist/v4.1.1/node-v4.1.1.tar.gz')
.reply(200, 'OK');
releasePost.verifyDownloads('4.1.1').then((results) => {
const sourceDownload = results[0];
t.equal(
sourceDownload,
'Source Code: https://nodejs.org/dist/v4.1.1/node-v4.1.1.tar.gz'
);
t.true(nodejsorg.isDone(), 'nodejs.org was requested');
t.end();
});
});
t.test(
'resolves to "<binary title>: *Coming soon*" when HEAD request fails',
(t) => {
const nodejsorg = nock('https://direct.nodejs.org')
.head('/dist/v4.1.1/node-v4.1.1-linux-armv6l.tar.gz')
.reply(404, 'Not found');
releasePost.verifyDownloads('4.1.1').then((results) => {
const armDownload = results[1];
t.equal(armDownload, 'ARMv6 32-bit Binary: *Coming soon*');
t.true(nodejsorg.isDone(), 'nodejs.org was requested');
t.end();
});
}
);
t.end();
});
test('fetchShasums(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
t.test('resolves with content from response when succeeded', (t) => {
const nodejsorg = nock('https://nodejs.org')
.get('/dist/v4.1.1/SHASUMS256.txt.asc')
.reply(200, 'LIST OF SHASUMS HERE');
releasePost.fetchShasums('4.1.1').then((result) => {
t.equal(result, 'LIST OF SHASUMS HERE');
t.true(nodejsorg.isDone(), 'nodejs.org was requested');
t.end();
});
});
t.test('rejects with [INSERT SHASUMS HERE] when response fails', (t) => {
const nodejsorg = nock('https://nodejs.org')
.get('/dist/v4.1.1/SHASUMS256.txt.asc')
.reply(404, 'Not found');
releasePost.fetchShasums('4.1.1').then((result) => {
t.equal(result, '[INSERT SHASUMS HERE]');
t.true(nodejsorg.isDone(), 'nodejs.org was requested');
t.end();
});
});
t.end();
});
test('fetchChangelog(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
const changelogFixture = path.resolve(__dirname, 'CHANGELOG.fixture.md');
const changelogLegacyFixture = path.resolve(
__dirname,
'CHANGELOG.fixture.legacy.md'
);
t.test(
'resolves with section of changelog related to specified version',
(t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.replyWithFile(200, changelogFixture);
releasePost.fetchChangelog('4.1.1').then((changelog) => {
t.true(changelog.charAt(changelog.length - 1) !== '\n');
t.true(changelog.charAt(0) !== '\n');
t.true(changelog.includes('Fixed a bug introduced in v4.1.0'));
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
}
);
t.test('can fetch changelog of legacy versions of Node.js', (t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V012.md')
.replyWithFile(200, changelogLegacyFixture);
releasePost.fetchChangelog('0.12.9').then((changelog) => {
t.true(changelog.includes('Security Update'));
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.test(
'rejects when a matching version section could not be found in changelog',
(t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V012.md')
.reply(200, changelogLegacyFixture);
releasePost.fetchChangelog('0.12.1000').then(t.fail, (err) => {
t.equal(err.message, "Couldn't find matching changelog for 0.12.1000");
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
});
}
);
t.end();
});
test('fetchChangelogBody(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
t.test('does not include `## header` in matched version section', (t) => {
const changelogFixture = path.resolve(__dirname, 'CHANGELOG.fixture.md');
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.replyWithFile(200, changelogFixture);
releasePost.fetchChangelogBody('4.1.0').then((body) => {
t.true(body.startsWith('### Notable changes'));
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.test('does not include "```console', (t) => {
const changelogFixture = path.resolve(
__dirname,
'CHANGELOG.fixture.withconsole.md'
);
const githubWithConsole = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V15.md')
.replyWithFile(200, changelogFixture);
releasePost.fetchChangelogBody('15.1.0').then((body) => {
t.false(body.includes('```console'));
t.true(githubWithConsole.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.end();
});
test('fetchVersionPolicy(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
const changelogFixture = path.resolve(__dirname, 'CHANGELOG.fixture.md');
const changelogLegacyFixture = path.resolve(
__dirname,
'CHANGELOG.fixture.legacy.md'
);
t.test('finds "Current" version policy', (t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.replyWithFile(200, changelogFixture);
releasePost.fetchVersionPolicy('4.1.0').then((policy) => {
t.equal(policy, 'Stable');
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.test('finds "LTS" version policy', (t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.replyWithFile(200, changelogFixture);
releasePost.fetchVersionPolicy('4.2.0').then((policy) => {
t.equal(policy, 'LTS');
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.test('finds "LTS" version policy in legacy changelogs', (t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V012.md')
.replyWithFile(200, changelogLegacyFixture);
releasePost.fetchVersionPolicy('0.12.9').then((policy) => {
t.equal(policy, 'LTS');
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
}, t.fail);
});
t.end();
});
test('fetchAuthor(<version>)', (t) => {
const releasePost = require('../../scripts/release-post');
const changelogFixture = path.resolve(__dirname, 'CHANGELOG.fixture.md');
t.test('resolves with full name of release author via github.com', (t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.replyWithFile(200, changelogFixture);
const api = nock('https://api.github.com').get('/users/rvagg').reply(200, {
login: 'rvagg',
name: 'Rod Vagg'
});
releasePost.fetchAuthor('4.1.1').then((author) => {
t.equal(author, 'Rod Vagg');
t.true(github.isDone(), 'githubusercontent.com was requested');
t.true(api.isDone(), 'api.github.com was requested');
t.end();
}, t.fail);
});
t.test(
'rejects when a matching version section could not be found in changelog',
(t) => {
const github = nock('https://raw.githubusercontent.com')
.get('/nodejs/node/master/doc/changelogs/CHANGELOG_V4.md')
.reply(200, 'A changelog without version sections...');
releasePost.fetchAuthor('4.1.1').then(null, (err) => {
t.equal(err.message, "Couldn't find matching changelog for 4.1.1");
t.true(github.isDone(), 'githubusercontent.com was requested');
t.end();
});
}
);
t.end();
});
test('findLatestVersion<version>', (t) => {
const releasePost = require('../../scripts/release-post');
t.test('fetches the latest version from nodejs.org', (t) => {
nock('https://nodejs.org')
.get('/dist/index.json')
.reply(200, [{ version: 'v4.1.1' }, { version: 'v4.1.0' }]);
releasePost.findLatestVersion().then((version) => {
t.equal(version, '4.1.1');
t.end();
});
});
t.end();
});
test('writeToFile<object>', (t) => {
let fileExists;
const fs = {
access: (filename, flags, cb) => cb(!fileExists && new Error('ENOENT')),
writeFile: (filename, contents, cb) => cb()
};
const releasePost = proxyquire('../../scripts/release-post', { fs });
const results = {
version: '4.1.1',
content: 'Lets pretend this is a changelog'
};
t.test('rejects when blog post already exists', (t) => {
fileExists = true;
releasePost.writeToFile(results).then(t.fail, (err) => {
t.equal(err.message, 'Release post for 4.1.1 already exists!');
t.end();
});
});
t.test('writes content to locale/en/blog/release/v<VERSION>.md', (t) => {
fileExists = false;
releasePost.writeToFile(results).then((filepath) => {
const expectedPath = path.resolve(
__dirname,
'..',
'..',
'locale',
'en',
'blog',
'release',
`v${results.version}.md`
);
t.equal(filepath, expectedPath);
t.end();
}, t.fail);
});
t.end();
});