11cb0ef41Sopenharmony_ciimport '../common/index.mjs'; 21cb0ef41Sopenharmony_ciimport tmpdir from '../common/tmpdir.js'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciimport assert from 'assert'; 51cb0ef41Sopenharmony_ciimport { spawnSync } from 'child_process'; 61cb0ef41Sopenharmony_ciimport fs from 'fs'; 71cb0ef41Sopenharmony_ciimport path from 'path'; 81cb0ef41Sopenharmony_ciimport { fileURLToPath } from 'url'; 91cb0ef41Sopenharmony_ciimport util from 'util'; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst debuglog = util.debuglog('test'); 121cb0ef41Sopenharmony_ciconst versionsTool = fileURLToPath( 131cb0ef41Sopenharmony_ci new URL('../../tools/doc/versions.mjs', import.meta.url)); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// At the time of writing these are the minimum expected versions. 161cb0ef41Sopenharmony_ci// New versions of Node.js do not have to be explicitly added here. 171cb0ef41Sopenharmony_ciconst expected = [ 181cb0ef41Sopenharmony_ci '12.x', 191cb0ef41Sopenharmony_ci '11.x', 201cb0ef41Sopenharmony_ci '10.x', 211cb0ef41Sopenharmony_ci '9.x', 221cb0ef41Sopenharmony_ci '8.x', 231cb0ef41Sopenharmony_ci '7.x', 241cb0ef41Sopenharmony_ci '6.x', 251cb0ef41Sopenharmony_ci '5.x', 261cb0ef41Sopenharmony_ci '4.x', 271cb0ef41Sopenharmony_ci '0.12.x', 281cb0ef41Sopenharmony_ci '0.10.x', 291cb0ef41Sopenharmony_ci]; 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_citmpdir.refresh(); 321cb0ef41Sopenharmony_ciconst versionsFile = path.join(tmpdir.path, 'versions.json'); 331cb0ef41Sopenharmony_cidebuglog(`${process.execPath} ${versionsTool} ${versionsFile}`); 341cb0ef41Sopenharmony_ciconst opts = { cwd: tmpdir.path, encoding: 'utf8' }; 351cb0ef41Sopenharmony_ciconst cp = spawnSync(process.execPath, [ versionsTool, versionsFile ], opts); 361cb0ef41Sopenharmony_cidebuglog(cp.stderr); 371cb0ef41Sopenharmony_cidebuglog(cp.stdout); 381cb0ef41Sopenharmony_ciassert.strictEqual(cp.stdout, ''); 391cb0ef41Sopenharmony_ciassert.strictEqual(cp.signal, null); 401cb0ef41Sopenharmony_ciassert.strictEqual(cp.status, 0); 411cb0ef41Sopenharmony_ciconst versions = JSON.parse(fs.readFileSync(versionsFile)); 421cb0ef41Sopenharmony_cidebuglog(versions); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci// Coherence checks for each returned version. 451cb0ef41Sopenharmony_cifor (const version of versions) { 461cb0ef41Sopenharmony_ci const tested = util.inspect(version); 471cb0ef41Sopenharmony_ci const parts = version.num.split('.'); 481cb0ef41Sopenharmony_ci const expectedLength = parts[0] === '0' ? 3 : 2; 491cb0ef41Sopenharmony_ci assert.strictEqual(parts.length, expectedLength, 501cb0ef41Sopenharmony_ci `'num' from ${tested} should be '<major>.x'.`); 511cb0ef41Sopenharmony_ci assert.strictEqual(parts[parts.length - 1], 'x', 521cb0ef41Sopenharmony_ci `'num' from ${tested} doesn't end in '.x'.`); 531cb0ef41Sopenharmony_ci const isEvenRelease = Number.parseInt(parts[expectedLength - 2]) % 2 === 0; 541cb0ef41Sopenharmony_ci const hasLtsProperty = Object.hasOwn(version, 'lts'); 551cb0ef41Sopenharmony_ci if (hasLtsProperty) { 561cb0ef41Sopenharmony_ci // Odd-numbered versions of Node.js are never LTS. 571cb0ef41Sopenharmony_ci assert.ok(isEvenRelease, `${tested} should not be an 'lts' release.`); 581cb0ef41Sopenharmony_ci assert.ok(version.lts, `'lts' from ${tested} should 'true'.`); 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci// Check that the minimum number of versions were returned. 631cb0ef41Sopenharmony_ci// Later versions are allowed, but not checked for here (they were checked 641cb0ef41Sopenharmony_ci// above). 651cb0ef41Sopenharmony_ci// Also check for the previous semver major -- From the main branch this will be 661cb0ef41Sopenharmony_ci// the most recent major release. 671cb0ef41Sopenharmony_ciconst thisMajor = Number.parseInt(process.versions.node.split('.')[0]); 681cb0ef41Sopenharmony_ciconst prevMajorString = `${thisMajor - 1}.x`; 691cb0ef41Sopenharmony_ciif (!expected.includes(prevMajorString)) { 701cb0ef41Sopenharmony_ci expected.unshift(prevMajorString); 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_cifor (const version of expected) { 731cb0ef41Sopenharmony_ci assert.ok(versions.find((x) => x.num === version), 741cb0ef41Sopenharmony_ci `Did not find entry for '${version}' in ${util.inspect(versions)}`); 751cb0ef41Sopenharmony_ci} 76