From a09691e8f92936f9d40bbb893425293f32600fb5 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sat, 21 Dec 2024 06:22:47 -0500 Subject: [PATCH] Lazily access new lazy properties --- test/socket-cdxgen.test.ts | 11 +++++++---- test/socket-npm.test.cjs | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/socket-cdxgen.test.ts b/test/socket-cdxgen.test.ts index e3cb87b..91e5f6b 100644 --- a/test/socket-cdxgen.test.ts +++ b/test/socket-cdxgen.test.ts @@ -10,7 +10,7 @@ type PromiseSpawnOptions = Exclude[2], undefined> & { encoding?: BufferEncoding | undefined } -const { abortSignal, execPath, rootBinPath } = constants +const { abortSignal, rootBinPath } = constants const entryPath = path.join(rootBinPath, 'cli.js') const testPath = __dirname @@ -27,7 +27,8 @@ describe('Socket cdxgen command', async () => { for (const command of ['-h', '--help']) { // eslint-disable-next-line no-await-in-loop const ret = await spawn( - execPath, + // Lazily access constants.execPath. + constants.execPath, [entryPath, 'cdxgen', command], spawnOpts ) @@ -38,7 +39,8 @@ describe('Socket cdxgen command', async () => { for (const command of ['-u', '--unknown']) { // eslint-disable-next-line no-await-in-loop await assert.rejects( - () => spawn(execPath, [entryPath, 'cdxgen', command], spawnOpts), + // Lazily access constants.execPath. + () => spawn(constants.execPath, [entryPath, 'cdxgen', command], spawnOpts), e => e?.['stderr']?.startsWith(`Unknown argument: ${command}`), 'singular' ) @@ -46,7 +48,8 @@ describe('Socket cdxgen command', async () => { await assert.rejects( () => spawn( - execPath, + // Lazily access constants.execPath. + constants.execPath, [entryPath, 'cdxgen', '-u', '-h', '--unknown'], spawnOpts ), diff --git a/test/socket-npm.test.cjs b/test/socket-npm.test.cjs index 1af39ab..0a33b63 100644 --- a/test/socket-npm.test.cjs +++ b/test/socket-npm.test.cjs @@ -8,7 +8,7 @@ const { describe, it } = require('node:test') const spawn = require('@npmcli/promise-spawn') const constants = require('../dist/constants.js') -const { abortSignal, execPath, rootBinPath } = constants +const { abortSignal, rootBinPath } = constants const entryPath = path.join(rootBinPath, 'cli.js') const testPath = __dirname @@ -29,7 +29,8 @@ for (const npm of ['npm8', 'npm10']) { it('should bail on new typosquat', async () => { await assert.rejects( () => - spawn(execPath, [entryPath, 'npm', 'install', 'bowserify'], { + // Lazily access constants.execPath. + spawn(constants.execPath, [entryPath, 'npm', 'install', 'bowserify'], { cwd: path.join(npmFixturesPath, 'lacking-typosquat'), encoding: 'utf8', env: {