diff options
author | npm-cli+bot@github.com <npm CLI robot> | 2022-05-11 17:17:18 +0000 |
---|---|---|
committer | Luigi Pinca <luigipinca@gmail.com> | 2022-05-18 19:13:24 +0200 |
commit | 06dd8c31fd7e736f1d0e57d8ae4a41227661bbc3 (patch) | |
tree | cd3b2a62ae1fd65261faab3ee4c81b73bd3bc4c5 /deps/npm/test | |
parent | 06ba40a8535f84e9fe34b597b7778162f1f67fcf (diff) | |
download | node-new-06dd8c31fd7e736f1d0e57d8ae4a41227661bbc3.tar.gz |
deps: upgrade npm to 8.10.0
PR-URL: https://github.com/nodejs/node/pull/43061
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'deps/npm/test')
-rw-r--r-- | deps/npm/test/coverage-map.js | 26 | ||||
-rw-r--r-- | deps/npm/test/fixtures/libnpmsearch-stream-result.js | 27 | ||||
-rw-r--r-- | deps/npm/test/fixtures/mock-registry.js | 27 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/deprecate.js | 6 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/docs.js | 13 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/owner.js | 44 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/search.js | 302 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/star.js | 154 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/unstar.js | 73 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/view.js | 457 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/config/definitions.js | 11 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/file-exists.js | 30 | ||||
-rw-r--r-- | deps/npm/test/lib/utils/hosted-git-info-from-manifest.js | 21 |
13 files changed, 493 insertions, 698 deletions
diff --git a/deps/npm/test/coverage-map.js b/deps/npm/test/coverage-map.js deleted file mode 100644 index 9a289b6489..0000000000 --- a/deps/npm/test/coverage-map.js +++ /dev/null @@ -1,26 +0,0 @@ -const coverageMap = (filename) => { - const { basename } = require('path') - const testbase = basename(filename) - if (filename === 'test/index.js') { - return ['index.js'] - } - if (testbase === 'load-all-commands.js') { - const { cmdList } = require('../lib/utils/cmd-list.js') - return cmdList.map(cmd => `lib/${cmd}.js`) - .concat('lib/base-command.js') - } - if (/^test\/lib\/commands/.test(filename) || filename === 'test/lib/npm.js') { - return [ - filename.replace(/^test\//, ''), - 'lib/npm.js', - 'lib/base-command.js', - 'lib/exec/get-workspace-location-msg.js', - ] - } - if (/^test\/(lib|bin)\//.test(filename)) { - return filename.replace(/^test\//, '') - } - return [] -} - -module.exports = coverageMap diff --git a/deps/npm/test/fixtures/libnpmsearch-stream-result.js b/deps/npm/test/fixtures/libnpmsearch-stream-result.js index 4d3aca396f..b2ec20f59e 100644 --- a/deps/npm/test/fixtures/libnpmsearch-stream-result.js +++ b/deps/npm/test/fixtures/libnpmsearch-stream-result.js @@ -5,7 +5,7 @@ module.exports = [ version: '3.0.1', description: 'Collection of programmatic APIs for the npm CLI', keywords: ['npm', 'api', 'package manager', 'lib'], - date: new Date('2019-07-16T17:50:00.572Z'), + date: '2019-07-16T17:50:00.572Z', links: { npm: 'https://www.npmjs.com/package/libnpm', homepage: 'https://github.com/npm/libnpm#readme', @@ -26,7 +26,8 @@ module.exports = [ scope: 'unscoped', version: '4.0.1', description: 'programmatic library for `npm access` commands', - date: new Date('2020-11-03T19:19:00.526Z'), + keywords: 'libnpmaccess', + date: '2020-11-03T19:19:00.526Z', links: { npm: 'https://www.npmjs.com/package/libnpmaccess', homepage: 'https://npmjs.com/package/libnpmaccess', @@ -47,7 +48,7 @@ module.exports = [ scope: 'evocateur', version: '3.1.2', description: 'programmatic library for `npm access` commands', - date: new Date('2019-07-16T19:43:33.959Z'), + date: '2019-07-16T19:43:33.959Z', links: { npm: 'https://www.npmjs.com/package/%40evocateur%2Flibnpmaccess', homepage: 'https://npmjs.com/package/@evocateur/libnpmaccess', @@ -63,7 +64,7 @@ module.exports = [ scope: 'evocateur', version: '1.2.2', description: 'Programmatic API for the bits behind npm publish and unpublish', - date: new Date('2019-07-16T19:40:40.850Z'), + date: '2019-07-16T19:40:40.850Z', links: { npm: 'https://www.npmjs.com/package/%40evocateur%2Flibnpmpublish', homepage: 'https://npmjs.com/package/@evocateur/libnpmpublish', @@ -80,7 +81,7 @@ module.exports = [ version: '2.0.1', description: 'Programmatic api for `npm org` commands', keywords: ['libnpm', 'npm', 'package manager', 'api', 'orgs', 'teams'], - date: new Date('2020-11-03T19:21:57.757Z'), + date: '2020-11-03T19:21:57.757Z', links: { npm: 'https://www.npmjs.com/package/libnpmorg', homepage: 'https://npmjs.com/package/libnpmorg', @@ -102,7 +103,7 @@ module.exports = [ version: '3.1.0', description: 'Programmatic API for searching in npm and compatible registries.', keywords: ['npm', 'search', 'api', 'libnpm'], - date: new Date('2020-12-08T23:54:18.374Z'), + date: '2020-12-08T23:54:18.374Z', links: { npm: 'https://www.npmjs.com/package/libnpmsearch', homepage: 'https://npmjs.com/package/libnpmsearch', @@ -123,7 +124,7 @@ module.exports = [ scope: 'unscoped', version: '2.0.2', description: 'npm Team management APIs', - date: new Date('2020-11-03T19:24:42.380Z'), + date: '2020-11-03T19:24:42.380Z', links: { npm: 'https://www.npmjs.com/package/libnpmteam', homepage: 'https://npmjs.com/package/libnpmteam', @@ -145,7 +146,7 @@ module.exports = [ version: '6.0.1', description: 'programmatic API for managing npm registry hooks', keywords: ['npm', 'hooks', 'registry', 'npm api'], - date: new Date('2020-11-03T19:20:45.818Z'), + date: '2020-11-03T19:20:45.818Z', links: { npm: 'https://www.npmjs.com/package/libnpmhook', homepage: 'https://github.com/npm/libnpmhook#readme', @@ -166,7 +167,7 @@ module.exports = [ scope: 'unscoped', version: '4.0.0', description: 'Programmatic API for the bits behind npm publish and unpublish', - date: new Date('2020-11-03T19:13:43.780Z'), + date: '2020-11-03T19:13:43.780Z', links: { npm: 'https://www.npmjs.com/package/libnpmpublish', homepage: 'https://npmjs.com/package/libnpmpublish', @@ -193,7 +194,7 @@ module.exports = [ 'git', 'fund', 'gitfund', ], - date: new Date('2020-12-08T23:22:00.213Z'), + date: '2020-12-08T23:22:00.213Z', links: { npm: 'https://www.npmjs.com/package/libnpmfund', homepage: 'https://github.com/npm/libnpmfund#readme', @@ -222,7 +223,7 @@ module.exports = [ 'workspaces', 'map-workspaces', ], - date: new Date('2020-09-30T15:16:29.017Z'), + date: '2020-09-30T15:16:29.017Z', links: { npm: 'https://www.npmjs.com/package/%40npmcli%2Fmap-workspaces', homepage: 'https://github.com/npm/map-workspaces#readme', @@ -243,7 +244,7 @@ module.exports = [ scope: 'unscoped', version: '1.0.7', description: "library to do the things that 'npm version' does", - date: new Date('2020-11-04T00:21:41.069Z'), + date: '2020-11-04T00:21:41.069Z', links: { npm: 'https://www.npmjs.com/package/libnpmversion', homepage: 'https://github.com/npm/libnpmversion#readme', @@ -269,7 +270,7 @@ module.exports = [ scope: 'types', version: '2.0.1', description: 'TypeScript definitions for libnpmsearch', - date: new Date('2019-09-26T22:24:28.713Z'), + date: '2019-09-26T22:24:28.713Z', links: { npm: 'https://www.npmjs.com/package/%40types%2Flibnpmsearch' }, publisher: { username: 'types', email: 'ts-npm-types@microsoft.com' }, maintainers: [{ username: 'types', email: 'ts-npm-types@microsoft.com' }], diff --git a/deps/npm/test/fixtures/mock-registry.js b/deps/npm/test/fixtures/mock-registry.js index 5890fa7ee9..a62890b72e 100644 --- a/deps/npm/test/fixtures/mock-registry.js +++ b/deps/npm/test/fixtures/mock-registry.js @@ -46,6 +46,19 @@ class MockRegistry { this.#nock = nock } + search ({ responseCode = 200, results = [], error }) { + // the flags, score, and searchScore parts of the response are never used + // by npm, only package is used + const response = results.map(p => ({ package: p })) + this.nock = this.nock.get('/-/v1/search').query(true) + if (error) { + this.nock = this.nock.replyWithError(error) + } else { + this.nock = this.nock.reply(responseCode, { objects: response }) + } + return this.nock + } + whoami ({ username, body, responseCode = 200, times = 1 }) { if (username) { this.nock = this.nock.get('/-/whoami').times(times).reply(responseCode, { username }) @@ -170,6 +183,15 @@ class MockRegistry { } } + star (manifest, users) { + const spec = npa(manifest.name) + this.nock = this.nock.put(`/${spec.escapedName}`, { + _id: manifest._id, + _rev: manifest._rev, + users, + }).reply(200, { ...manifest, users }) + } + async package ({ manifest, times = 1, query, tarballs }) { let nock = this.nock const spec = npa(manifest.name) @@ -193,7 +215,7 @@ class MockRegistry { // either pass in packuments if you need to set specific attributes besides version, // or an array of versions // the last packument in the packuments or versions array will be tagged latest - manifest ({ name = 'test-package', packuments, versions } = {}) { + manifest ({ name = 'test-package', users, packuments, versions } = {}) { packuments = this.packuments(packuments, name) const latest = packuments.slice(-1)[0] const manifest = { @@ -207,6 +229,9 @@ class MockRegistry { 'dist-tags': { latest: latest.version }, ...latest, } + if (users) { + manifest.users = users + } if (versions) { packuments = versions.map(version => ({ version })) } diff --git a/deps/npm/test/lib/commands/deprecate.js b/deps/npm/test/lib/commands/deprecate.js index 03177cb7be..8a925fc2a6 100644 --- a/deps/npm/test/lib/commands/deprecate.js +++ b/deps/npm/test/lib/commands/deprecate.js @@ -85,7 +85,7 @@ t.test('undeprecate', async t => { name: 'foo', versions, }) - registry.package({ manifest, query: { write: true } }) + await registry.package({ manifest, query: { write: true } }) registry.nock.put('/foo', body => { for (const version of versions) { if (body.versions[version].deprecated !== '') { @@ -110,7 +110,7 @@ t.test('deprecates given range', async t => { name: 'foo', versions, }) - registry.package({ manifest, query: { write: true } }) + await registry.package({ manifest, query: { write: true } }) const message = 'test deprecation message' registry.nock.put('/foo', body => { if (body.versions['1.0.1'].deprecated) { @@ -136,7 +136,7 @@ t.test('deprecates all versions when no range is specified', async t => { name: 'foo', versions, }) - registry.package({ manifest, query: { write: true } }) + await registry.package({ manifest, query: { write: true } }) const message = 'test deprecation message' registry.nock.put('/foo', body => { for (const version of versions) { diff --git a/deps/npm/test/lib/commands/docs.js b/deps/npm/test/lib/commands/docs.js index a3b31bd706..b2a65786bf 100644 --- a/deps/npm/test/lib/commands/docs.js +++ b/deps/npm/test/lib/commands/docs.js @@ -35,6 +35,13 @@ const pkgDirs = t.testdir({ repository: { url: 'https://github.com/foo/repoobj' }, }), }, + repourlobj: { + 'package.json': JSON.stringify({ + name: 'repourlobj', + version: '1.2.3', + repository: { url: { works: false } }, + }), + }, workspaces: { 'package.json': JSON.stringify({ name: 'workspaces-test', @@ -81,14 +88,13 @@ const docs = new Docs(npm) t.afterEach(() => opened = {}) t.test('open docs urls', t => { - // XXX It is very odd that `where` is how pacote knows to look anywhere other - // than the cwd. I would think npm.localPrefix would factor in somehow - flatOptions.where = pkgDirs + npm.localPrefix = pkgDirs const expect = { nodocs: 'https://www.npmjs.com/package/nodocs', docsurl: 'https://bugzilla.localhost/docsurl', repourl: 'https://github.com/foo/repourl#readme', repoobj: 'https://github.com/foo/repoobj#readme', + repourlobj: 'https://www.npmjs.com/package/repourlobj', '.': 'https://example.com', } const keys = Object.keys(expect) @@ -110,7 +116,6 @@ t.test('open default package if none specified', async t => { }) t.test('workspaces', (t) => { - flatOptions.where = undefined npm.localPrefix = join(pkgDirs, 'workspaces') t.test('all workspaces', async t => { await docs.execWorkspaces([], []) diff --git a/deps/npm/test/lib/commands/owner.js b/deps/npm/test/lib/commands/owner.js index 800d5b96a5..f8ab7feef5 100644 --- a/deps/npm/test/lib/commands/owner.js +++ b/deps/npm/test/lib/commands/owner.js @@ -46,7 +46,7 @@ function registryPackage (t, registry, name) { name, packuments: [{ maintainers, version: '1.0.0' }], }) - mockRegistry.package({ manifest }) + return mockRegistry.package({ manifest }) } t.test('owner no args', async t => { @@ -73,7 +73,7 @@ t.test('owner ls no args', async t => { name: packageName, packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) await npm.exec('owner', ['ls']) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) @@ -137,7 +137,7 @@ t.test('owner ls <pkg>', async t => { name: packageName, packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) await npm.exec('owner', ['ls', packageName]) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) @@ -153,7 +153,7 @@ t.test('owner ls <pkg> no maintainers', async t => { name: packageName, versions: ['1.0.0'], }) - registry.package({ manifest }) + await registry.package({ manifest }) await npm.exec('owner', ['ls', packageName]) t.equal(joinedOutput(), 'no admin found') @@ -173,7 +173,7 @@ t.test('owner add <user> <pkg>', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`, body => { t.match(body, { _id: manifest._id, @@ -206,7 +206,7 @@ t.test('owner add <user> cwd package', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`, body => { t.match(body, { _id: manifest._id, @@ -236,7 +236,7 @@ t.test('owner add <user> <pkg> already an owner', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) await npm.exec('owner', ['add', username, packageName]) t.equal(joinedOutput(), '') t.match( @@ -273,7 +273,7 @@ t.test('owner add <user> <pkg> fails to PUT updates', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`).reply(404, {}) await t.rejects( npm.exec('owner', ['add', username, packageName]), @@ -295,7 +295,7 @@ t.test('owner add <user> <pkg> no previous maintainers property from server', as packuments: [{ maintainers: undefined, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`, body => { t.match(body, { _id: manifest._id, @@ -351,7 +351,7 @@ t.test('owner rm <user> <pkg>', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`, body => { t.match(body, { _id: manifest._id, @@ -378,7 +378,7 @@ t.test('owner rm <user> <pkg> not a current owner', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) await npm.exec('owner', ['rm', username, packageName]) t.match(logs.info, [['owner rm', `Not a package owner: ${username}`]]) }) @@ -400,7 +400,7 @@ t.test('owner rm <user> cwd package', async t => { packuments: [{ maintainers, version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.nock.put(`/${spec.escapedName}/-rev/${manifest._rev}`, body => { t.match(body, { _id: manifest._id, @@ -430,7 +430,7 @@ t.test('owner rm <user> only user', async t => { packuments: [{ maintainers: maintainers.slice(0, 1), version: '1.0.0' }], }) registry.couchuser({ username }) - registry.package({ manifest }) + await registry.package({ manifest }) await t.rejects( npm.exec('owner', ['rm', username]), { @@ -486,7 +486,7 @@ t.test('workspaces', async t => { 'process.cwd': () => path.join(prefix, 'workspace-a'), }), }) - registryPackage(t, npm.config.get('registry'), 'workspace-a') + await registryPackage(t, npm.config.get('registry'), 'workspace-a') await npm.exec('owner', ['ls']) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) }) @@ -499,7 +499,7 @@ t.test('workspaces', async t => { }), }) npm.config.set('workspace', ['workspace-a']) - registryPackage(t, npm.config.get('registry'), 'workspace-a') + await registryPackage(t, npm.config.get('registry'), 'workspace-a') await npm.exec('owner', ['ls']) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) }) @@ -511,7 +511,7 @@ t.test('workspaces', async t => { 'process.cwd': () => path.join(prefix, 'workspace-a'), }), }) - registryPackage(t, npm.config.get('registry'), packageName) + await registryPackage(t, npm.config.get('registry'), packageName) await npm.exec('owner', ['ls', packageName]) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) }) @@ -524,7 +524,7 @@ t.test('workspaces', async t => { }), }) npm.config.set('workspace', ['workspace-a']) - registryPackage(t, npm.config.get('registry'), packageName) + await registryPackage(t, npm.config.get('registry'), packageName) await npm.exec('owner', ['ls', packageName]) t.match(joinedOutput(), maintainers.map(m => `${m.name} <${m.email}>`).join('\n')) }) @@ -543,7 +543,7 @@ t.test('workspaces', async t => { name: 'workspace-a', packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.couchuser({ username }) registry.nock.put(`/workspace-a/-rev/${manifest._rev}`, body => { t.match(body, { @@ -572,7 +572,7 @@ t.test('workspaces', async t => { name: 'workspace-a', packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.couchuser({ username }) registry.nock.put(`/workspace-a/-rev/${manifest._rev}`, body => { t.match(body, { @@ -603,7 +603,7 @@ t.test('workspaces', async t => { name: 'workspace-a', packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) registry.couchuser({ username }) registry.nock.put(`/workspace-a/-rev/${manifest._rev}`, body => { t.match(body, { @@ -649,7 +649,7 @@ t.test('completion', async t => { name: packageName, packuments: [{ maintainers, version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) const res = await owner.completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } }) t.strictSame(res, maintainers.map(m => m.name), 'should return list of current owners') }) @@ -683,7 +683,7 @@ t.test('completion', async t => { name: packageName, packuments: [{ maintainers: [], version: '1.0.0' }], }) - registry.package({ manifest }) + await registry.package({ manifest }) const res = await owner.completion({ conf: { argv: { remain: ['npm', 'owner', 'rm'] } } }) t.strictSame(res, [], 'should return no owners if not found') diff --git a/deps/npm/test/lib/commands/search.js b/deps/npm/test/lib/commands/search.js index d2462b1aed..f18fcc475a 100644 --- a/deps/npm/test/lib/commands/search.js +++ b/deps/npm/test/lib/commands/search.js @@ -1,169 +1,92 @@ const t = require('tap') -const Minipass = require('minipass') -const { fake: mockNpm } = require('../../fixtures/mock-npm') +const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') +const MockRegistry = require('../../fixtures/mock-registry.js') const libnpmsearchResultFixture = require('../../fixtures/libnpmsearch-stream-result.js') -let result = '' -const flatOptions = { - search: { - exclude: null, - limit: 20, - opts: '', - }, -} -const config = { - json: false, - parseable: false, -} -const npm = mockNpm({ - config, - flatOptions: { ...flatOptions }, - output: (...msg) => { - result += msg.join('\n') - }, -}) -const npmlog = { - silly () {}, - clearProgress () {}, -} -const libnpmsearch = { - stream () {}, -} -const mocks = { - npmlog, - libnpmsearch, -} - -t.afterEach(() => { - result = '' - config.json = false - config.parseable = false - npm.flatOptions = { ...flatOptions } -}) - -const Search = t.mock('../../../lib/commands/search.js', mocks) -const search = new Search(npm) - t.test('no args', async t => { + const { npm } = await loadMockNpm(t) await t.rejects( - search.exec([]), + npm.exec('search', []), /search must be called with arguments/, 'should throw usage instructions' ) }) -t.test('search <name>', async t => { - const src = new Minipass() - src.objectMode = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, +t.test('search <name> text', async t => { + const { npm, joinedOutput } = await loadMockNpm(t) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - for (const i of libnpmsearchResultFixture) { - src.write(i) - } - - src.end() - - await search.exec(['libnpm']) - t.matchSnapshot(result, 'should have expected search results') + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'should have expected search results') }) t.test('search <name> --json', async t => { - const src = new Minipass() - src.objectMode = true - - npm.flatOptions.json = true - config.json = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, + const { npm, joinedOutput } = await loadMockNpm(t, { config: { json: true } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - for (const i of libnpmsearchResultFixture) { - src.write(i) - } + registry.search({ results: libnpmsearchResultFixture }) - src.end() - await search.exec(['libnpm']) - - const parsedResult = JSON.parse(result) - parsedResult.forEach((entry) => { - entry.date = new Date(entry.date) - }) + await npm.exec('search', ['libnpm']) t.same( - parsedResult, + JSON.parse(joinedOutput()), libnpmsearchResultFixture, 'should have expected search results as json' ) +}) - config.json = false +t.test('search <name> --parseable', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { parseable: true } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) + + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'should have expected search results as parseable') }) -t.test('search <invalid-module> --json', async t => { - const src = new Minipass() - src.objectMode = true - - npm.flatOptions.json = true - config.json = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, +t.test('search <name> --color', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { color: 'always' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - src.end() - await search.exec(['foo']) + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'should have expected search results with color') +}) - t.equal(result, '\n[]\n', 'should have expected empty square brackets') +t.test('search /<name>/--color', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { color: 'always' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) - config.json = false + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['/libnpm/']) + t.matchSnapshot(joinedOutput(), 'should have expected search results with color') }) -t.test('search <name> --searchexclude --searchopts', async t => { - npm.flatOptions.search = { - ...flatOptions.search, - exclude: '', - } - - const src = new Minipass() - src.objectMode = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, +t.test('search <name>', async t => { + const { npm, joinedOutput } = await loadMockNpm(t) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - src.write({ + registry.search({ results: [{ name: 'foo', scope: 'unscoped', version: '1.0.0', @@ -175,8 +98,7 @@ t.test('search <name> --searchexclude --searchopts', async t => { maintainers: [ { username: 'foo', email: 'foo@npmjs.com' }, ], - }) - src.write({ + }, { name: 'libnpmversion', scope: 'unscoped', version: '1.0.0', @@ -188,58 +110,100 @@ t.test('search <name> --searchexclude --searchopts', async t => { maintainers: [ { username: 'foo', email: 'foo@npmjs.com' }, ], - }) + }] }) - src.end() - await search.exec(['foo']) + await npm.exec('search', ['foo']) - t.matchSnapshot(result, 'should have filtered expected search results') + t.matchSnapshot(joinedOutput(), 'should have filtered expected search results') }) t.test('empty search results', async t => { - const src = new Minipass() - src.objectMode = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, + const { npm, joinedOutput } = await loadMockNpm(t) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - src.end() - await search.exec(['foo']) + registry.search({ results: [] }) + await npm.exec('search', ['foo']) - t.matchSnapshot(result, 'should have expected search results') + t.matchSnapshot(joinedOutput(), 'should have expected search results') }) -t.test('search api response error', async t => { - const src = new Minipass() - src.objectMode = true - const libnpmsearch = { - stream () { - return src - }, - } - - const Search = t.mock('../../../lib/commands/search.js', { - ...mocks, - libnpmsearch, +t.test('empty search results --json', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { json: true } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) - const search = new Search(npm) - setImmediate(() => { - src.emit('error', new Error('ERR')) - src.end() + registry.search({ results: [] }) + + await npm.exec('search', ['foo']) + t.equal(joinedOutput(), '\n[]\n', 'should have expected empty square brackets') +}) + +t.test('search api response error', async t => { + const { npm } = await loadMockNpm(t) + + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), }) + registry.search({ error: 'ERR' }) + await t.rejects( - search.exec(['foo']), + npm.exec('search', ['foo']), /ERR/, 'should throw response error' ) }) + +t.test('search exclude string', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { searchexclude: 'libnpmversion' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) + + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'results should not have libnpmversion') +}) + +t.test('search exclude username with upper case letters', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { searchexclude: 'NLF' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) + + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'results should not have nlf') +}) + +t.test('search exclude regex', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { searchexclude: '/version/' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) + + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'results should not have libnpmversion') +}) + +t.test('search exclude forward slash', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { config: { searchexclude: '/version' } }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + }) + + registry.search({ results: libnpmsearchResultFixture }) + await npm.exec('search', ['libnpm']) + t.matchSnapshot(joinedOutput(), 'results should not have libnpmversion') +}) diff --git a/deps/npm/test/lib/commands/star.js b/deps/npm/test/lib/commands/star.js index 5b79c07769..ce9d258be1 100644 --- a/deps/npm/test/lib/commands/star.js +++ b/deps/npm/test/lib/commands/star.js @@ -1,133 +1,61 @@ const t = require('tap') -const { fake: mockNpm } = require('../../fixtures/mock-npm') +const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') +const MockRegistry = require('../../fixtures/mock-registry.js') -let result = '' - -const noop = () => null -const config = { - unicode: false, - 'star.unstar': false, -} -const npm = mockNpm({ - config, - output: (...msg) => { - result += msg.join('\n') - }, -}) -const npmFetch = { json: noop } -const log = { error: noop, info: noop, verbose: noop } -const mocks = { - 'proc-log': log, - 'npm-registry-fetch': npmFetch, - '../../../lib/utils/get-identity.js': async () => 'foo', -} - -const Star = t.mock('../../../lib/commands/star.js', mocks) -const star = new Star(npm) - -t.afterEach(() => { - config.unicode = false - config['star.unstar'] = false - log.info = noop - result = '' -}) +const pkgName = '@npmcli/test-package' +const authToken = 'test-auth-token' +const username = 'test-user' +const auth = { '//registry.npmjs.org/:_authToken': authToken } t.test('no args', async t => { + const { npm } = await loadMockNpm(t) await t.rejects( - star.exec([]), + npm.exec('star', []), { code: 'EUSAGE' }, 'should throw usage error' ) }) -t.test('star a package', async t => { - t.plan(4) - const pkgName = '@npmcli/arborist' - npmFetch.json = async (uri, opts) => { - return { - _id: pkgName, - _rev: 'hash', - users: ( - opts.method === 'PUT' - ? { foo: true } - : {} - ), - } - } - log.info = (title, msg, id) => { - t.equal(title, 'star', 'should use expected title') - t.equal(msg, 'starring', 'should use expected msg') - t.equal(id, pkgName, 'should use expected id') - } - await star.exec([pkgName]) - t.equal( - result, - '(*) @npmcli/arborist', - 'should output starred package msg' - ) -}) +t.test('first person to star a package unicode:false', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { + config: { unicode: false, ...auth }, + }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + authorization: authToken, + }) + const manifest = registry.manifest({ name: pkgName }) + await registry.package({ manifest, query: { write: true } }) + registry.whoami({ username }) + registry.star(manifest, { [username]: true }) -t.test('unstar a package', async t => { - t.plan(4) - const pkgName = '@npmcli/arborist' - config['star.unstar'] = true - npmFetch.json = async (uri, opts) => { - return { - _id: pkgName, - _rev: 'hash', - ...(opts.method === 'PUT' - ? {} - : { foo: true } - ), - } - } - log.info = (title, msg, id) => { - t.equal(title, 'unstar', 'should use expected title') - t.equal(msg, 'unstarring', 'should use expected msg') - t.equal(id, pkgName, 'should use expected id') - } - await star.exec([pkgName]) + await npm.exec('star', [pkgName]) t.equal( - result, - '( ) @npmcli/arborist', - 'should output unstarred package msg' + joinedOutput(), + '(*) @npmcli/test-package', + 'should output starred package msg' ) }) -t.test('unicode', async t => { - t.test('star a package', async t => { - config.unicode = true - npmFetch.json = async (uri, opts) => ({}) - await star.exec(['pkg']) - t.equal( - result, - '\u2605 pkg', - 'should output unicode starred package msg' - ) +t.test('second person to star a package unicode:true', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { + config: { unicode: true, ...auth }, }) - - t.test('unstar a package', async t => { - config.unicode = true - config['star.unstar'] = true - npmFetch.json = async (uri, opts) => ({}) - await star.exec(['pkg']) - t.equal( - result, - '\u2606 pkg', - 'should output unstarred package msg' - ) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + authorization: authToken, }) -}) + const manifest = registry.manifest({ name: pkgName, users: { otheruser: true } }) + await registry.package({ manifest, query: { write: true } }) + registry.whoami({ username }) + registry.star(manifest, { otheruser: true, [username]: true }) -t.test('logged out user', async t => { - const Star = t.mock('../../../lib/commands/star.js', { - ...mocks, - '../../../lib/utils/get-identity.js': async () => undefined, - }) - const star = new Star(npm) - await t.rejects( - star.exec(['@npmcli/arborist']), - /You need to be logged in/, - 'should throw login required error' + await npm.exec('star', [pkgName]) + t.equal( + joinedOutput(), + '★ @npmcli/test-package', + 'should output starred package msg' ) }) diff --git a/deps/npm/test/lib/commands/unstar.js b/deps/npm/test/lib/commands/unstar.js index fb3c269b7b..85c33d2793 100644 --- a/deps/npm/test/lib/commands/unstar.js +++ b/deps/npm/test/lib/commands/unstar.js @@ -1,29 +1,62 @@ const t = require('tap') +const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') +const MockRegistry = require('../../fixtures/mock-registry.js') -t.test('unstar', async t => { - t.plan(3) +const pkgName = '@npmcli/test-package' +const authToken = 'test-auth-token' +const username = 'test-user' +const auth = { '//registry.npmjs.org/:_authToken': authToken } - class Star { - constructor (npm) { - this.npm = npm - } +t.test('no args', async t => { + const { npm } = await loadMockNpm(t) + await t.rejects( + npm.exec('unstar', []), + { code: 'EUSAGE' }, + 'should throw usage error' + ) +}) + +t.test('unstar a package unicode:false', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { + config: { unicode: false, ...auth }, + }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + authorization: authToken, + }) + const manifest = registry.manifest({ name: pkgName, users: { [username]: true } }) + await registry.package({ manifest, query: { write: true } }) + registry.whoami({ username }) + registry.star(manifest, {}) + + await npm.exec('unstar', [pkgName]) + t.equal( + joinedOutput(), + '( ) @npmcli/test-package', + 'should output unstarred package msg' + ) +}) - async exec (args) { - t.same(args, ['pkg'], 'should forward packages') - } - } - const Unstar = t.mock('../../../lib/commands/unstar.js', { - '../../../lib/commands/star.js': Star, +t.test('unstar a package unicode:true', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { + config: { unicode: true, ...auth }, }) - const unstar = new Unstar({ - config: { - set: (key, value) => { - t.equal(key, 'star.unstar', 'should set unstar config value') - t.equal(value, true, 'should set a truthy value') - }, - }, + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + authorization: authToken, }) + const manifest = registry.manifest({ name: pkgName, users: { [username]: true } }) + await registry.package({ manifest, query: { write: true } }) + registry.whoami({ username }) + registry.star(manifest, {}) - await unstar.exec(['pkg']) + await npm.exec('unstar', [pkgName]) + t.equal( + joinedOutput(), + '☆ @npmcli/test-package', + 'should output unstarred package msg' + ) }) diff --git a/deps/npm/test/lib/commands/view.js b/deps/npm/test/lib/commands/view.js index 82be1201ee..da823db5d7 100644 --- a/deps/npm/test/lib/commands/view.js +++ b/deps/npm/test/lib/commands/view.js @@ -1,4 +1,5 @@ const t = require('tap') +const { load: _loadMockNpm } = require('../../fixtures/mock-npm.js') t.cleanSnapshot = str => str .replace(/(published ).*?( ago)/g, '$1{TIME}$2') @@ -6,18 +7,6 @@ t.cleanSnapshot = str => str // run the same as tap does when running directly with node process.stdout.columns = undefined -const { fake: mockNpm } = require('../../fixtures/mock-npm') - -let logs -const cleanLogs = () => { - logs = '' - const fn = (...args) => { - logs += '\n' - args.map(el => logs += el) - } - console.log = fn -} - // 3 days. its never yesterday and never a week ago const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24 * 3) @@ -71,7 +60,7 @@ const packument = (nv, opts) => { tarball: 'http://hm.blue.com/1.0.1.tgz', integrity: '---', fileCount: 1, - unpackedSize: 1, + unpackedSize: 1000, }, }, }, @@ -94,7 +83,7 @@ const packument = (nv, opts) => { tarball: 'http://hm.cyan.com/1.0.0.tgz', integrity: '---', fileCount: 1, - unpackedSize: 1, + unpackedSize: 1000000, }, }, '1.0.1': {}, @@ -180,7 +169,7 @@ const packument = (nv, opts) => { tarball: 'http://hm.green.com/1.0.0.tgz', integrity: '---', fileCount: 1, - unpackedSize: 1, + unpackedSize: 1000000000, }, }, '1.0.1': {}, @@ -271,289 +260,212 @@ const packument = (nv, opts) => { return mocks[nv.name] } -t.beforeEach(cleanLogs) - -t.test('should log package info', async t => { - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const npm = mockNpm({ - config: { unicode: false }, - }) - const view = new View(npm) - - const ViewJson = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, +const loadMockNpm = async function (t, opts = {}) { + const consoleLogs = [] + const mockNpm = await _loadMockNpm(t, { + mocks: { + pacote: { + packument, + }, }, - }) - const jsonNpm = mockNpm({ - config: { - json: true, - tag: 'latest', + globals: { + 'console.log': (...args) => { + consoleLogs.push(args) + }, }, + ...opts, }) - const viewJson = new ViewJson(jsonNpm) + return { ...mockNpm, consoleLogs } +} - const ViewUnicode = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const unicodeNpm = mockNpm({ - config: { unicode: true }, - }) - const viewUnicode = new ViewUnicode(unicodeNpm) +t.test('package from git', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['https://github.com/npm/green']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package from git', async t => { - await view.exec(['https://github.com/npm/green']) - t.matchSnapshot(logs) - }) +t.test('deprecated package with license, bugs, repository and other fields', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['green@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with license, bugs, repository and other fields', async t => { - await view.exec(['green@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('deprecated package with unicode', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: true } }) + await npm.exec('view', ['green@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with more than 25 deps', async t => { - await view.exec(['black@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with more than 25 deps', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['black@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with maintainers info as object', async t => { - await view.exec(['pink@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with maintainers info as object', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['pink@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with homepage', async t => { - await view.exec(['orange@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with homepage', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['orange@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with no versions', async t => { - await view.exec(['brown']) - t.equal(logs, '', 'no info to display') - }) +t.test('package with no versions', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['brown']) + t.equal(consoleLogs.join('\n'), '', 'no info to display') +}) - t.test('package with no repo or homepage', async t => { - await view.exec(['blue@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with no repo or homepage', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['blue@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with semver range', async t => { - await view.exec(['blue@^1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with semver range', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['blue@^1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with no modified time', async t => { - await viewUnicode.exec(['cyan@1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with no modified time', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { unicode: false } }) + await npm.exec('view', ['cyan@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with --json and semver range', async t => { - await viewJson.exec(['cyan@^1.0.0']) - t.matchSnapshot(logs) - }) +t.test('package with --json and semver range', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { json: true } }) + await npm.exec('view', ['cyan@^1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) +}) - t.test('package with --json and no versions', async t => { - await viewJson.exec(['brown']) - t.equal(logs, '', 'no info to display') - }) +t.test('package with --json and no versions', async t => { + const { npm, consoleLogs } = await loadMockNpm(t, { config: { json: true } }) + await npm.exec('view', ['brown']) + t.equal(consoleLogs.join('\n'), '', 'no info to display') }) -t.test('should log info of package in current working dir', async t => { - const testDir = t.testdir({ +t.test('package in cwd', async t => { + const prefixDir = { 'package.json': JSON.stringify({ name: 'blue', version: '1.0.0', }, null, 2), - }) - - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const npm = mockNpm({ - prefix: testDir, - config: { - tag: '1.0.0', - }, - }) - const view = new View(npm) + } t.test('specific version', async t => { - await view.exec(['.@1.0.0']) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { prefixDir }) + await npm.exec('view', ['.@1.0.0']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('non-specific version', async t => { - await view.exec(['.']) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { prefixDir }) + await npm.exec('view', ['.']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('directory', async t => { - await view.exec(['./blue']) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { prefixDir }) + await npm.exec('view', ['./blue']) + t.matchSnapshot(consoleLogs.join('\n')) }) }) -t.test('should log info by field name', async t => { - const ViewJson = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const jsonNpm = mockNpm({ - config: { - tag: 'latest', - json: true, - }, - }) - - const viewJson = new ViewJson(jsonNpm) - - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, +t.test('specific field names', async t => { + const { npm, consoleLogs } = await loadMockNpm(t) + t.afterEach(() => { + consoleLogs.length = 0 }) - const npm = mockNpm() - const view = new View(npm) - t.test('readme', async t => { - await view.exec(['yellow@1.0.0', 'readme']) - t.matchSnapshot(logs) + await npm.exec('view', ['yellow@1.0.0', 'readme']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('several fields', async t => { - await viewJson.exec(['yellow@1.0.0', 'name', 'version', 'foo[bar]']) - t.matchSnapshot(logs) + await npm.exec('view', ['yellow@1.0.0', 'name', 'version', 'foo[bar]']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('several fields with several versions', async t => { - await view.exec(['yellow@1.x.x', 'author']) - t.matchSnapshot(logs) + await npm.exec('view', ['yellow@1.x.x', 'author']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('nested field with brackets', async t => { - await viewJson.exec(['orange@1.0.0', 'dist[shasum]']) - t.matchSnapshot(logs) + await npm.exec('view', ['orange@1.0.0', 'dist[shasum]']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('maintainers with email', async t => { - await viewJson.exec(['yellow@1.0.0', 'maintainers', 'name']) - t.matchSnapshot(logs) + await npm.exec('view', ['yellow@1.0.0', 'maintainers', 'name']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('maintainers with url', async t => { - await viewJson.exec(['pink@1.0.0', 'maintainers']) - t.matchSnapshot(logs) + await npm.exec('view', ['pink@1.0.0', 'maintainers']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('unknown nested field ', async t => { - await view.exec(['yellow@1.0.0', 'dist.foobar']) - t.equal(logs, '', 'no info to display') + await npm.exec('view', ['yellow@1.0.0', 'dist.foobar']) + t.equal(consoleLogs.join('\n'), '', 'no info to display') }) t.test('array field - 1 element', async t => { - await view.exec(['purple@1.0.0', 'maintainers.name']) - t.matchSnapshot(logs) + await npm.exec('view', ['purple@1.0.0', 'maintainers.name']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('array field - 2 elements', async t => { - await view.exec(['yellow@1.x.x', 'maintainers.name']) - t.matchSnapshot(logs) + await npm.exec('view', ['yellow@1.x.x', 'maintainers.name']) + t.matchSnapshot(consoleLogs.join('\n')) }) }) t.test('throw error if global mode', async t => { - const View = t.mock('../../../lib/commands/view.js') - const npm = mockNpm({ - config: { - global: true, - tag: 'latest', - }, - }) - const view = new View(npm) + const { npm } = await loadMockNpm(t, { config: { global: true } }) await t.rejects( - view.exec([]), + npm.exec('view', []), /Cannot use view command in global mode./ ) }) t.test('throw ENOENT error if package.json missing', async t => { - const testDir = t.testdir({}) - - const View = t.mock('../../../lib/commands/view.js') - const npm = mockNpm({ - prefix: testDir, - }) - const view = new View(npm) + const { npm } = await loadMockNpm(t) await t.rejects( - view.exec([]), + npm.exec('view', []), { code: 'ENOENT' } ) }) -t.test('throw EJSONPARSE error if package.json not json', async t => { - const testDir = t.testdir({ - 'package.json': 'not json, nope, not even a little bit!', - }) - - const View = t.mock('../../../lib/commands/view.js') - const npm = mockNpm({ - prefix: testDir, - }) - const view = new View(npm) - await t.rejects( - view.exec([]), - { code: 'EJSONPARSE' } - ) -}) - t.test('throw error if package.json has no name', async t => { - const testDir = t.testdir({ - 'package.json': '{}', - }) - - const View = t.mock('../../../lib/commands/view.js') - const npm = mockNpm({ - prefix: testDir, + const { npm } = await loadMockNpm(t, { + prefixDir: { + 'package.json': '{}', + }, }) - const view = new View(npm) await t.rejects( - view.exec([]), + npm.exec('view', []), /Invalid package.json, no "name" field/ ) }) t.test('throws when unpublished', async t => { - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const npm = mockNpm({ - config: { - tag: '1.0.1', - }, - }) - const view = new View(npm) + const { npm } = await loadMockNpm(t) await t.rejects( - view.exec(['red']), + npm.exec('view', ['red']), { code: 'E404', pkgid: 'red@1.0.1', message: 'Unpublished on 2012-12-20T00:00:00.000Z' } ) }) t.test('workspaces', async t => { - t.beforeEach(() => { - warnMsg = undefined - config.json = false - }) - const testDir = t.testdir({ + const prefixDir = { 'package.json': JSON.stringify({ name: 'workspaces-test-package', version: '1.2.3', @@ -571,106 +483,103 @@ t.test('workspaces', async t => { version: '1.2.3', }), }, - }) - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - 'proc-log': { - warn: (msg) => { - warnMsg = msg - }, - silly: () => {}, - }, - }) - const config = { - unicode: false, - tag: 'latest', } - let warnMsg - const npm = mockNpm({ - config, - localPrefix: testDir, - }) - const view = new View(npm) t.test('all workspaces', async t => { - await view.execWorkspaces([], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true }, + }) + await npm.exec('view', []) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('one specific workspace', async t => { - await view.execWorkspaces([], ['green']) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspace: ['green'] }, + }) + await npm.exec('view', []) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('all workspaces --json', async t => { - config.json = true - await view.execWorkspaces([], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true, json: true }, + }) + await npm.exec('view', []) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('all workspaces single field', async t => { - await view.execWorkspaces(['.', 'name'], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true }, + }) + await npm.exec('view', ['.', 'name']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('all workspaces nonexistent field', async t => { - await view.execWorkspaces(['.', 'foo'], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true }, + }) + await npm.exec('view', ['.', 'foo']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('all workspaces nonexistent field --json', async t => { - config.json = true - await view.execWorkspaces(['.', 'foo'], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true, json: true }, + }) + await npm.exec('view', ['.', 'foo']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('all workspaces single field --json', async t => { - config.json = true - await view.execWorkspaces(['.', 'name'], []) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true, json: true }, + }) + await npm.exec('view', ['.', 'name']) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('single workspace --json', async t => { - config.json = true - await view.execWorkspaces([], ['green']) - t.matchSnapshot(logs) + const { npm, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspace: ['green'], json: true }, + }) + await npm.exec('view', []) + t.matchSnapshot(consoleLogs.join('\n')) }) t.test('remote package name', async t => { - await view.execWorkspaces(['pink'], []) - t.matchSnapshot(warnMsg) - t.matchSnapshot(logs) + const { npm, logs, consoleLogs } = await loadMockNpm(t, { + prefixDir, + config: { unicode: false, workspaces: true }, + }) + await npm.exec('view', ['pink']) + t.matchSnapshot(consoleLogs.join('\n')) + t.matchSnapshot(logs.warn, 'should have warning of ignoring workspaces') }) }) t.test('completion', async t => { - const View = t.mock('../../../lib/commands/view.js', { - pacote: { - packument, - }, - }) - const npm = mockNpm({ - config: { - tag: '1.0.1', - }, - }) - const view = new View(npm) + const { npm } = await loadMockNpm(t) + const view = await npm.cmd('view') const res = await view.completion({ conf: { argv: { remain: ['npm', 'view', 'green@1.0.0'] } }, }) t.ok(res, 'returns back fields') }) -t.test('no registry completion', async t => { - const View = t.mock('../../../lib/commands/view.js') - const npm = mockNpm({ - config: { - tag: '1.0.1', - }, - }) - const view = new View(npm) +t.test('no package completion', async t => { + const { npm } = await loadMockNpm(t) + const view = await npm.cmd('view') const res = await view.completion({ conf: { argv: { remain: ['npm', 'view'] } } }) t.notOk(res, 'there is no package completion') t.end() diff --git a/deps/npm/test/lib/utils/config/definitions.js b/deps/npm/test/lib/utils/config/definitions.js index 088d0cdb6e..200ee9e553 100644 --- a/deps/npm/test/lib/utils/config/definitions.js +++ b/deps/npm/test/lib/utils/config/definitions.js @@ -457,6 +457,13 @@ t.test('retry options', t => { }) t.test('search options', t => { + const vals = { + description: 'test description', + exclude: 'test search exclude', + limit: 99, + staleneess: 99, + + } const obj = {} // <config>: flat.search[<option>] const mapping = { @@ -469,9 +476,9 @@ t.test('search options', t => { for (const [config, option] of Object.entries(mapping)) { const msg = `${config} -> search.${option}` const flat = {} - obj[config] = 99 + obj[config] = vals[option] definitions[config].flatten(config, obj, flat) - t.strictSame(flat, { search: { limit: 20, [option]: 99 } }, msg) + t.strictSame(flat, { search: { limit: 20, [option]: vals[option] } }, msg) delete obj[config] } diff --git a/deps/npm/test/lib/utils/file-exists.js b/deps/npm/test/lib/utils/file-exists.js deleted file mode 100644 index c8edf4d968..0000000000 --- a/deps/npm/test/lib/utils/file-exists.js +++ /dev/null @@ -1,30 +0,0 @@ -const t = require('tap') -const fileExists = require('../../../lib/utils/file-exists.js') - -t.test('returns true when arg is a file', async (t) => { - const path = t.testdir({ - foo: 'just some file', - }) - - const result = await fileExists(`${path}/foo`) - t.equal(result, true, 'file exists') - t.end() -}) - -t.test('returns false when arg is not a file', async (t) => { - const path = t.testdir({ - foo: {}, - }) - - const result = await fileExists(`${path}/foo`) - t.equal(result, false, 'file does not exist') - t.end() -}) - -t.test('returns false when arg does not exist', async (t) => { - const path = t.testdir() - - const result = await fileExists(`${path}/foo`) - t.equal(result, false, 'file does not exist') - t.end() -}) diff --git a/deps/npm/test/lib/utils/hosted-git-info-from-manifest.js b/deps/npm/test/lib/utils/hosted-git-info-from-manifest.js deleted file mode 100644 index 516d3d5867..0000000000 --- a/deps/npm/test/lib/utils/hosted-git-info-from-manifest.js +++ /dev/null @@ -1,21 +0,0 @@ -const t = require('tap') -const hostedFromMani = require('../../../lib/utils/hosted-git-info-from-manifest.js') -const hostedGitInfo = require('hosted-git-info') - -t.equal(hostedFromMani({}), null) -t.equal(hostedFromMani({ repository: { no: 'url' } }), null) -t.equal(hostedFromMani({ repository: 123 }), null) -t.equal(hostedFromMani({ repository: 'not hosted anywhere' }), null) -t.equal(hostedFromMani({ repository: { url: 'not hosted anywhere' } }), null) - -t.match(hostedFromMani({ - repository: 'git+https://github.com/isaacs/abbrev-js', -}), hostedGitInfo.fromUrl('git+https://github.com/isaacs/abbrev-js')) - -t.match(hostedFromMani({ - repository: { url: 'git+https://github.com/isaacs/abbrev-js' }, -}), hostedGitInfo.fromUrl('https://github.com/isaacs/abbrev-js')) - -t.match(hostedFromMani({ - repository: { url: 'git+ssh://git@github.com/isaacs/abbrev-js' }, -}), hostedGitInfo.fromUrl('ssh://git@github.com/isaacs/abbrev-js')) |