Skip to content

Commit

Permalink
tarball times
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed May 8, 2024
1 parent 0b1ae12 commit 1d24db0
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions smoke-tests/test/npm-replace-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ t.test('pack and replace global self', async t => {
})

t.test('publish and replace global self', async t => {
const pkg = require('../../package.json')
const { name, version } = pkg

const {
npm,
npmPath,
Expand All @@ -113,42 +110,42 @@ t.test('publish and replace global self', async t => {
},
})

const mockNpmPackage = async ({ manifest, ...opts } = {}) => {
let publishedPackument = null
const { name, version } = require('../../package.json')

const npmPackage = async ({ manifest, ...opts } = {}) => {
await registry.package({
manifest: registry.manifest({ name, ...manifest }),
...opts,
})
await fs.rm(cache, { recursive: true, force: true })
}

const mockPublish = (() => {
let publishedPackument = null
registry.nock.put('/npm', body => {
if (body._id === 'npm' && body.versions[version]) {
publishedPackument = body.versions[version]
return true
}
return false
}).reply(201, {})
return {
get packument () {
return publishedPackument
},
}
})()
await mockNpmPackage()
await npmLocal('publish', { proxy: true, force: true })
const npmInstall = async (useNpm) => {
await npmPackage({
manifest: { packuments: [publishedPackument] },
tarballs: { [version]: tarball },
times: 3,
})
await fs.rm(cache, { recursive: true, force: true })
await useNpm('install', 'npm@latest', '--global')
return getPaths()
}

const tarball = await npmLocalTarball()

await mockNpmPackage({
manifest: { packuments: [mockPublish.packument] },
tarballs: { [version]: tarball },
times: 3,
})
await npm('install', 'npm@latest', '--global')
const paths = await getPaths()
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')
Expand All @@ -161,13 +158,7 @@ t.test('publish and replace global self', async t => {
'bin has npm and npx'
)

await mockNpmPackage({
manifest: { packuments: [mockPublish.packument] },
tarballs: { [version]: tarball },
times: 3,
})
await npmPath('install', 'npm@latest', '--global')
t.strictSame(await getPaths(), paths)
t.strictSame(await npmInstall(npmPath), paths)
})

t.test('fail when updating with lazy require', async t => {
Expand Down

0 comments on commit 1d24db0

Please sign in to comment.