|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { execFileSync, spawnSync } from 'node:child_process'; |
| 3 | +import { mkdirSync, readdirSync } from 'node:fs'; |
| 4 | +import { join, dirname, delimiter } from 'node:path'; |
| 5 | +import { artifact } from './harness.mjs'; |
| 6 | + |
| 7 | +// Build once on the release runtime, then install and exercise that exact tarball |
| 8 | +// on each minimum supported LTS runtime. No production telemetry is sent. |
| 9 | +const packed = artifact(); |
| 10 | +const packageRoot = new URL('../..', import.meta.url); |
| 11 | +try { |
| 12 | + for (const version of ['20.20.0', '22.22.0', '18.20.8', '20.19.0', '22.21.0']) { |
| 13 | + const runtimeRoot = join(packed.root, `node-${version}`); |
| 14 | + mkdirSync(runtimeRoot); |
| 15 | + execFileSync('npm', ['install', '--prefix', runtimeRoot, '--no-audit', '--no-fund', '--cache', join(packed.root, 'runtime-cache'), `node@${version}`], { stdio: 'pipe', timeout: 120000 }); |
| 16 | + const node = join(runtimeRoot, 'node_modules/node/bin/node'); |
| 17 | + const env = { ...process.env, PATH: `${dirname(node)}${delimiter}${process.env.PATH}`, PACKAGE_TRACKER_ANALYTICS: 'false', SETUP_TEST_TARBALL: packed.tarball }; |
| 18 | + if (['20.20.0', '22.22.0'].includes(version)) { |
| 19 | + const tests = [ |
| 20 | + ...['unit', 'integration'].flatMap(dir => readdirSync(new URL(`../${dir}/`, import.meta.url)).filter(f => f.endsWith('.test.mjs')).map(f => `tests/${dir}/${f}`)), |
| 21 | + ...['wizard', 'collectors', 'docker', 'safety', 'platform'].map(f => `tests/e2e/${f}.test.mjs`), |
| 22 | + ]; |
| 23 | + execFileSync(node, ['--test', '--test-concurrency=1', ...tests], { cwd: packageRoot, env, stdio: 'inherit', timeout: 600000 }); |
| 24 | + console.log(`Node ${version}: packed CLI and telemetry regression suites passed; artifact ${packed.digest}`); |
| 25 | + } else { |
| 26 | + const work = join(runtimeRoot, 'empty-home'); |
| 27 | + mkdirSync(work); |
| 28 | + const result = spawnSync(node, [join(packed.installed, 'bin.cjs')], { cwd: work, encoding: 'utf8', env: { PATH: '', HOME: work }, timeout: 10000 }); |
| 29 | + assert.equal(result.status, 1); |
| 30 | + assert.match(result.stderr, /requires Node.js 20\.20\+, 22\.22\+, or 23\.5\+/); |
| 31 | + assert.equal(result.stdout, ''); |
| 32 | + assert.deepEqual(readdirSync(work), []); |
| 33 | + console.log(`Node ${version}: rejected before importing the wizard`); |
| 34 | + } |
| 35 | + } |
| 36 | +} finally { |
| 37 | + packed.cleanup(); |
| 38 | +} |
0 commit comments