|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// This test checks that the changelogs contain an entry for releases. |
| 4 | + |
| 5 | +constcommon=require('../common'); |
| 6 | +constassert=require('assert'); |
| 7 | +constfs=require('fs'); |
| 8 | +constpath=require('path'); |
| 9 | + |
| 10 | +constgetDefine=(text,name)=>{ |
| 11 | +constregexp=newRegExp(`#define\\s+${name}\\s+(.*)`); |
| 12 | +constmatch=regexp.exec(text); |
| 13 | +assert.notStrictEqual(match,null); |
| 14 | +returnmatch[1]; |
| 15 | +}; |
| 16 | + |
| 17 | +constsrcRoot=path.join(__dirname,'..','..'); |
| 18 | +constmainChangelogFile=path.join(srcRoot,'CHANGELOG.md'); |
| 19 | +constversionFile=path.join(srcRoot,'src','node_version.h'); |
| 20 | +constversionText=fs.readFileSync(versionFile,{encoding: 'utf8'}); |
| 21 | +constrelease=getDefine(versionText,'NODE_VERSION_IS_RELEASE')!=='0'; |
| 22 | + |
| 23 | +if(!release){ |
| 24 | +common.skip('release bit is not set'); |
| 25 | +} |
| 26 | + |
| 27 | +constmajor=getDefine(versionText,'NODE_MAJOR_VERSION'); |
| 28 | +constminor=getDefine(versionText,'NODE_MINOR_VERSION'); |
| 29 | +constpatch=getDefine(versionText,'NODE_PATCH_VERSION'); |
| 30 | +constversionForRegex=`${major}\\.${minor}\\.${patch}`; |
| 31 | + |
| 32 | +constlts=getDefine(versionText,'NODE_VERSION_IS_LTS')!=='0'; |
| 33 | +constcodename=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 | +constchangelogPath=`doc/changelogs/CHANGELOG_V${major}.md`; |
| 41 | +// Check CHANGELOG_V*.md |
| 42 | +{ |
| 43 | +constchangelog=fs.readFileSync(path.join(srcRoot,changelogPath), |
| 44 | +{encoding: 'utf8'}); |
| 45 | +// Check title matches major version. |
| 46 | +assert.match(changelog,newRegExp(`# Node\\.js ${major} ChangeLog`)); |
| 47 | +// Check table header |
| 48 | +lettableHeader; |
| 49 | +if(lts){ |
| 50 | +tableHeader=newRegExp(`<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,newRegExp(`<a href="#${versionForRegex}">${versionForRegex}</a>`)); |
| 57 | +// Check anchor for this release. |
| 58 | +assert.match(changelog,newRegExp(`<a id="${versionForRegex}"></a>`)); |
| 59 | +// Check title for changelog entry. |
| 60 | +lettitle; |
| 61 | +if(lts){ |
| 62 | +title=newRegExp(`## \\d{4}-\\d{2}-\\d{2}, Version ${versionForRegex} '${codename}' \\(LTS\\), @\\S+`); |
| 63 | +}else{ |
| 64 | +title=newRegExp(`## \\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 | +constmainChangelog=fs.readFileSync(mainChangelogFile, |
| 72 | +{encoding: 'utf8'}); |
| 73 | +// Check for the link to the appropriate CHANGELOG_V*.md file. |
| 74 | +letlinkToChangelog; |
| 75 | +if(lts){ |
| 76 | +linkToChangelog=newRegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Long Term Support\\*\\*`); |
| 77 | +}else{ |
| 78 | +linkToChangelog=newRegExp(`\\[Node\\.js ${major}\\]\\(${changelogPath}\\) \\*\\*Current\\*\\*`); |
| 79 | +} |
| 80 | +assert.match(mainChangelog,linkToChangelog); |
| 81 | +// Check table header. |
| 82 | +lettableHeader; |
| 83 | +if(lts){ |
| 84 | +tableHeader=newRegExp(`<th title="LTS Until \\d{4}-\\d{2}"><a href="${changelogPath}">${major}</a><sup>LTS</sup></th>`); |
| 85 | +}else{ |
| 86 | +tableHeader=newRegExp(`<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 | +constlinkToVersion=newRegExp(`<b><a href="${changelogPath}#${versionForRegex}">${versionForRegex}</a></b><br/>`); |
| 92 | +assert.match(mainChangelog,linkToVersion); |
| 93 | +} |
0 commit comments