Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions smoke-tests/tap-snapshots/test/index.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ All commands:
unstar, update, version, view, whoami

Specify configs in the ini-formatted file:
{CWD}/{TESTDIR}/project/.npmrc
{NPM}/{TESTDIR}/project/.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

npm {CWD}
npm {NPM}
`

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

exports[`test/index.js TAP basic npm init > should have successful npm init result 1`] = `
Wrote to {CWD}/{TESTDIR}/project/package.json:
Wrote to {NPM}/{TESTDIR}/project/package.json:

{
"name": "project",
Expand Down Expand Up @@ -231,7 +231,7 @@ Object {
`

exports[`test/index.js TAP basic npm ls > should have expected ls output 1`] = `
[email protected] {CWD}/{TESTDIR}/project
[email protected] {NPM}/{TESTDIR}/project
+-- [email protected]
\`-- [email protected]
`
Expand Down Expand Up @@ -347,7 +347,7 @@ exports[`test/index.js TAP basic npm pkg set scripts > should have expected set-
`

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

exports[`test/index.js TAP basic npm run-script > should have expected run-script output 1`] = `
Expand Down
38 changes: 29 additions & 9 deletions smoke-tests/test/fixtures/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,32 @@ const testdirHelper = (obj) => {
}

const getSpawnArgs = async () => {
const cliBin = join('bin', 'npm-cli.js')
const cliBin = join('bin', 'npm')
const cliJsBin = join('bin', 'npm-cli.js')
const npmLinks = await which('npm', { all: true })
const npmPaths = await Promise.all(npmLinks.map(npm => fs.realpath(npm)))

const cleanNpmPaths = [...new Set([
CLI_ROOT,
join(CLI_ROOT, cliBin),
join(CLI_ROOT, cliJsBin),
...npmLinks,
...npmPaths,
...npmPaths.map(n => n.replace(sep + cliBin, '')),
...npmPaths.map(n => n.replace(sep + cliJsBin, '')),
])]

if (SMOKE_PUBLISH_NPM) {
return {
command: ['npm'],
NPM: await which('npm').then(p => fs.realpath(p).replace(sep + cliBin)),
NPM: cleanNpmPaths,
}
}

return {
command: [process.execPath, join(CLI_ROOT, cliBin)],
command: [process.execPath, join(CLI_ROOT, cliJsBin)],
NODE: process.execPath,
NPM: join(CLI_ROOT, cliBin),
NPM: cleanNpmPaths,
}
}

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

const { command, ...spawnPaths } = await getSpawnArgs()
const cleanPaths = Object.entries({ ...spawnPaths, CWD: CLI_ROOT })
const debugLog = debug || CI ? (...a) => console.error(...a) : () => {}
const { command, ...spawnPaths } = await getSpawnArgs({ log: debugLog })
const cleanPaths = Object.entries(spawnPaths)

const cleanOutput = s => {
// sometimes we print normalized paths in snapshots regardless of
// platform so replace those first then replace platform style paths
for (const [key, value] of cleanPaths) {
s = s.split(normalizePath(value)).join(`{${key}}`)
const values = [].concat(value)
for (const v of values) {
s = s.split(normalizePath(v)).join(`{${key}}`)
}
}
for (const [key, value] of cleanPaths) {
s = s.split(value).join(`{${key}}`)
const values = [].concat(value)
for (const v of values) {
s = s.split(v).join(`{${key}}`)
}
}
return s
.split(relative(CLI_ROOT, t.testdirName)).join('{TESTDIR}')
Expand All @@ -110,7 +130,7 @@ module.exports = async (t, { testdir = {}, debug } = {}) => {
.replace(/^.*debug-[0-9]+.log$/gm, '')
.replace(/in \d+ms$/gm, 'in {TIME}')
}
const log = debug || CI ? (...a) => console.error(cleanOutput(a.join(' '))) : () => {}
const log = (...a) => debugLog(cleanOutput(a.join(' ')))
t.cleanSnapshot = cleanOutput

const npm = async (...args) => {
Expand Down