Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@github.com>2022-08-03 00:44:59 +0300
committerGitHub <noreply@github.com>2022-08-03 00:44:59 +0300
commit703dbbf2a8149dff72c848d60600889a76779828 (patch)
tree8af1d5cda4ec0a7d6dabbef6d4084916b782931f /workspaces/arborist/test
parentfd030c86b1e01b7df1b9d73fda07496742a4737f (diff)
feat: add --replace-registry-host=<npmjs|always|never> (#4860)
feat: add --replace-registry-host=<npmjs|always|never>|<hostname>
Diffstat (limited to 'workspaces/arborist/test')
-rw-r--r--workspaces/arborist/test/arborist/index.js9
-rw-r--r--workspaces/arborist/test/arborist/reify.js130
-rw-r--r--workspaces/arborist/test/fixtures/tnock.js14
3 files changed, 153 insertions, 0 deletions
diff --git a/workspaces/arborist/test/arborist/index.js b/workspaces/arborist/test/arborist/index.js
index 3469c5c73..7f69eb36e 100644
--- a/workspaces/arborist/test/arborist/index.js
+++ b/workspaces/arborist/test/arborist/index.js
@@ -236,3 +236,12 @@ t.test('lockfileVersion config validation', async t => {
message: 'Invalid lockfileVersion config: banana',
})
})
+
+t.test('valid replaceRegistryHost values', t => {
+ t.equal(new Arborist({ replaceRegistryHost: 'registry.garbage.com' }).options.replaceRegistryHost, 'registry.garbage.com')
+ t.equal(new Arborist({ replaceRegistryHost: 'npmjs' }).options.replaceRegistryHost, 'registry.npmjs.org')
+ t.equal(new Arborist({ replaceRegistryHost: undefined }).options.replaceRegistryHost, 'registry.npmjs.org')
+ t.equal(new Arborist({ replaceRegistryHost: 'always' }).options.replaceRegistryHost, 'always')
+ t.equal(new Arborist({ replaceRegistryHost: 'never' }).options.replaceRegistryHost, 'never')
+ t.end()
+})
diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js
index 406b4281d..db5a9c1fe 100644
--- a/workspaces/arborist/test/arborist/reify.js
+++ b/workspaces/arborist/test/arborist/reify.js
@@ -2,6 +2,7 @@ const { join, resolve, basename } = require('path')
const t = require('tap')
const runScript = require('@npmcli/run-script')
const localeCompare = require('@isaacs/string-locale-compare')('en')
+const tnock = require('../fixtures/tnock')
// mock rimraf so we can make it fail in rollback tests
const realRimraf = require('rimraf')
@@ -2923,3 +2924,132 @@ t.test('installLinks', (t) => {
t.end()
})
+
+t.only('should preserve exact ranges, missing actual tree', async (t) => {
+ const Arborist = require('../../lib/index.js')
+ const abbrev = resolve(__dirname,
+ '../fixtures/registry-mocks/content/abbrev/-/abbrev-1.1.1.tgz')
+ const abbrevTGZ = fs.readFileSync(abbrev)
+
+ const abbrevPackument = JSON.stringify({
+ _id: 'abbrev',
+ _rev: 'lkjadflkjasdf',
+ name: 'abbrev',
+ 'dist-tags': { latest: '1.1.1' },
+ versions: {
+ '1.1.1': {
+ name: 'abbrev',
+ version: '1.1.1',
+ dist: {
+ tarball: 'https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz',
+ },
+ },
+ },
+ })
+
+ const abbrevPackument2 = JSON.stringify({
+ _id: 'abbrev',
+ _rev: 'lkjadflkjasdf',
+ name: 'abbrev',
+ 'dist-tags': { latest: '1.1.1' },
+ versions: {
+ '1.1.1': {
+ name: 'abbrev',
+ version: '1.1.1',
+ dist: {
+ tarball: 'https://registry.garbage.org/abbrev/-/abbrev-1.1.1.tgz',
+ },
+ },
+ },
+ })
+
+ t.only('host should not be replaced replaceRegistryHost=never', async (t) => {
+ const testdir = t.testdir({
+ project: {
+ 'package.json': JSON.stringify({
+ name: 'myproject',
+ version: '1.0.0',
+ dependencies: {
+ abbrev: '1.1.1',
+ },
+ }),
+ },
+ })
+
+ tnock(t, 'https://registry.github.com')
+ .get('/abbrev')
+ .reply(200, abbrevPackument)
+
+ tnock(t, 'https://registry.npmjs.org')
+ .get('/abbrev/-/abbrev-1.1.1.tgz')
+ .reply(200, abbrevTGZ)
+
+ const arb = new Arborist({
+ path: resolve(testdir, 'project'),
+ registry: 'https://registry.github.com',
+ cache: resolve(testdir, 'cache'),
+ replaceRegistryHost: 'never',
+ })
+ await arb.reify()
+ })
+
+ t.only('host should be replaced replaceRegistryHost=npmjs', async (t) => {
+ const testdir = t.testdir({
+ project: {
+ 'package.json': JSON.stringify({
+ name: 'myproject',
+ version: '1.0.0',
+ dependencies: {
+ abbrev: '1.1.1',
+ },
+ }),
+ },
+ })
+
+ tnock(t, 'https://registry.github.com')
+ .get('/abbrev')
+ .reply(200, abbrevPackument)
+
+ tnock(t, 'https://registry.github.com')
+ .get('/abbrev/-/abbrev-1.1.1.tgz')
+ .reply(200, abbrevTGZ)
+
+ const arb = new Arborist({
+ path: resolve(testdir, 'project'),
+ registry: 'https://registry.github.com',
+ cache: resolve(testdir, 'cache'),
+ replaceRegistryHost: 'npmjs',
+ })
+ await arb.reify()
+ })
+
+ t.only('host should be always replaceRegistryHost=always', async (t) => {
+ const testdir = t.testdir({
+ project: {
+ 'package.json': JSON.stringify({
+ name: 'myproject',
+ version: '1.0.0',
+ dependencies: {
+ abbrev: '1.1.1',
+ },
+ }),
+ },
+ })
+
+ tnock(t, 'https://registry.github.com')
+ .get('/abbrev')
+ .reply(200, abbrevPackument2)
+
+ tnock(t, 'https://registry.github.com')
+ .get('/abbrev/-/abbrev-1.1.1.tgz')
+ .reply(200, abbrevTGZ)
+
+ const arb = new Arborist({
+ path: resolve(testdir, 'project'),
+ registry: 'https://registry.github.com',
+ cache: resolve(testdir, 'cache'),
+ replaceRegistryHost: 'always',
+ })
+ await arb.reify()
+ })
+})
diff --git a/workspaces/arborist/test/fixtures/tnock.js b/workspaces/arborist/test/fixtures/tnock.js
new file mode 100644
index 000000000..2e07f7364
--- /dev/null
+++ b/workspaces/arborist/test/fixtures/tnock.js
@@ -0,0 +1,14 @@
+'use strict'
+
+const nock = require('nock')
+
+module.exports = tnock
+function tnock (t, host) {
+ const server = nock(host)
+ nock.disableNetConnect()
+ t.teardown(function () {
+ nock.enableNetConnect()
+ server.done()
+ })
+ return server
+}