• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This test checks that the changelogs contain an entry for releases.
4
5const common = require('../common');
6const assert = require('assert');
7const fs = require('fs');
8const path = require('path');
9
10const 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
17const srcRoot = path.join(__dirname, '..', '..');
18const mainChangelogFile = path.join(srcRoot, 'CHANGELOG.md');
19const versionFile = path.join(srcRoot, 'src', 'node_version.h');
20const versionText = fs.readFileSync(versionFile, { encoding: 'utf8' });
21const release = getDefine(versionText, 'NODE_VERSION_IS_RELEASE') !== '0';
22
23if (!release) {
24  common.skip('release bit is not set');
25}
26
27const major = getDefine(versionText, 'NODE_MAJOR_VERSION');
28const minor = getDefine(versionText, 'NODE_MINOR_VERSION');
29const patch = getDefine(versionText, 'NODE_PATCH_VERSION');
30const versionForRegex = `${major}\\.${minor}\\.${patch}`;
31
32const lts = getDefine(versionText, 'NODE_VERSION_IS_LTS') !== '0';
33const codename = getDefine(versionText, 'NODE_VERSION_LTS_CODENAME')
34  .slice(1, -1);
35// If the LTS bit is set there should be a codename.
36if (lts) {
37  assert.notStrictEqual(codename, '');
38}
39
40const 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}
94