| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7048360 commit 6733556
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,89 @@ | |||
| 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').slice(1, -1); | ||
| 34 | + // If the LTS bit is set there should be a codename. | ||
| 35 | + if (lts) { | ||
| 36 | + assert.notStrictEqual(codename, ''); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + const 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments