Skip to content

Commit 1d24db0

Browse files
committed
tarball times
1 parent 0b1ae12 commit 1d24db0

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

smoke-tests/test/npm-replace-global.js

+27-36
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ t.test('pack and replace global self', async t => {
9494
})
9595

9696
t.test('publish and replace global self', async t => {
97-
const pkg = require('../../package.json')
98-
const { name, version } = pkg
99-
10097
const {
10198
npm,
10299
npmPath,
@@ -113,42 +110,42 @@ t.test('publish and replace global self', async t => {
113110
},
114111
})
115112

116-
const mockNpmPackage = async ({ manifest, ...opts } = {}) => {
113+
let publishedPackument = null
114+
const { name, version } = require('../../package.json')
115+
116+
const npmPackage = async ({ manifest, ...opts } = {}) => {
117117
await registry.package({
118118
manifest: registry.manifest({ name, ...manifest }),
119119
...opts,
120120
})
121-
await fs.rm(cache, { recursive: true, force: true })
122121
}
123122

124-
const mockPublish = (() => {
125-
let publishedPackument = null
126-
registry.nock.put('/npm', body => {
127-
if (body._id === 'npm' && body.versions[version]) {
128-
publishedPackument = body.versions[version]
129-
return true
130-
}
131-
return false
132-
}).reply(201, {})
133-
return {
134-
get packument () {
135-
return publishedPackument
136-
},
137-
}
138-
})()
139-
await mockNpmPackage()
140-
await npmLocal('publish', { proxy: true, force: true })
123+
const npmInstall = async (useNpm) => {
124+
await npmPackage({
125+
manifest: { packuments: [publishedPackument] },
126+
tarballs: { [version]: tarball },
127+
times: 3,
128+
})
129+
await fs.rm(cache, { recursive: true, force: true })
130+
await useNpm('install', 'npm@latest', '--global')
131+
return getPaths()
132+
}
141133

142134
const tarball = await npmLocalTarball()
143135

144-
await mockNpmPackage({
145-
manifest: { packuments: [mockPublish.packument] },
146-
tarballs: { [version]: tarball },
147-
times: 3,
148-
})
149-
await npm('install', 'npm@latest', '--global')
150-
const paths = await getPaths()
136+
if (setup.SMOKE_PUBLISH) {
137+
await npmPackage()
138+
}
139+
registry.nock.put('/npm', body => {
140+
if (body._id === 'npm' && body.versions[version]) {
141+
publishedPackument = body.versions[version]
142+
return true
143+
}
144+
return false
145+
}).reply(201, {})
146+
await npmLocal('publish', { proxy: true, force: true })
151147

148+
const paths = await npmInstall(npm)
152149
t.equal(paths.npmRoot, join(globalNodeModules, 'npm'), 'npm root is in the testdir')
153150
t.equal(paths.pathNpm, join(globalBin, 'npm'), 'npm bin is in the testdir')
154151
t.equal(paths.pathNpx, join(globalBin, 'npx'), 'npx bin is in the testdir')
@@ -161,13 +158,7 @@ t.test('publish and replace global self', async t => {
161158
'bin has npm and npx'
162159
)
163160

164-
await mockNpmPackage({
165-
manifest: { packuments: [mockPublish.packument] },
166-
tarballs: { [version]: tarball },
167-
times: 3,
168-
})
169-
await npmPath('install', 'npm@latest', '--global')
170-
t.strictSame(await getPaths(), paths)
161+
t.strictSame(await npmInstall(npmPath), paths)
171162
})
172163

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

0 commit comments

Comments
 (0)