Skip to content

Commit

Permalink
Lazily access new lazy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 21, 2024
1 parent e67e49d commit a09691e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions test/socket-cdxgen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type PromiseSpawnOptions = Exclude<Parameters<typeof spawn>[2], undefined> & {
encoding?: BufferEncoding | undefined
}

const { abortSignal, execPath, rootBinPath } = constants
const { abortSignal, rootBinPath } = constants

const entryPath = path.join(rootBinPath, 'cli.js')
const testPath = __dirname
Expand All @@ -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
)
Expand All @@ -38,15 +39,17 @@ 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'
)
}
await assert.rejects(
() =>
spawn(
execPath,
// Lazily access constants.execPath.
constants.execPath,
[entryPath, 'cdxgen', '-u', '-h', '--unknown'],
spawnOpts
),
Expand Down
5 changes: 3 additions & 2 deletions test/socket-npm.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down

0 comments on commit a09691e

Please sign in to comment.