1import '../common/index.mjs'; 2import tmpdir from '../common/tmpdir.js'; 3 4import assert from 'assert'; 5import { spawnSync } from 'child_process'; 6import fs from 'fs'; 7import path from 'path'; 8import { fileURLToPath } from 'url'; 9import util from 'util'; 10 11const debuglog = util.debuglog('test'); 12const versionsTool = fileURLToPath( 13 new URL('../../tools/doc/versions.mjs', import.meta.url)); 14 15// At the time of writing these are the minimum expected versions. 16// New versions of Node.js do not have to be explicitly added here. 17const expected = [ 18 '12.x', 19 '11.x', 20 '10.x', 21 '9.x', 22 '8.x', 23 '7.x', 24 '6.x', 25 '5.x', 26 '4.x', 27 '0.12.x', 28 '0.10.x', 29]; 30 31tmpdir.refresh(); 32const versionsFile = path.join(tmpdir.path, 'versions.json'); 33debuglog(`${process.execPath} ${versionsTool} ${versionsFile}`); 34const opts = { cwd: tmpdir.path, encoding: 'utf8' }; 35const cp = spawnSync(process.execPath, [ versionsTool, versionsFile ], opts); 36debuglog(cp.stderr); 37debuglog(cp.stdout); 38assert.strictEqual(cp.stdout, ''); 39assert.strictEqual(cp.signal, null); 40assert.strictEqual(cp.status, 0); 41const versions = JSON.parse(fs.readFileSync(versionsFile)); 42debuglog(versions); 43 44// Coherence checks for each returned version. 45for (const version of versions) { 46 const tested = util.inspect(version); 47 const parts = version.num.split('.'); 48 const expectedLength = parts[0] === '0' ? 3 : 2; 49 assert.strictEqual(parts.length, expectedLength, 50 `'num' from ${tested} should be '<major>.x'.`); 51 assert.strictEqual(parts[parts.length - 1], 'x', 52 `'num' from ${tested} doesn't end in '.x'.`); 53 const isEvenRelease = Number.parseInt(parts[expectedLength - 2]) % 2 === 0; 54 const hasLtsProperty = version.hasOwnProperty('lts'); 55 if (hasLtsProperty) { 56 // Odd-numbered versions of Node.js are never LTS. 57 assert.ok(isEvenRelease, `${tested} should not be an 'lts' release.`); 58 assert.ok(version.lts, `'lts' from ${tested} should 'true'.`); 59 } 60} 61 62// Check that the minimum number of versions were returned. 63// Later versions are allowed, but not checked for here (they were checked 64// above). 65// Also check for the previous semver major -- From master this will be the 66// most recent major release. 67const thisMajor = Number.parseInt(process.versions.node.split('.')[0]); 68const prevMajorString = `${thisMajor - 1}.x`; 69if (!expected.includes(prevMajorString)) { 70 expected.unshift(prevMajorString); 71} 72for (const version of expected) { 73 assert.ok(versions.find((x) => x.num === version), 74 `Did not find entry for '${version}' in ${util.inspect(versions)}`); 75} 76