Skip to content

Commit eff6aa1

Browse files
committed
test(snapshots): scrub resolved npm/npx binary paths from dry-run output
1 parent 7841edd commit eff6aa1

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

packages/cli/test/integration/cli/cmd-raw-npm.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('socket raw-npm', async () => {
8484
8585
[DryRun]: Would execute raw npm command
8686
87-
Command: /[HOME]/.socket/_wheelhouse/rack/npm/12.0.1/package/bin/npm-cli.js
87+
Command: [NPM_CLI]
8888
Arguments: --dry-run --config {"apiToken":"fakeToken"}
8989
9090
Run without --dry-run to execute this command."

packages/cli/test/integration/cli/cmd-raw-npx.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('socket raw-npx', async () => {
8484
8585
[DryRun]: Would execute raw pnpm exec command
8686
87-
Command: /[HOME]/.socket/_wheelhouse/rack/npm/12.0.1/package/bin/npx-cli.js
87+
Command: [NPX_CLI]
8888
Arguments: --dry-run --config {"apiToken":"fakeToken"}
8989
9090
Run without --dry-run to execute this command."

packages/cli/test/util/scrub-snapshot-data.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ export function scrubSnapshotData(
104104
// Temp directories.
105105
scrubbed = scrubbed.replace(/\/tmp\/[a-zA-Z0-9_-]+/g, '/[TEMP]')
106106
scrubbed = scrubbed.replace(/\\Temp\\[a-zA-Z0-9_-]+/gi, '\\[TEMP]')
107+
108+
// Resolved npm/npx binary paths. The raw-npm/raw-npx dry-run prints the
109+
// npm install it resolved, which varies by machine (wheelhouse rack copy
110+
// locally, hostedtoolcache npm in CI) and by rack npm version.
111+
scrubbed = scrubbed.replace(/\S+[\\/]npm-cli\.js/g, '[NPM_CLI]')
112+
scrubbed = scrubbed.replace(/\S+[\\/]npx-cli\.js/g, '[NPX_CLI]')
107113
}
108114

109115
// Phase 3: IDs and UUIDs.

packages/cli/test/util/scrub-snapshot-data.test.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ Updated: 2 days ago
220220
const result = scrubSnapshotData(input)
221221
expect(result).toBe('Working in [PROJECT]/src/utils')
222222
})
223+
224+
it('should scrub resolved npm and npx binary paths', () => {
225+
const input = [
226+
'Command: /opt/hostedtoolcache/node/26.3.0/x64/lib/node_modules/npm/bin/npx-cli.js',
227+
'Command: ~/.socket/_wheelhouse/rack/npm/12.0.1/package/bin/npm-cli.js',
228+
].join('\n')
229+
const result = scrubSnapshotData(input)
230+
expect(result).toBe('Command: [NPX_CLI]\nCommand: [NPM_CLI]')
231+
})
223232
})
224233

225234
describe('toSnapshotString', () => {

0 commit comments

Comments
 (0)