Skip to content

Commit 47718dc

Browse files
authored
chore: fix async realpath in smoke publish (#5836)
1 parent 7a5fd01 commit 47718dc

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

smoke-tests/tap-snapshots/test/index.js.test.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ All commands:
3232
unstar, update, version, view, whoami
3333
3434
Specify configs in the ini-formatted file:
35-
{CWD}/{TESTDIR}/project/.npmrc
35+
{NPM}/{TESTDIR}/project/.npmrc
3636
or on the command line via: npm <command> --key=value
3737
3838
More configuration info: npm help config
3939
Configuration fields: npm help 7 config
4040
41-
npm {CWD}
41+
npm {NPM}
4242
`
4343

4444
exports[`test/index.js TAP basic npm ci > should throw mismatch deps in lock file error 1`] = `
@@ -107,7 +107,7 @@ [email protected]
107107
`
108108

109109
exports[`test/index.js TAP basic npm init > should have successful npm init result 1`] = `
110-
Wrote to {CWD}/{TESTDIR}/project/package.json:
110+
Wrote to {NPM}/{TESTDIR}/project/package.json:
111111
112112
{
113113
"name": "project",
@@ -231,7 +231,7 @@ Object {
231231
`
232232

233233
exports[`test/index.js TAP basic npm ls > should have expected ls output 1`] = `
234-
[email protected] {CWD}/{TESTDIR}/project
234+
[email protected] {NPM}/{TESTDIR}/project
235235
236236
237237
`
@@ -347,7 +347,7 @@ exports[`test/index.js TAP basic npm pkg set scripts > should have expected set-
347347
`
348348

349349
exports[`test/index.js TAP basic npm prefix > should have expected prefix output 1`] = `
350-
{CWD}/{TESTDIR}/project
350+
{NPM}/{TESTDIR}/project
351351
`
352352

353353
exports[`test/index.js TAP basic npm run-script > should have expected run-script output 1`] = `

smoke-tests/test/fixtures/setup.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,32 @@ const testdirHelper = (obj) => {
3232
}
3333

3434
const getSpawnArgs = async () => {
35-
const cliBin = join('bin', 'npm-cli.js')
35+
const cliBin = join('bin', 'npm')
36+
const cliJsBin = join('bin', 'npm-cli.js')
37+
const npmLinks = await which('npm', { all: true })
38+
const npmPaths = await Promise.all(npmLinks.map(npm => fs.realpath(npm)))
39+
40+
const cleanNpmPaths = [...new Set([
41+
CLI_ROOT,
42+
join(CLI_ROOT, cliBin),
43+
join(CLI_ROOT, cliJsBin),
44+
...npmLinks,
45+
...npmPaths,
46+
...npmPaths.map(n => n.replace(sep + cliBin, '')),
47+
...npmPaths.map(n => n.replace(sep + cliJsBin, '')),
48+
])]
3649

3750
if (SMOKE_PUBLISH_NPM) {
3851
return {
3952
command: ['npm'],
40-
NPM: await which('npm').then(p => fs.realpath(p).replace(sep + cliBin)),
53+
NPM: cleanNpmPaths,
4154
}
4255
}
4356

4457
return {
45-
command: [process.execPath, join(CLI_ROOT, cliBin)],
58+
command: [process.execPath, join(CLI_ROOT, cliJsBin)],
4659
NODE: process.execPath,
47-
NPM: join(CLI_ROOT, cliBin),
60+
NPM: cleanNpmPaths,
4861
}
4962
}
5063

@@ -87,17 +100,24 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
87100
t.strictSame(registry.nock.activeMocks(), [], 'no active mocks after each')
88101
})
89102

90-
const { command, ...spawnPaths } = await getSpawnArgs()
91-
const cleanPaths = Object.entries({ ...spawnPaths, CWD: CLI_ROOT })
103+
const debugLog = debug || CI ? (...a) => console.error(...a) : () => {}
104+
const { command, ...spawnPaths } = await getSpawnArgs({ log: debugLog })
105+
const cleanPaths = Object.entries(spawnPaths)
92106

93107
const cleanOutput = s => {
94108
// sometimes we print normalized paths in snapshots regardless of
95109
// platform so replace those first then replace platform style paths
96110
for (const [key, value] of cleanPaths) {
97-
s = s.split(normalizePath(value)).join(`{${key}}`)
111+
const values = [].concat(value)
112+
for (const v of values) {
113+
s = s.split(normalizePath(v)).join(`{${key}}`)
114+
}
98115
}
99116
for (const [key, value] of cleanPaths) {
100-
s = s.split(value).join(`{${key}}`)
117+
const values = [].concat(value)
118+
for (const v of values) {
119+
s = s.split(v).join(`{${key}}`)
120+
}
101121
}
102122
return s
103123
.split(relative(CLI_ROOT, t.testdirName)).join('{TESTDIR}')
@@ -110,7 +130,7 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
110130
.replace(/^.*debug-[0-9]+.log$/gm, '')
111131
.replace(/in \d+ms$/gm, 'in {TIME}')
112132
}
113-
const log = debug || CI ? (...a) => console.error(cleanOutput(a.join(' '))) : () => {}
133+
const log = (...a) => debugLog(cleanOutput(a.join(' ')))
114134
t.cleanSnapshot = cleanOutput
115135

116136
const npm = async (...args) => {

0 commit comments

Comments
 (0)