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').slice(1, -1); 34// If the LTS bit is set there should be a codename. 35if (lts) { 36 assert.notStrictEqual(codename, ''); 37} 38 39const changelogPath = `doc/changelogs/CHANGELOG_V${major}.md`; 40// Check CHANGELOG_V*.md 41{ 42 const changelog = fs.readFileSync(path.join(srcRoot, changelogPath), { encoding: 'utf8' }); 43 // Check title matches major version. 44 assert.match(changelog, new RegExp(`# Node\\.js ${major} ChangeLog`)); 45 // Check table header 46 let tableHeader; 47 if (lts) { 48 tableHeader = new RegExp(`<th>LTS '${codename}'</th>`); 49 } else { 50 tableHeader = /<th>Current<\/th>/; 51 } 52 assert.match(changelog, tableHeader); 53 // Check table contains link to this release. 54 assert.match(changelog, new RegExp(`<a href="#${versionForRegex}">${versionForRegex}</a>`)); 55 // Check anchor for this release. 56 assert.match(changelog, new RegExp(`<a id="${versionForRegex}"></a>`)); 57 // Check title for changelog entry. 58 let title; 59 if (lts) { 60 title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${codename}' \\(LTS\\), @\\S+`); 61 } else { 62 title = new RegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} \\(Current\\), @\\S+`); 63 } 64 assert.match(changelog, title); 65} 66 67// Main CHANGELOG.md checks 68{ 69 const mainChangelog = fs.readFileSync(mainChangelogFile, { encoding: 'utf8' }); 70 // Check for the link to the appropriate CHANGELOG_V*.md file. 71 let linkToChangelog; 72 if (lts) { 73 linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Long Term Support\\*\\*`); 74 } else { 75 linkToChangelog = new RegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Current\\*\\*`); 76 } 77 assert.match(mainChangelog, linkToChangelog); 78 // Check table header. 79 let tableHeader; 80 if (lts) { 81 tableHeader = new RegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${changelogPath}">${major}</a> \\(LTS\\)</th>`); 82 } else { 83 tableHeader = new RegExp(`<th title="Current"><a href="${changelogPath}">${major}</a> \\(Current\\)</th>`); 84 } 85 assert.match(mainChangelog, tableHeader); 86 // Check the table contains a link to the release in the appropriate CHANGELOG_V*.md file. 87 const linkToVersion = new RegExp(`<b><a href="${changelogPath}#${versionForRegex}">${versionForRegex}</a></b><br/>`); 88 assert.match(mainChangelog, linkToVersion); 89} 90