From f7762e52883b2034b006643e6e3dc2b99966fc56 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 19 Apr 2023 11:44:13 -0700 Subject: [PATCH] chore: smoke test for npx caching issue --- smoke-tests/test/index.js | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/smoke-tests/test/index.js b/smoke-tests/test/index.js index 98f276be841b7..152bab15666f2 100644 --- a/smoke-tests/test/index.js +++ b/smoke-tests/test/index.js @@ -18,6 +18,16 @@ t.test('basic', async t => { 'package.json': { name: 'promise-all-reject-late', version: '5.0.0' }, 'index.js': 'module.exports = null', }, + 'exec-test-1.0.0': { + 'package.json': { name: 'exec-test', version: '1.0.0', bin: { 'exec-test': 'run.sh' } }, + 'index.js': 'module.exports = "1.0.0"', + 'run.sh': 'echo 1.0.0', + }, + 'exec-test-1.0.1': { + 'package.json': { name: 'exec-test', version: '1.0.1', bin: { 'exec-test': 'run.sh' } }, + 'index.js': 'module.exports = "1.0.1"', + 'run.sh': 'echo 1.0.1', + }, }, }, }) @@ -332,4 +342,44 @@ t.test('basic', async t => { t.equal(err.code, 1) t.matchSnapshot(err.stderr, 'should throw mismatch deps in lock file error') }) + + await t.test('npm exec', async t => { + if (process.platform === 'win32') { + t.skip() + return + } + // First run finds package + { + const packument = registry.packument({ + name: 'exec-test', version: '1.0.0', bin: { 'exec-test': 'run.sh' }, + }) + const manifest = registry.manifest({ name: 'exec-test', packuments: [packument] }) + await registry.package({ + times: 2, + manifest, + tarballs: { + '1.0.0': join(paths.root, 'packages', 'exec-test-1.0.0'), + }, + }) + + const o = await npm('exec', 'exec-test') + t.match(o.trim(), '1.0.0') + } + // Second run finds newer version + { + const packument = registry.packument({ + name: 'exec-test', version: '1.0.1', bin: { 'exec-test': 'run.sh' }, + }) + const manifest = registry.manifest({ name: 'exec-test', packuments: [packument] }) + await registry.package({ + times: 2, + manifest, + tarballs: { + '1.0.1': join(paths.root, 'packages', 'exec-test-1.0.1'), + }, + }) + const o = await npm('exec', 'exec-test') + t.match(o.trim(), '1.0.1') + } + }) })