Skip to content

Commit 5b2ea12

Browse files
committed
test: add test to validate changelogs for releases
Add a new test to check that the changelog files have been correctly updated for releases. PR-URL: #45325 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 436a596 commit 5b2ea12

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
'use strict';
2+
3+
// This test checks that the changelogs contain an entry for releases.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const path = require('path');
9+
10+
const getDefine = (text, name) => {
11+
const regexp = new RegExp(`#define\\s+${name}\\s+(.*)`);
12+
const match = regexp.exec(text);
13+
assert.notStrictEqual(match, null);
14+
return match[1];
15+
};
16+
17+
const srcRoot = path.join(__dirname, '..', '..');
18+
const mainChangelogFile = path.join(srcRoot, 'CHANGELOG.md');
19+
const versionFile = path.join(srcRoot, 'src', 'node_version.h');
20+
const versionText = fs.readFileSync(versionFile, { encoding: 'utf8' });
21+
const release = getDefine(versionText, 'NODE_VERSION_IS_RELEASE') !== '0';
22+
23+
if (!release) {
24+
common.skip('release bit is not set');
25+
}
26+
27+
const major = getDefine(versionText, 'NODE_MAJOR_VERSION');
28+
const minor = getDefine(versionText, 'NODE_MINOR_VERSION');
29+
const patch = getDefine(versionText, 'NODE_PATCH_VERSION');
30+
const versionForRegex = `${major}\\.${minor}\\.${patch}`;
31+
32+
const lts = getDefine(versionText, 'NODE_VERSION_IS_LTS') !== '0';
33+
const codename = getDefine(versionText, 'NODE_VERSION_LTS_CODENAME')
34+
.slice(1, -1);
35+
// If the LTS bit is set there should be a codename.
36+
if (lts) {
37+
assert.notStrictEqual(codename, '');
38+
}
39+
40+
const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`;
41+
// Check CHANGELOG_V*.md
42+
{
43+
const changelog = fs.readFileSync(path.join(srcRoot, changelogPath),
44+
{ encoding: 'utf8' });
45+
// Check title matches major version.
46+
assert.match(changelog, new RegExp(`# Node\\.js ${major} ChangeLog`));
47+
// Check table header
48+
let tableHeader;
49+
if (lts) {
50+
tableHeader = new RegExp(`<th>LTS '${codename}'</th>`);
51+
} else {
52+
tableHeader = /<th>Current<\/th>/;
53+
}
54+
assert.match(changelog, tableHeader);
55+
// Check table contains link to this release.
56+
assert.match(changelog, new RegExp(`<a href="#${versionForRegex}">${versionForRegex}</a>`));
57+
// Check anchor for this release.
58+
assert.match(changelog, new RegExp(`<a id="${versionForRegex}"></a>`));
59+
// Check title for changelog entry.
60+
let title;
61+
if (lts) {
62+
title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${codename}' \\(LTS\\), @\\S+`);
63+
} else {
64+
title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} \\(Current\\), @\\S+`);
65+
}
66+
assert.match(changelog, title);
67+
}
68+
69+
// Main CHANGELOG.md checks
70+
{
71+
const mainChangelog = fs.readFileSync(mainChangelogFile,
72+
{ encoding: 'utf8' });
73+
// Check for the link to the appropriate CHANGELOG_V*.md file.
74+
let linkToChangelog;
75+
if (lts) {
76+
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Long Term Support\\*\\*`);
77+
} else {
78+
linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Current\\*\\*`);
79+
}
80+
assert.match(mainChangelog, linkToChangelog);
81+
// Check table header.
82+
let tableHeader;
83+
if (lts) {
84+
tableHeader = new RegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${changelogPath}">${major}</a><sup>LTS</sup></th>`);
85+
} else {
86+
tableHeader = new RegExp(`<th title="Current"><a href="${changelogPath}">${major}</a> \\(Current\\)</th>`);
87+
}
88+
assert.match(mainChangelog, tableHeader);
89+
// Check the table contains a link to the release in the appropriate
90+
// CHANGELOG_V*.md file.
91+
const linkToVersion = new RegExp(`<b><a href="${changelogPath}#${versionForRegex}">${versionForRegex}</a></b><br/>`);
92+
assert.match(mainChangelog, linkToVersion);
93+
}

0 commit comments

Comments
 (0)