Skip to content

Commit

Permalink
chore: add smoke-test to proxy live registry
Browse files Browse the repository at this point in the history
Ref: #6760
  • Loading branch information
lukekarrys committed Sep 7, 2023
1 parent 09d8e0a commit 139cb41
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ graph LR;
npmcli-smoke-tests-->npmcli-mock-registry["@npmcli/mock-registry"];
npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-smoke-tests-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-smoke-tests-->proxy;
npmcli-smoke-tests-->tap;
npmcli-smoke-tests-->which;
npmlog-->are-we-there-yet;
Expand Down
134 changes: 134 additions & 0 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,110 @@
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
"dev": true
},
"node_modules/args": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/args/-/args-5.0.3.tgz",
"integrity": "sha512-h6k/zfFgusnv3i5TU08KQkVKuCPBtL/PWQbWkHUxvJrZ2nAyeaUupneemcrgn1xmqxPQsPIzwkUhOpoqPDRZuA==",
"dev": true,
"dependencies": {
"camelcase": "5.0.0",
"chalk": "2.4.2",
"leven": "2.1.0",
"mri": "1.1.4"
},
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/args/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/args/node_modules/camelcase": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.0.0.tgz",
"integrity": "sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/args/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/args/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/args/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"node_modules/args/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/args/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/args/node_modules/mri": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz",
"integrity": "sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/args/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/array-buffer-byte-length": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.0.tgz",
Expand Down Expand Up @@ -4416,6 +4520,12 @@
],
"inBundle": true
},
"node_modules/basic-auth-parser": {
"version": "0.0.2-1",
"resolved": "https://registry.npmjs.org/basic-auth-parser/-/basic-auth-parser-0.0.2-1.tgz",
"integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==",
"dev": true
},
"node_modules/before-after-hook": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz",
Expand Down Expand Up @@ -8633,6 +8743,15 @@
"node": ">=6"
}
},
"node_modules/leven": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz",
"integrity": "sha512-nvVPLpIHUxCUoRLrFqTgSxXJ614d8AgQoWl7zPe/2VadE8+1dpU3LBhowRuBAcuwruWtOdD8oYC9jDNJjXDPyA==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/levn": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
Expand Down Expand Up @@ -12192,6 +12311,20 @@
"url": "https://github.com/sponsors/wooorm"
}
},
"node_modules/proxy": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/proxy/-/proxy-2.1.1.tgz",
"integrity": "sha512-nLgd7zdUAOpB3ZO/xCkU8gy74UER7P0aihU8DkUsDS5ZoFwVCX7u8dy+cv5tVK8UaB/yminU1GiLWE26TKPYpg==",
"dev": true,
"dependencies": {
"args": "^5.0.3",
"basic-auth-parser": "0.0.2-1",
"debug": "^4.3.4"
},
"engines": {
"node": ">= 14"
}
},
"node_modules/psl": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
Expand Down Expand Up @@ -17243,6 +17376,7 @@
"@npmcli/promise-spawn": "^7.0.0",
"@npmcli/template-oss": "4.18.0",
"http-proxy": "^1.18.1",
"proxy": "^2.1.1",
"tap": "^16.3.8",
"which": "^4.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions smoke-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@npmcli/promise-spawn": "^7.0.0",
"@npmcli/template-oss": "4.18.0",
"http-proxy": "^1.18.1",
"proxy": "^2.1.1",
"tap": "^16.3.8",
"which": "^4.0.0"
},
Expand Down
10 changes: 8 additions & 2 deletions smoke-tests/test/fixtures/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const httpProxy = require('http-proxy')
const { SMOKE_PUBLISH_NPM, SMOKE_PUBLISH_TARBALL, CI, PATH, Path, TAP_CHILD_ID = '0' } = process.env
const PROXY_PORT = 12345 + (+TAP_CHILD_ID)
const HTTP_PROXY = `http://localhost:${PROXY_PORT}/`
const DEFAULT_REGISTRY = new URL('https://registry.npmjs.org/')

const NODE_PATH = process.execPath
const CLI_ROOT = resolve(process.cwd(), '..')
Expand Down Expand Up @@ -114,7 +115,11 @@ module.exports = async (t, { testdir = {}, debug, registry: _registry = {} } = {
globalNodeModules: join(root, 'global', GLOBAL_NODE_MODULES),
}

const registry = await createRegistry(t, { ..._registry, debug })
const liveRegistry = _registry === false
const USE_PROXY = !liveRegistry
const registry = liveRegistry
? DEFAULT_REGISTRY
: await createRegistry(t, { ..._registry, debug })

// update notifier should never be written
t.afterEach((t) => {
Expand Down Expand Up @@ -178,7 +183,7 @@ module.exports = async (t, { testdir = {}, debug, registry: _registry = {} } = {
}

const baseNpm = async (...a) => {
const [{ cwd, cmd, argv = [], proxy = true, ...opts }, args] = getOpts(...a)
const [{ cwd, cmd, argv = [], proxy = USE_PROXY, ...opts }, args] = getOpts(...a)

const isGlobal = args.some(arg => ['-g', '--global', '--global=true'].includes(arg))

Expand Down Expand Up @@ -262,3 +267,4 @@ module.exports.WINDOWS = WINDOWS
module.exports.SMOKE_PUBLISH = !!SMOKE_PUBLISH_NPM
module.exports.SMOKE_PUBLISH_TARBALL = SMOKE_PUBLISH_TARBALL
module.exports.HTTP_PROXY = HTTP_PROXY
module.exports.PROXY_PORT = PROXY_PORT
29 changes: 29 additions & 0 deletions smoke-tests/test/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const t = require('tap')
const setup = require('./fixtures/setup.js')
const { createProxy } = require('proxy')
const http = require('http')

t.test('basic', async t => {
const PORT = setup.PROXY_PORT
const { npm, readFile } = await setup(t, {
registry: false,
testdir: {
home: {
'.npmrc': `proxy = "http://localhost:${PORT}/"`,
},
},
})

const server = createProxy(http.createServer())
await new Promise(res => server.listen(PORT, res))

t.teardown(() => server.close())

await t.test('npm install prodDep@version', async t => {
await npm('install', 'abbrev@1.0.4')

t.strictSame(await readFile('package.json'), {
dependencies: { abbrev: '^1.0.4' },
})
})
})

0 comments on commit 139cb41

Please sign in to comment.