From eb33f8f8777d70d400eb85d69efa232198bf10b9 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 9 Apr 2024 16:03:07 -0700 Subject: [PATCH 01/16] chore(smoke-tests): add expected lazy require failure --- smoke-tests/test/npm-replace-global.js | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index 432935d49fd38..aaad992b00eca 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -162,3 +162,46 @@ t.test('publish and replace global self', async t => { t.strictSame(await npmInstall(npmPath), paths) }) + +t.test('fail when updating with lazy require', async t => { + const { + npm, + npmLocalTarball, + npmPath, + paths, + } = await setupNpmGlobal(t, { + testdir: { + project: { + 'package.json': { + name: 'npm', + version: '999.999.999', + bin: { + npm: './npm.js', + }, + }, + 'npm.js': `#!/usr/bin/env node\nconsole.log('This worked!')`, + }, + }, + }) + + await npm('install', await npmLocalTarball(), '--global') + await npmPath('pack') + + // exit-handler is the last thing called in the code + // so an uncached lazy require within the exit handler will always throw + await fs.writeFile( + join(paths.globalNodeModules, 'npm/lib/utils/exit-handler.js'), + `module.exports = () => require('./LAZY_REQUIRE_CANARY') + module.exports.setNpm = () => {} + `, + 'utf-8' + ) + + await t.rejects(npmPath('install', 'npm-999.999.999.tgz', '--global'), { + stderr: `Error: Cannot find module './LAZY_REQUIRE_CANARY'`, + }, 'command fails with lazy require') + + await t.resolveMatch(npmPath(), { + stdout: 'This worked!', + }, 'bin placement still works') +}) From b008bbb3b271e0790be6ad4378606b95d8bcde04 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 9 Apr 2024 16:30:19 -0700 Subject: [PATCH 02/16] wip: investigate windows failing tests --- smoke-tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index 85b33edeb8b94..927d26eef30c6 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -9,7 +9,7 @@ "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", "snap": "tap", - "test": "tap", + "test": "tap test/npm-replace-global.js -g \"fail when updating with lazy require\"", "posttest": "npm run lint" }, "repository": { From 6180cafb335dce5eb3e2dee232a0375628ff84b0 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 10:06:11 -0700 Subject: [PATCH 03/16] wip: increase smoke test timeout --- smoke-tests/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index 927d26eef30c6..18de977567d2f 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -9,7 +9,7 @@ "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", "snap": "tap", - "test": "tap test/npm-replace-global.js -g \"fail when updating with lazy require\"", + "test": "tap", "posttest": "npm run lint" }, "repository": { @@ -36,7 +36,7 @@ }, "tap": { "no-coverage": true, - "timeout": 600, + "timeout": 1800, "jobs": 1, "test-ignore": "fixtures/*", "nyc-arg": [ From e3dd30609279f58f472c733bc721634b42e39b70 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 13:30:56 -0700 Subject: [PATCH 04/16] wip: windows --- smoke-tests/package.json | 2 +- smoke-tests/test/npm-replace-global.js | 29 ++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index 18de977567d2f..b799c7f43df9d 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -9,7 +9,7 @@ "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", "snap": "tap", - "test": "tap", + "test": "tap test/npm-replace-global.js --grep \"fail when updating with lazy require\"", "posttest": "npm run lint" }, "repository": { diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index aaad992b00eca..d536d3e756cc9 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -25,10 +25,10 @@ const setupNpmGlobal = async (t, opts) => { return { npmRoot: await mock.npmPath('help').then(setup.getNpmRoot), - pathNpm: await which('npm', { path: mock.getPath(), nothrow: true }), - globalNpm: await which('npm', { nothrow: true }), - pathNpx: await which('npx', { path: mock.getPath(), nothrow: true }), - globalNpx: await which('npx', { nothrow: true }), + pathNpm: await which('npm', { path: mock.getPath() }), + globalNpm: await which('npm'), + pathNpx: await which('npx', { path: mock.getPath() }), + globalNpx: await which('npx'), binContents, nodeModulesContents, } @@ -191,17 +191,20 @@ t.test('fail when updating with lazy require', async t => { // so an uncached lazy require within the exit handler will always throw await fs.writeFile( join(paths.globalNodeModules, 'npm/lib/utils/exit-handler.js'), - `module.exports = () => require('./LAZY_REQUIRE_CANARY') - module.exports.setNpm = () => {} - `, + `module.exports = () => require('./LAZY_REQUIRE_CANARY');module.exports.setNpm = () => {}`, 'utf-8' ) - await t.rejects(npmPath('install', 'npm-999.999.999.tgz', '--global'), { - stderr: `Error: Cannot find module './LAZY_REQUIRE_CANARY'`, - }, 'command fails with lazy require') + let installErr + try { + await npmPath('install', 'npm-999.999.999.tgz', '--global') + } catch (err) { + installErr = err + } + + console.error(installErr.stderr) + + t.match(installErr.stderr, `Error: Cannot find module './LAZY_REQUIRE_CANARY'`) - await t.resolveMatch(npmPath(), { - stdout: 'This worked!', - }, 'bin placement still works') + await t.resolveMatch(npmPath(), { stdout: 'This worked!' }, 'bin placement still works') }) From bcab34a1c50d98f8ec185c616b85cd61e13d7d69 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 13:59:11 -0700 Subject: [PATCH 05/16] wip: log on events --- smoke-tests/test/fixtures/setup.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/smoke-tests/test/fixtures/setup.js b/smoke-tests/test/fixtures/setup.js index d2500507119a8..c056619400739 100644 --- a/smoke-tests/test/fixtures/setup.js +++ b/smoke-tests/test/fixtures/setup.js @@ -158,7 +158,7 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy log(`${spawnCmd} ${spawnArgs.join(' ')}`) log('-'.repeat(40)) - const { stderr, stdout } = await spawn(spawnCmd, spawnArgs, { + const spawnPromise = spawn(spawnCmd, spawnArgs, { cwd, env: { ...getEnvPath(), @@ -169,10 +169,22 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy ...opts, }) - log(stderr) - log('-'.repeat(40)) - log(stdout) - log('='.repeat(40)) + const proc = spawnPromise.process + + if (proc.stdout) { + proc.stdout.on('data', c => log(c)) + } + + if (proc.stderr) { + proc.stderr.on('data', c => log(c)) + } + + const { stderr, stdout } = await spawnPromise + + // log(stderr) + // log('-'.repeat(40)) + // log(stdout) + // log('='.repeat(40)) return { stderr, stdout } } From f612ffc9a42102f9ae7a9f44975e1253e6d2a2e9 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:03:49 -0700 Subject: [PATCH 06/16] wip --- smoke-tests/package.json | 2 +- smoke-tests/test/npm-replace-global.js | 136 ++++++++++++------------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index b799c7f43df9d..fc0e515ced261 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -9,7 +9,7 @@ "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", "snap": "tap", - "test": "tap test/npm-replace-global.js --grep \"fail when updating with lazy require\"", + "test": "tap test/npm-replace-global.js", "posttest": "npm run lint" }, "repository": { diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index d536d3e756cc9..a209a35835190 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -94,74 +94,74 @@ t.test('pack and replace global self', async t => { t.strictSame(postPaths.nodeModulesContents, ['package.json'], 'contents is only package.json') }) -t.test('publish and replace global self', async t => { - let publishedPackument = null - const pkg = require('../../package.json') - const { name, version } = pkg - - const { - npm, - npmPath, - registry, - npmLocal, - npmLocalTarball, - getPaths, - paths: { globalBin, globalNodeModules, cache }, - } = await setupNpmGlobal(t, { - testdir: { - home: { - '.npmrc': `//${setup.MOCK_REGISTRY.host}/:_authToken = test-token`, - }, - }, - }) - - const npmPackage = async ({ manifest, ...opts } = {}) => { - await registry.package({ - manifest: registry.manifest({ name, ...manifest }), - ...opts, - }) - } - - const npmInstall = async (useNpm) => { - await npmPackage({ - manifest: { packuments: [publishedPackument] }, - tarballs: { [version]: tarball }, - times: 2, - }) - await fs.rm(cache, { recursive: true, force: true }) - await useNpm('install', 'npm@latest', '--global') - return getPaths() - } - - const tarball = await npmLocalTarball() - - if (setup.SMOKE_PUBLISH) { - await npmPackage() - } - registry.nock.put('/npm', body => { - if (body._id === 'npm' && body.versions[version]) { - publishedPackument = body.versions[version] - return true - } - return false - }).reply(201, {}) - await npmLocal('publish', { proxy: true, force: true }) - - const paths = await npmInstall(npm) - t.equal(paths.npmRoot, join(globalNodeModules, 'npm'), 'npm root is in the testdir') - t.equal(paths.pathNpm, join(globalBin, 'npm'), 'npm bin is in the testdir') - t.equal(paths.pathNpx, join(globalBin, 'npx'), 'npx bin is in the testdir') - t.ok(paths.nodeModulesContents.length > 1, 'node modules has npm contents') - t.ok(paths.nodeModulesContents.includes('node_modules'), 'npm has its node_modules') - - t.strictSame( - paths.binContents, - ['npm', 'npx'].flatMap(p => setup.WINDOWS ? [p, `${p}.cmd`, `${p}.ps1`] : p), - 'bin has npm and npx' - ) - - t.strictSame(await npmInstall(npmPath), paths) -}) +// t.test('publish and replace global self', async t => { +// let publishedPackument = null +// const pkg = require('../../package.json') +// const { name, version } = pkg + +// const { +// npm, +// npmPath, +// registry, +// npmLocal, +// npmLocalTarball, +// getPaths, +// paths: { globalBin, globalNodeModules, cache }, +// } = await setupNpmGlobal(t, { +// testdir: { +// home: { +// '.npmrc': `//${setup.MOCK_REGISTRY.host}/:_authToken = test-token`, +// }, +// }, +// }) + +// const npmPackage = async ({ manifest, ...opts } = {}) => { +// await registry.package({ +// manifest: registry.manifest({ name, ...manifest }), +// ...opts, +// }) +// } + +// const npmInstall = async (useNpm) => { +// await npmPackage({ +// manifest: { packuments: [publishedPackument] }, +// tarballs: { [version]: tarball }, +// times: 2, +// }) +// await fs.rm(cache, { recursive: true, force: true }) +// await useNpm('install', 'npm@latest', '--global') +// return getPaths() +// } + +// const tarball = await npmLocalTarball() + +// if (setup.SMOKE_PUBLISH) { +// await npmPackage() +// } +// registry.nock.put('/npm', body => { +// if (body._id === 'npm' && body.versions[version]) { +// publishedPackument = body.versions[version] +// return true +// } +// return false +// }).reply(201, {}) +// await npmLocal('publish', { proxy: true, force: true }) + +// const paths = await npmInstall(npm) +// t.equal(paths.npmRoot, join(globalNodeModules, 'npm'), 'npm root is in the testdir') +// t.equal(paths.pathNpm, join(globalBin, 'npm'), 'npm bin is in the testdir') +// t.equal(paths.pathNpx, join(globalBin, 'npx'), 'npx bin is in the testdir') +// t.ok(paths.nodeModulesContents.length > 1, 'node modules has npm contents') +// t.ok(paths.nodeModulesContents.includes('node_modules'), 'npm has its node_modules') + +// t.strictSame( +// paths.binContents, +// ['npm', 'npx'].flatMap(p => setup.WINDOWS ? [p, `${p}.cmd`, `${p}.ps1`] : p), +// 'bin has npm and npx' +// ) + +// t.strictSame(await npmInstall(npmPath), paths) +// }) t.test('fail when updating with lazy require', async t => { const { From cfd9aa1469e3377ffd8533652fd1dedbda72694d Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:04:14 -0700 Subject: [PATCH 07/16] wip: revert test timeout --- smoke-tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index fc0e515ced261..6d4fb3a55541c 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -36,7 +36,7 @@ }, "tap": { "no-coverage": true, - "timeout": 1800, + "timeout": 600, "jobs": 1, "test-ignore": "fixtures/*", "nyc-arg": [ From 416b4cbe3facf51aa7a65e95953de56973be5e4b Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:09:58 -0700 Subject: [PATCH 08/16] wip --- smoke-tests/test/npm-replace-global.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index a209a35835190..2871e41226207 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -185,6 +185,8 @@ t.test('fail when updating with lazy require', async t => { }) await npm('install', await npmLocalTarball(), '--global') + console.error(npmPath()) + console.error(npmPath('help')) await npmPath('pack') // exit-handler is the last thing called in the code From 5bc4c3c307604ea19d1244cad8070eafeb3e1757 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:10:54 -0700 Subject: [PATCH 09/16] wip --- smoke-tests/test/npm-replace-global.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index 2871e41226207..c2a9ed235f067 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -185,8 +185,8 @@ t.test('fail when updating with lazy require', async t => { }) await npm('install', await npmLocalTarball(), '--global') - console.error(npmPath()) - console.error(npmPath('help')) + console.error(await npmPath()) + console.error(await npmPath('help')) await npmPath('pack') // exit-handler is the last thing called in the code From bea75810e2515128bca9b142496f5249567ff0c7 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:12:24 -0700 Subject: [PATCH 10/16] wip --- smoke-tests/test/npm-replace-global.js | 1 - 1 file changed, 1 deletion(-) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index c2a9ed235f067..da417dadc6a19 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -185,7 +185,6 @@ t.test('fail when updating with lazy require', async t => { }) await npm('install', await npmLocalTarball(), '--global') - console.error(await npmPath()) console.error(await npmPath('help')) await npmPath('pack') From 012593fc506bf60608dd2647a442cf460a92d11e Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:18:35 -0700 Subject: [PATCH 11/16] wip: does the bin break it on windows? --- smoke-tests/test/npm-replace-global.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index da417dadc6a19..9897d5a808795 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -51,9 +51,7 @@ t.test('pack and replace global self', async t => { }, }) - const tarball = await npmLocalTarball() - - await npm('install', tarball, '--global') + await npm('install', await npmLocalTarball(), '--global') t.equal( await fs.realpath(join(globalBin, 'npm')), @@ -175,11 +173,11 @@ t.test('fail when updating with lazy require', async t => { 'package.json': { name: 'npm', version: '999.999.999', - bin: { - npm: './npm.js', - }, + // bin: { + // npm: './npm.js', + // }, }, - 'npm.js': `#!/usr/bin/env node\nconsole.log('This worked!')`, + // 'npm.js': `#!/usr/bin/env node\nconsole.log('This worked!')`, }, }, }) From 8b11c23593a037f0b84d6501a25c7c982e20b93c Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:23:01 -0700 Subject: [PATCH 12/16] wip: rename bin --- smoke-tests/test/npm-replace-global.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index 9897d5a808795..2fccd8aa7b221 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -173,17 +173,16 @@ t.test('fail when updating with lazy require', async t => { 'package.json': { name: 'npm', version: '999.999.999', - // bin: { - // npm: './npm.js', - // }, + bin: { + npm: './my-new-npm-bin.js', + }, }, - // 'npm.js': `#!/usr/bin/env node\nconsole.log('This worked!')`, + 'my-new-npm-bin.js': `#!/usr/bin/env node\nconsole.log('This worked!')`, }, }, }) await npm('install', await npmLocalTarball(), '--global') - console.error(await npmPath('help')) await npmPath('pack') // exit-handler is the last thing called in the code From bd4efa447a2d9bc20931c8dc891e229aad3e2472 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:27:20 -0700 Subject: [PATCH 13/16] wip: revert everything back to how it was --- smoke-tests/package.json | 2 +- smoke-tests/test/npm-replace-global.js | 149 ++++++++++++------------- 2 files changed, 72 insertions(+), 79 deletions(-) diff --git a/smoke-tests/package.json b/smoke-tests/package.json index 6d4fb3a55541c..85b33edeb8b94 100644 --- a/smoke-tests/package.json +++ b/smoke-tests/package.json @@ -9,7 +9,7 @@ "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", "snap": "tap", - "test": "tap test/npm-replace-global.js", + "test": "tap", "posttest": "npm run lint" }, "repository": { diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index 2fccd8aa7b221..7f788af281fd4 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -92,74 +92,74 @@ t.test('pack and replace global self', async t => { t.strictSame(postPaths.nodeModulesContents, ['package.json'], 'contents is only package.json') }) -// t.test('publish and replace global self', async t => { -// let publishedPackument = null -// const pkg = require('../../package.json') -// const { name, version } = pkg - -// const { -// npm, -// npmPath, -// registry, -// npmLocal, -// npmLocalTarball, -// getPaths, -// paths: { globalBin, globalNodeModules, cache }, -// } = await setupNpmGlobal(t, { -// testdir: { -// home: { -// '.npmrc': `//${setup.MOCK_REGISTRY.host}/:_authToken = test-token`, -// }, -// }, -// }) - -// const npmPackage = async ({ manifest, ...opts } = {}) => { -// await registry.package({ -// manifest: registry.manifest({ name, ...manifest }), -// ...opts, -// }) -// } - -// const npmInstall = async (useNpm) => { -// await npmPackage({ -// manifest: { packuments: [publishedPackument] }, -// tarballs: { [version]: tarball }, -// times: 2, -// }) -// await fs.rm(cache, { recursive: true, force: true }) -// await useNpm('install', 'npm@latest', '--global') -// return getPaths() -// } - -// const tarball = await npmLocalTarball() - -// if (setup.SMOKE_PUBLISH) { -// await npmPackage() -// } -// registry.nock.put('/npm', body => { -// if (body._id === 'npm' && body.versions[version]) { -// publishedPackument = body.versions[version] -// return true -// } -// return false -// }).reply(201, {}) -// await npmLocal('publish', { proxy: true, force: true }) - -// const paths = await npmInstall(npm) -// t.equal(paths.npmRoot, join(globalNodeModules, 'npm'), 'npm root is in the testdir') -// t.equal(paths.pathNpm, join(globalBin, 'npm'), 'npm bin is in the testdir') -// t.equal(paths.pathNpx, join(globalBin, 'npx'), 'npx bin is in the testdir') -// t.ok(paths.nodeModulesContents.length > 1, 'node modules has npm contents') -// t.ok(paths.nodeModulesContents.includes('node_modules'), 'npm has its node_modules') - -// t.strictSame( -// paths.binContents, -// ['npm', 'npx'].flatMap(p => setup.WINDOWS ? [p, `${p}.cmd`, `${p}.ps1`] : p), -// 'bin has npm and npx' -// ) - -// t.strictSame(await npmInstall(npmPath), paths) -// }) +t.test('publish and replace global self', async t => { + let publishedPackument = null + const pkg = require('../../package.json') + const { name, version } = pkg + + const { + npm, + npmPath, + registry, + npmLocal, + npmLocalTarball, + getPaths, + paths: { globalBin, globalNodeModules, cache }, + } = await setupNpmGlobal(t, { + testdir: { + home: { + '.npmrc': `//${setup.MOCK_REGISTRY.host}/:_authToken = test-token`, + }, + }, + }) + + const npmPackage = async ({ manifest, ...opts } = {}) => { + await registry.package({ + manifest: registry.manifest({ name, ...manifest }), + ...opts, + }) + } + + const npmInstall = async (useNpm) => { + await npmPackage({ + manifest: { packuments: [publishedPackument] }, + tarballs: { [version]: tarball }, + times: 2, + }) + await fs.rm(cache, { recursive: true, force: true }) + await useNpm('install', 'npm@latest', '--global') + return getPaths() + } + + const tarball = await npmLocalTarball() + + if (setup.SMOKE_PUBLISH) { + await npmPackage() + } + registry.nock.put('/npm', body => { + if (body._id === 'npm' && body.versions[version]) { + publishedPackument = body.versions[version] + return true + } + return false + }).reply(201, {}) + await npmLocal('publish', { proxy: true, force: true }) + + const paths = await npmInstall(npm) + t.equal(paths.npmRoot, join(globalNodeModules, 'npm'), 'npm root is in the testdir') + t.equal(paths.pathNpm, join(globalBin, 'npm'), 'npm bin is in the testdir') + t.equal(paths.pathNpx, join(globalBin, 'npx'), 'npx bin is in the testdir') + t.ok(paths.nodeModulesContents.length > 1, 'node modules has npm contents') + t.ok(paths.nodeModulesContents.includes('node_modules'), 'npm has its node_modules') + + t.strictSame( + paths.binContents, + ['npm', 'npx'].flatMap(p => setup.WINDOWS ? [p, `${p}.cmd`, `${p}.ps1`] : p), + 'bin has npm and npx' + ) + + t.strictSame(await npmInstall(npmPath), paths) +}) t.test('fail when updating with lazy require', async t => { const { @@ -193,16 +193,9 @@ t.test('fail when updating with lazy require', async t => { 'utf-8' ) - let installErr - try { - await npmPath('install', 'npm-999.999.999.tgz', '--global') - } catch (err) { - installErr = err - } - - console.error(installErr.stderr) - - t.match(installErr.stderr, `Error: Cannot find module './LAZY_REQUIRE_CANARY'`) + await t.rejects(npmPath('install', 'npm-999.999.999.tgz', '--global'), { + stderr: `Error: Cannot find module './LAZY_REQUIRE_CANARY'`, + }, 'install command fails with lazy require error') await t.resolveMatch(npmPath(), { stdout: 'This worked!' }, 'bin placement still works') }) From 7f42bad061a5bf7acd3db908239cc3053ee08e35 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:29:30 -0700 Subject: [PATCH 14/16] wip: revert setup: --- smoke-tests/test/fixtures/setup.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/smoke-tests/test/fixtures/setup.js b/smoke-tests/test/fixtures/setup.js index c056619400739..fb01ed7924a0f 100644 --- a/smoke-tests/test/fixtures/setup.js +++ b/smoke-tests/test/fixtures/setup.js @@ -158,7 +158,7 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy log(`${spawnCmd} ${spawnArgs.join(' ')}`) log('-'.repeat(40)) - const spawnPromise = spawn(spawnCmd, spawnArgs, { + const { stderr, stdout } = await spawn(spawnCmd, spawnArgs, { cwd, env: { ...getEnvPath(), @@ -169,24 +169,12 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy ...opts, }) - const proc = spawnPromise.process - - if (proc.stdout) { - proc.stdout.on('data', c => log(c)) - } - - if (proc.stderr) { - proc.stderr.on('data', c => log(c)) - } - - const { stderr, stdout } = await spawnPromise - - // log(stderr) - // log('-'.repeat(40)) - // log(stdout) - // log('='.repeat(40)) + log(stderr) + log('-'.repeat(40)) + log(stdout) + log('='.repeat(40)) - return { stderr, stdout } + return { stdout, stderr } } const baseNpm = async (...a) => { From d0a6cec75c3bf92ab9c15581c04f0768cb03b3d6 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:29:53 -0700 Subject: [PATCH 15/16] wip: revert setup --- smoke-tests/test/fixtures/setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/test/fixtures/setup.js b/smoke-tests/test/fixtures/setup.js index fb01ed7924a0f..d2500507119a8 100644 --- a/smoke-tests/test/fixtures/setup.js +++ b/smoke-tests/test/fixtures/setup.js @@ -174,7 +174,7 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy log(stdout) log('='.repeat(40)) - return { stdout, stderr } + return { stderr, stdout } } const baseNpm = async (...a) => { From f1244648b63642220eb0b4b6ef1d5d0fb592e4e6 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 10 Apr 2024 14:31:48 -0700 Subject: [PATCH 16/16] wip: separate commands for tarball --- smoke-tests/test/npm-replace-global.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smoke-tests/test/npm-replace-global.js b/smoke-tests/test/npm-replace-global.js index 7f788af281fd4..5b84daf356ce2 100644 --- a/smoke-tests/test/npm-replace-global.js +++ b/smoke-tests/test/npm-replace-global.js @@ -51,7 +51,8 @@ t.test('pack and replace global self', async t => { }, }) - await npm('install', await npmLocalTarball(), '--global') + const tarball = await npmLocalTarball() + await npm('install', tarball, '--global') t.equal( await fs.realpath(join(globalBin, 'npm')), @@ -182,7 +183,8 @@ t.test('fail when updating with lazy require', async t => { }, }) - await npm('install', await npmLocalTarball(), '--global') + const tarball = await npmLocalTarball() + await npm('install', tarball, '--global') await npmPath('pack') // exit-handler is the last thing called in the code