diff options
Diffstat (limited to 'deps/npm/test/lib/commands')
-rw-r--r-- | deps/npm/test/lib/commands/access.js | 5 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/adduser.js | 7 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/deprecate.js | 7 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/diff.js | 3 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/dist-tag.js | 10 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/doctor.js | 12 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/hook.js | 47 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/logout.js | 9 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/org.js | 41 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/owner.js | 26 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/ping.js | 9 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/publish.js | 60 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/run-script.js | 28 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/star.js | 6 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/team.js | 21 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/unpublish.js | 7 | ||||
-rw-r--r-- | deps/npm/test/lib/commands/update.js | 10 |
17 files changed, 99 insertions, 209 deletions
diff --git a/deps/npm/test/lib/commands/access.js b/deps/npm/test/lib/commands/access.js index c4e6f3167a..298897e4f5 100644 --- a/deps/npm/test/lib/commands/access.js +++ b/deps/npm/test/lib/commands/access.js @@ -75,13 +75,12 @@ t.test('access public on unscoped package', async t => { }) t.test('access public on scoped package', async t => { - t.plan(3) + t.plan(2) const name = '@scoped/npm-access-public-pkg' const { npm } = await loadMockNpm(t, { mocks: { libnpmaccess: { - public: (pkg, { registry, log }) => { - t.ok(log, 'should pass a logger') + public: (pkg, { registry }) => { t.equal(pkg, name, 'should use pkg name ref') t.equal( registry, diff --git a/deps/npm/test/lib/commands/adduser.js b/deps/npm/test/lib/commands/adduser.js index 8a9358f9ab..f88508d15a 100644 --- a/deps/npm/test/lib/commands/adduser.js +++ b/deps/npm/test/lib/commands/adduser.js @@ -20,13 +20,6 @@ const authDummy = (npm, options) => { throw new Error('did not pass full flatOptions to auth function') } - if (!options.log) { - // A quick to test to make sure a log gets passed to auth - // XXX: should be refactored with change to real mock npm - // https://github.com/npm/statusboard/issues/411 - throw new Error('pass log to auth') - } - return Promise.resolve({ message: 'success', newCreds: { diff --git a/deps/npm/test/lib/commands/deprecate.js b/deps/npm/test/lib/commands/deprecate.js index aa158cca3a..180629a748 100644 --- a/deps/npm/test/lib/commands/deprecate.js +++ b/deps/npm/test/lib/commands/deprecate.js @@ -2,15 +2,12 @@ const t = require('tap') let getIdentityImpl = () => 'someperson' let npmFetchBody = null -let npmFetchLog = null const npmFetch = async (uri, opts) => { npmFetchBody = opts.body - npmFetchLog = opts.log } npmFetch.json = async (uri, opts) => { - npmFetchLog = opts.log return { versions: { '1.0.0': {}, @@ -87,10 +84,8 @@ t.test('invalid semver range', async t => { t.test('undeprecate', async t => { t.teardown(() => { npmFetchBody = null - npmFetchLog = null }) await deprecate.exec(['foo', '']) - t.ok(npmFetchLog, 'was passed a logger') t.match(npmFetchBody, { versions: { '1.0.0': { deprecated: '' }, @@ -103,11 +98,9 @@ t.test('undeprecate', async t => { t.test('deprecates given range', async t => { t.teardown(() => { npmFetchBody = null - npmFetchLog = null }) await deprecate.exec(['foo@1.0.0', 'this version is deprecated']) - t.ok(npmFetchLog, 'was passed a logger') t.match(npmFetchBody, { versions: { '1.0.0': { diff --git a/deps/npm/test/lib/commands/diff.js b/deps/npm/test/lib/commands/diff.js index f73a543cb4..ed0702e378 100644 --- a/deps/npm/test/lib/commands/diff.js +++ b/deps/npm/test/lib/commands/diff.js @@ -61,10 +61,9 @@ const diff = new Diff(npm) t.test('no args', t => { t.test('in a project dir', async t => { - t.plan(4) + t.plan(3) libnpmdiff = async ([a, b], opts) => { - t.ok(opts.log, 'should be passed a logger') t.equal(a, 'foo@latest', 'should have default spec comparison') t.equal(b, `file:${fooPath}`, 'should compare to cwd') t.match(opts, npm.flatOptions, 'should forward flat options') diff --git a/deps/npm/test/lib/commands/dist-tag.js b/deps/npm/test/lib/commands/dist-tag.js index b83c30e9c6..eb13c7ff02 100644 --- a/deps/npm/test/lib/commands/dist-tag.js +++ b/deps/npm/test/lib/commands/dist-tag.js @@ -43,7 +43,6 @@ const routeMap = { // XXX overriding this does not appear to do anything, adding t.plan to things // that use it fails the test let npmRegistryFetchMock = (url, opts) => { - npmRegistryFetchLog = opts.log if (url === '/-/package/foo/dist-tags') { throw new Error('no package found') } @@ -51,9 +50,7 @@ let npmRegistryFetchMock = (url, opts) => { return routeMap[url] } -let npmRegistryFetchLog npmRegistryFetchMock.json = async (url, opts) => { - npmRegistryFetchLog = opts.log return routeMap[url] } @@ -86,10 +83,6 @@ const npm = mockNpm({ }) const distTag = new DistTag(npm) -t.afterEach(() => { - npmRegistryFetchLog = null -}) - t.test('ls in current package', async t => { npm.prefix = t.testdir({ 'package.json': JSON.stringify({ @@ -97,7 +90,6 @@ t.test('ls in current package', async t => { }), }) await distTag.exec(['ls']) - t.ok(npmRegistryFetchLog, 'is passed a logger') t.matchSnapshot( result, 'should list available tags for current package' @@ -299,7 +291,6 @@ t.test('add new tag', async t => { }) npmRegistryFetchMock = async (url, opts) => { - t.ok(opts.log, 'is passed a logger') t.equal(opts.method, 'PUT', 'should trigger request to add new tag') t.equal(opts.body, '7.7.7', 'should point to expected version') } @@ -366,7 +357,6 @@ t.test('remove existing tag', async t => { } npm.prefix = t.testdir({}) await distTag.exec(['rm', '@scoped/another', 'c']) - t.ok(npmRegistryFetchLog, 'is passed a logger') t.matchSnapshot(log, 'should log remove info') t.matchSnapshot(result, 'should return success msg') }) diff --git a/deps/npm/test/lib/commands/doctor.js b/deps/npm/test/lib/commands/doctor.js index 51b6111a0a..dee2110ff3 100644 --- a/deps/npm/test/lib/commands/doctor.js +++ b/deps/npm/test/lib/commands/doctor.js @@ -4,6 +4,7 @@ const { join } = require('path') const fs = require('fs') const ansiTrim = require('../../../lib/utils/ansi-trim.js') const isWindows = require('../../../lib/utils/is-windows.js') +const { fake: mockNpm } = require('../../fixtures/mock-npm') // getuid and getgid do not exist in windows, so we shim them // to return 0, as that is the value that lstat will assign the @@ -61,15 +62,18 @@ const clearLogs = () => { } } -const npm = { +const npm = mockNpm({ flatOptions: { registry: 'https://registry.npmjs.org/', }, + config: { + loglevel: 'info', + }, version: '7.1.0', output: data => { output.push(data) }, -} +}) let latestNpm = npm.version const pacote = { @@ -211,7 +215,7 @@ t.test('node versions', t => { npm.globalDir = dir npm.localBin = dir npm.globalBin = dir - mocks.npmlog.level = 'info' + npm.config.set('loglevel', 'silent') st.teardown(() => { delete npm.cache @@ -220,7 +224,7 @@ t.test('node versions', t => { delete npm.globalDir delete npm.localBin delete npm.globalBin - mocks.npmlog.level = 'error' + npm.config.set('loglevel', 'info') clearLogs() }) diff --git a/deps/npm/test/lib/commands/hook.js b/deps/npm/test/lib/commands/hook.js index a4eee711fe..60a59a3fe7 100644 --- a/deps/npm/test/lib/commands/hook.js +++ b/deps/npm/test/lib/commands/hook.js @@ -1,18 +1,20 @@ const t = require('tap') +const { fake: mockNpm } = require('../../fixtures/mock-npm') const output = [] -const npm = { +const npm = mockNpm({ flatOptions: { json: false, parseable: false, - silent: false, - loglevel: 'info', unicode: false, }, + config: { + loglevel: 'info', + }, output: msg => { output.push(msg) }, -} +}) const pkgTypes = { semver: 'package', @@ -78,7 +80,6 @@ t.test('npm hook add', async t => { await hook.exec(['add', 'semver', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -102,7 +103,6 @@ t.test('npm hook add - unicode output', async t => { await hook.exec(['add', 'semver', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -126,7 +126,6 @@ t.test('npm hook add - json output', async t => { await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -159,7 +158,6 @@ t.test('npm hook add - parseable output', async t => { await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -183,16 +181,15 @@ t.test('npm hook add - parseable output', async t => { }) t.test('npm hook add - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') hookArgs = null output.length = 0 }) await hook.exec(['add', '@npmcli', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -214,7 +211,6 @@ t.test('npm hook ls', async t => { await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -240,7 +236,6 @@ t.test('npm hook ls, no results', async t => { await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -270,7 +265,6 @@ t.test('npm hook ls, single result', async t => { await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -294,7 +288,6 @@ t.test('npm hook ls - json output', async t => { await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -340,7 +333,6 @@ t.test('npm hook ls - parseable output', async t => { await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -362,16 +354,15 @@ t.test('npm hook ls - parseable output', async t => { }) t.test('npm hook ls - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') hookArgs = null output.length = 0 }) await hook.exec(['ls']) - t.ok(hookArgs.log, 'is passed a logger') t.match( hookArgs, { @@ -391,7 +382,6 @@ t.test('npm hook rm', async t => { await hook.exec(['rm', '1']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -413,7 +403,6 @@ t.test('npm hook rm - unicode output', async t => { await hook.exec(['rm', '1']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -426,16 +415,15 @@ t.test('npm hook rm - unicode output', async t => { }) t.test('npm hook rm - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') hookArgs = null output.length = 0 }) await hook.exec(['rm', '1']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -457,7 +445,6 @@ t.test('npm hook rm - json output', async t => { await hook.exec(['rm', '1']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -488,7 +475,6 @@ t.test('npm hook rm - parseable output', async t => { await hook.exec(['rm', '1']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -515,7 +501,6 @@ t.test('npm hook update', async t => { await hook.exec(['update', '1', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -539,7 +524,6 @@ t.test('npm hook update - unicode', async t => { await hook.exec(['update', '1', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -563,7 +547,6 @@ t.test('npm hook update - json output', async t => { await hook.exec(['update', '1', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -596,7 +579,6 @@ t.test('npm hook update - parseable output', async t => { await hook.exec(['update', '1', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { @@ -618,16 +600,15 @@ t.test('npm hook update - parseable output', async t => { }) t.test('npm hook update - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') hookArgs = null output.length = 0 }) await hook.exec(['update', '1', 'https://google.com', 'some-secret']) - t.ok(hookArgs.opts.log, 'is passed a logger') t.match( hookArgs, { diff --git a/deps/npm/test/lib/commands/logout.js b/deps/npm/test/lib/commands/logout.js index 1a1fbb785c..73fe8028c7 100644 --- a/deps/npm/test/lib/commands/logout.js +++ b/deps/npm/test/lib/commands/logout.js @@ -31,7 +31,7 @@ t.afterEach(() => { }) t.test('token logout', async t => { - t.plan(6) + t.plan(5) flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/' @@ -62,7 +62,6 @@ t.test('token logout', async t => { await logout.exec([]) - t.ok(result.opts.log, 'should pass a logger') t.match( result, { @@ -92,7 +91,7 @@ t.test('token scoped logout', async t => { config.save = null }) - t.plan(8) + t.plan(7) flatOptions['//diff-registry.npmjs.com/:_authToken'] = '@bar/' flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/' @@ -133,7 +132,6 @@ t.test('token scoped logout', async t => { await logout.exec([]) - t.ok(result.opts.log, 'should pass a logger') t.match( result, { @@ -204,7 +202,7 @@ t.test('ignore invalid scoped registry config', async t => { config.delete = null config.save = null }) - t.plan(5) + t.plan(4) flatOptions['//registry.npmjs.org/:_authToken'] = '@foo/' config.scope = '@myscope' @@ -236,7 +234,6 @@ t.test('ignore invalid scoped registry config', async t => { await logout.exec([]) - t.ok(result.opts.log, 'should pass a logger') t.match( result, { diff --git a/deps/npm/test/lib/commands/org.js b/deps/npm/test/lib/commands/org.js index b716adc097..3ae951dd5c 100644 --- a/deps/npm/test/lib/commands/org.js +++ b/deps/npm/test/lib/commands/org.js @@ -1,18 +1,20 @@ const t = require('tap') const ansiTrim = require('../../../lib/utils/ansi-trim.js') +const { fake: mockNpm } = require('../../fixtures/mock-npm') const output = [] -const npm = { +const npm = mockNpm({ flatOptions: { json: false, parseable: false, - silent: false, + }, + config: { loglevel: 'info', }, output: msg => { output.push(msg) }, -} +}) let orgSize = 1 let orgSetArgs = null @@ -83,7 +85,6 @@ t.test('npm org add', async t => { await org.exec(['add', 'orgname', 'username']) - t.ok(orgSetArgs.opts.log, 'got passed a logger') t.match( orgSetArgs, { @@ -149,7 +150,6 @@ t.test('npm org add - more users', async t => { }) await org.exec(['add', 'orgname', 'username']) - t.ok(orgSetArgs.opts.log, 'got passed a logger') t.match( orgSetArgs, { @@ -177,7 +177,6 @@ t.test('npm org add - json output', async t => { await org.exec(['add', 'orgname', 'username']) - t.ok(orgSetArgs.opts.log, 'got passed a logger') t.match( orgSetArgs, { @@ -212,7 +211,6 @@ t.test('npm org add - parseable output', async t => { await org.exec(['add', 'orgname', 'username']) - t.ok(orgSetArgs.opts.log, 'got passed a logger') t.match( orgSetArgs, { @@ -234,16 +232,15 @@ t.test('npm org add - parseable output', async t => { }) t.test('npm org add - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') orgSetArgs = null output.length = 0 }) await org.exec(['add', 'orgname', 'username']) - t.ok(orgSetArgs.opts.log, 'got passed a logger') t.match( orgSetArgs, { @@ -266,7 +263,6 @@ t.test('npm org rm', async t => { await org.exec(['rm', 'orgname', 'username']) - t.ok(orgRmArgs.opts.log, 'got passed a logger') t.match( orgRmArgs, { @@ -276,7 +272,6 @@ t.test('npm org rm', async t => { }, 'libnpmorg.rm received the correct args' ) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -330,7 +325,6 @@ t.test('npm org rm - one user left', async t => { await org.exec(['rm', 'orgname', 'username']) - t.ok(orgRmArgs.opts.log, 'got passed a logger') t.match( orgRmArgs, { @@ -340,7 +334,6 @@ t.test('npm org rm - one user left', async t => { }, 'libnpmorg.rm received the correct args' ) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -367,7 +360,6 @@ t.test('npm org rm - json output', async t => { await org.exec(['rm', 'orgname', 'username']) - t.ok(orgRmArgs.opts.log, 'got passed a logger') t.match( orgRmArgs, { @@ -377,7 +369,6 @@ t.test('npm org rm - json output', async t => { }, 'libnpmorg.rm received the correct args' ) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -409,7 +400,6 @@ t.test('npm org rm - parseable output', async t => { await org.exec(['rm', 'orgname', 'username']) - t.ok(orgRmArgs.opts.log, 'got passed a logger') t.match( orgRmArgs, { @@ -419,7 +409,6 @@ t.test('npm org rm - parseable output', async t => { }, 'libnpmorg.rm received the correct args' ) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -439,9 +428,9 @@ t.test('npm org rm - parseable output', async t => { }) t.test('npm org rm - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') orgRmArgs = null orgLsArgs = null output.length = 0 @@ -449,7 +438,6 @@ t.test('npm org rm - silent output', async t => { await org.exec(['rm', 'orgname', 'username']) - t.ok(orgRmArgs.opts.log, 'got passed a logger') t.match( orgRmArgs, { @@ -459,7 +447,6 @@ t.test('npm org rm - silent output', async t => { }, 'libnpmorg.rm received the correct args' ) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -485,7 +472,6 @@ t.test('npm org ls', async t => { await org.exec(['ls', 'orgname']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -513,7 +499,6 @@ t.test('npm org ls - user filter', async t => { await org.exec(['ls', 'orgname', 'username']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -539,7 +524,6 @@ t.test('npm org ls - user filter, missing user', async t => { await org.exec(['ls', 'orgname', 'username']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -578,7 +562,6 @@ t.test('npm org ls - json output', async t => { await org.exec(['ls', 'orgname']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -606,7 +589,6 @@ t.test('npm org ls - parseable output', async t => { await org.exec(['ls', 'orgname']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { @@ -628,14 +610,14 @@ t.test('npm org ls - parseable output', async t => { }) t.test('npm org ls - silent output', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') orgList = { one: 'developer', two: 'admin', three: 'owner', } t.teardown(() => { - npm.flatOptions.silent = false + npm.config.set('loglevel', 'info') orgList = {} orgLsArgs = null output.length = 0 @@ -643,7 +625,6 @@ t.test('npm org ls - silent output', async t => { await org.exec(['ls', 'orgname']) - t.ok(orgLsArgs.opts.log, 'got passed a logger') t.match( orgLsArgs, { diff --git a/deps/npm/test/lib/commands/owner.js b/deps/npm/test/lib/commands/owner.js index a32a3df9b7..b5d4d15842 100644 --- a/deps/npm/test/lib/commands/owner.js +++ b/deps/npm/test/lib/commands/owner.js @@ -51,14 +51,13 @@ t.test('owner no args', async t => { }) t.test('owner ls no args', async t => { - t.plan(5) + t.plan(4) result = '' readPackageNameResponse = '@npmcli/map-workspaces' pacote.packument = async (spec, opts) => { t.equal(spec.name, '@npmcli/map-workspaces', 'should use expect pkg name') - t.ok(opts.log, 'is passed a logger') t.match( opts, { @@ -173,11 +172,10 @@ t.test('owner ls <pkg> no maintainers', async t => { }) t.test('owner add <user> <pkg>', async t => { - t.plan(11) + t.plan(8) result = '' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { t.ok('should request user info') @@ -218,7 +216,6 @@ t.test('owner add <user> <pkg>', async t => { } } pacote.packument = async (spec, opts) => { - t.ok(opts.log, 'is passed a logger') t.equal(spec.name, '@npmcli/map-workspaces', 'should use expect pkg name') t.match( opts, @@ -247,7 +244,6 @@ t.test('owner add <user> cwd package', async t => { result = '' readPackageNameResponse = '@npmcli/map-workspaces' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { return { @@ -277,7 +273,7 @@ t.test('owner add <user> cwd package', async t => { }) t.test('owner add <user> <pkg> already an owner', async t => { - t.plan(3) + t.plan(2) result = '' log.info = (title, msg) => { @@ -289,7 +285,6 @@ t.test('owner add <user> <pkg> already an owner', async t => { ) } npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:ruyadorno') { return { @@ -321,7 +316,6 @@ t.test('owner add <user> <pkg> fails to retrieve user', async t => { result = '' readPackageNameResponse = npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve borked user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { return { ok: false } @@ -352,7 +346,6 @@ t.test('owner add <user> <pkg> fails to retrieve user', async t => { t.test('owner add <user> <pkg> fails to PUT updates', async t => { result = '' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { return { @@ -389,7 +382,7 @@ t.test('owner add <user> <pkg> fails to PUT updates', async t => { }) t.test('owner add <user> <pkg> fails to retrieve user info', async t => { - t.plan(4) + t.plan(3) result = '' log.error = (title, msg) => { @@ -397,7 +390,6 @@ t.test('owner add <user> <pkg> fails to retrieve user info', async t => { t.equal(msg, 'Error getting user data for foo') } npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { throw Object.assign( @@ -429,7 +421,6 @@ t.test('owner add <user> <pkg> fails to retrieve user info', async t => { t.test('owner add <user> <pkg> no previous maintainers property from server', async t => { result = '' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { return { @@ -496,11 +487,10 @@ t.test('owner add <user> no cwd package', async t => { }) t.test('owner rm <user> <pkg>', async t => { - t.plan(11) + t.plan(8) result = '' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:ruyadorno') { t.ok('should request user info') @@ -534,7 +524,6 @@ t.test('owner rm <user> <pkg>', async t => { } } pacote.packument = async (spec, opts) => { - t.ok(opts.log, 'is passed a logger') t.equal(spec.name, '@npmcli/map-workspaces', 'should use expect pkg name') t.match( opts, @@ -560,7 +549,7 @@ t.test('owner rm <user> <pkg>', async t => { }) t.test('owner rm <user> <pkg> not a current owner', async t => { - t.plan(3) + t.plan(2) result = '' log.info = (title, msg) => { @@ -568,7 +557,6 @@ t.test('owner rm <user> <pkg> not a current owner', async t => { t.equal(msg, 'Not a package owner: foo', 'should log.info not a package owner msg') } npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:foo') { return { @@ -602,7 +590,6 @@ t.test('owner rm <user> cwd package', async t => { result = '' readPackageNameResponse = '@npmcli/map-workspaces' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:ruyadorno') { return { @@ -635,7 +622,6 @@ t.test('owner rm <user> only user', async t => { result = '' readPackageNameResponse = 'ipt' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') // retrieve user info from couchdb request if (uri === '/-/user/org.couchdb.user:ruyadorno') { return { diff --git a/deps/npm/test/lib/commands/ping.js b/deps/npm/test/lib/commands/ping.js index 19ba9d586b..f808e0ac3b 100644 --- a/deps/npm/test/lib/commands/ping.js +++ b/deps/npm/test/lib/commands/ping.js @@ -2,13 +2,12 @@ const t = require('tap') const { fake: mockNpm } = require('../../fixtures/mock-npm') t.test('pings', async t => { - t.plan(7) + t.plan(6) const registry = 'https://registry.npmjs.org' let noticeCalls = 0 const Ping = t.mock('../../../lib/commands/ping.js', { '../../../lib/utils/ping.js': function (spec) { - t.ok(spec.log, 'is passed a logger') t.equal(spec.registry, registry, 'passes flatOptions') return {} }, @@ -36,14 +35,13 @@ t.test('pings', async t => { }) t.test('pings and logs details', async t => { - t.plan(9) + t.plan(8) const registry = 'https://registry.npmjs.org' const details = { extra: 'data' } let noticeCalls = 0 const Ping = t.mock('../../../lib/commands/ping.js', { '../../../lib/utils/ping.js': function (spec) { - t.ok(spec.log, 'is passed a logger') t.equal(spec.registry, registry, 'passes flatOptions') return details }, @@ -75,14 +73,13 @@ t.test('pings and logs details', async t => { }) t.test('pings and returns json', async t => { - t.plan(10) + t.plan(9) const registry = 'https://registry.npmjs.org' const details = { extra: 'data' } let noticeCalls = 0 const Ping = t.mock('../../../lib/commands/ping.js', { '../../../lib/utils/ping.js': function (spec) { - t.ok(spec.log, 'is passed a logger') t.equal(spec.registry, registry, 'passes flatOptions') return details }, diff --git a/deps/npm/test/lib/commands/publish.js b/deps/npm/test/lib/commands/publish.js index 52d4c1b342..0a7f961bfb 100644 --- a/deps/npm/test/lib/commands/publish.js +++ b/deps/npm/test/lib/commands/publish.js @@ -1,15 +1,6 @@ const t = require('tap') const { fake: mockNpm } = require('../../fixtures/mock-npm') const fs = require('fs') -const log = require('../../../lib/utils/log-shim') - -// The way we set loglevel is kind of convoluted, and there is no way to affect -// it from these tests, which only interact with lib/publish.js, which assumes -// that the code that is requiring and calling lib/publish.js has already -// taken care of the loglevel -const _level = log.level -t.beforeEach(() => (log.level = 'silent')) -t.teardown(() => (log.level = _level)) t.cleanSnapshot = data => { return data.replace(/^ *"gitHead": .*$\n/gm, '') @@ -25,7 +16,7 @@ t.test( /* eslint-disable-next-line max-len */ 'should publish with libnpmpublish, passing through flatOptions and respecting publishConfig.registry', async t => { - t.plan(7) + t.plan(6) const registry = 'https://some.registry' const publishConfig = { registry } @@ -59,7 +50,6 @@ t.test( t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest') t.type(tarData, Buffer, 'tarData is a buffer') t.ok(opts, 'gets opts object') - t.ok(opts.log, 'gets passed a logger') t.same(opts.customValue, true, 'flatOptions values are passed through') t.same(opts.registry, registry, 'publishConfig.registry is passed through') }, @@ -82,7 +72,7 @@ t.test( ) t.test('re-loads publishConfig.registry if added during script process', async t => { - t.plan(6) + t.plan(5) const registry = 'https://some.registry' const publishConfig = { registry } const testDir = t.testdir({ @@ -113,7 +103,6 @@ t.test('re-loads publishConfig.registry if added during script process', async t t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest') t.type(tarData, Buffer, 'tarData is a buffer') t.ok(opts, 'gets opts object') - t.ok(opts.log, 'gets passed a logger') t.same(opts.registry, registry, 'publishConfig.registry is passed through') }, }, @@ -142,7 +131,6 @@ t.test('if loglevel=info and json, should not output package contents', async t ), }) - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { '../../../lib/utils/tar.js': { getContents: () => ({ @@ -159,11 +147,11 @@ t.test('if loglevel=info and json, should not output package contents', async t }, }) const npm = mockNpm({ - config: { json: true }, + config: { json: true, loglevel: 'info' }, output: () => { t.pass('output is called') }, - }) + }, t) npm.config.getCredentialsByURI = uri => { t.same(uri, npm.config.get('registry'), 'gets credentials for expected registry') return { token: 'some.registry.token' } @@ -206,11 +194,11 @@ t.test( }, }) const npm = mockNpm({ - config: { 'dry-run': true }, + config: { 'dry-run': true, loglevel: 'silent' }, output: () => { throw new Error('should not output in dry run mode') }, - }) + }, t) npm.config.getCredentialsByURI = () => { throw new Error('should not call getCredentialsByURI in dry run') } @@ -238,7 +226,6 @@ t.test( ), }) - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { '../../../lib/utils/tar.js': { getContents: () => ({ @@ -255,11 +242,11 @@ t.test( }, }) const npm = mockNpm({ - config: { 'dry-run': true }, + config: { 'dry-run': true, loglevel: 'info' }, output: () => { t.pass('output fn is called') }, - }) + }, t) npm.config.getCredentialsByURI = () => { throw new Error('should not call getCredentialsByURI in dry run') } @@ -294,7 +281,7 @@ t.test('throws when invalid tag', async t => { }) t.test('can publish a tarball', async t => { - t.plan(4) + t.plan(3) const testDir = t.testdir({ tarball: {}, @@ -319,7 +306,6 @@ t.test('can publish a tarball', async t => { const Publish = t.mock('../../../lib/commands/publish.js', { libnpmpublish: { publish: (manifest, tarData, opts) => { - t.ok(opts.log, 'gets passed a logger') t.match( manifest, { @@ -415,7 +401,7 @@ t.test('should check auth for scope specific registry', async t => { }) t.test('should use auth for scope specific registry', async t => { - t.plan(4) + t.plan(3) const registry = 'https://some.registry' const testDir = t.testdir({ 'package.json': JSON.stringify( @@ -432,7 +418,6 @@ t.test('should use auth for scope specific registry', async t => { libnpmpublish: { publish: (manifest, tarData, opts) => { t.ok(opts, 'gets opts object') - t.ok(opts.log, 'gets passed a logger') t.same(opts['@npm:registry'], registry, 'scope specific registry is passed through') }, }, @@ -450,7 +435,7 @@ t.test('should use auth for scope specific registry', async t => { }) t.test('read registry only from publishConfig', async t => { - t.plan(4) + t.plan(3) const registry = 'https://some.registry' const publishConfig = { registry } @@ -469,7 +454,6 @@ t.test('read registry only from publishConfig', async t => { const Publish = t.mock('../../../lib/commands/publish.js', { libnpmpublish: { publish: (manifest, tarData, opts) => { - t.ok(opts.log, 'gets passed a logger') t.match(manifest, { name: 'my-cool-pkg', version: '1.0.0' }, 'gets manifest') t.same(opts.registry, registry, 'publishConfig is passed through') }, @@ -486,7 +470,7 @@ t.test('read registry only from publishConfig', async t => { }) t.test('able to publish after if encountered multiple configs', async t => { - t.plan(3) + t.plan(2) const registry = 'https://some.registry' const tag = 'better-tag' @@ -515,7 +499,6 @@ t.test('able to publish after if encountered multiple configs', async t => { const Publish = t.mock('../../../lib/commands/publish.js', { libnpmpublish: { publish: (manifest, tarData, opts) => { - t.ok(opts.log, 'gets passed a logger') t.same(opts.defaultTag, tag, 'gets option for expected tag') }, }, @@ -526,6 +509,7 @@ t.test('able to publish after if encountered multiple configs', async t => { defaultTag: 'better-tag', registry: 'https://other.registry', }, + output () {}, config: { get: key => configList[0][key], list: configList, @@ -604,14 +588,12 @@ t.test('workspaces', t => { const publish = new Publish(npm) t.test('all workspaces', async t => { - log.level = 'info' await publish.execWorkspaces([], []) t.matchSnapshot(publishes, 'should publish all workspaces') t.matchSnapshot(outputs, 'should output all publishes') }) t.test('one workspace', async t => { - log.level = 'info' await publish.execWorkspaces([], ['workspace-a']) t.matchSnapshot(publishes, 'should publish given workspace') t.matchSnapshot(outputs, 'should output one publish') @@ -623,7 +605,6 @@ t.test('workspaces', t => { }) t.test('json', async t => { - log.level = 'info' npm.config.set('json', true) await publish.execWorkspaces([], []) t.matchSnapshot(publishes, 'should publish all workspaces') @@ -680,10 +661,11 @@ t.test('private workspaces', async t => { }, } const npm = mockNpm({ + config: { loglevel: 'info' }, output: o => { outputs.push(o) }, - }) + }, t) npm.localPrefix = testDir npm.config.getCredentialsByURI = uri => { return { token: 'some.registry.token' } @@ -692,7 +674,6 @@ t.test('private workspaces', async t => { t.test('with color', async t => { t.plan(4) - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { ...mocks, 'proc-log': { @@ -721,7 +702,6 @@ t.test('private workspaces', async t => { t.test('colorless', async t => { t.plan(4) - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { ...mocks, 'proc-log': { @@ -754,7 +734,6 @@ t.test('private workspaces', async t => { if (manifest.private) { throw new Error('ERR') } - t.ok(opts.log, 'gets passed a logger') publishes.push(manifest) }, }, @@ -794,7 +773,6 @@ t.test('runs correct lifecycle scripts', async t => { }) const scripts = [] - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { '@npmcli/run-script': args => { scripts.push(args) @@ -814,10 +792,11 @@ t.test('runs correct lifecycle scripts', async t => { }, }) const npm = mockNpm({ + config: { loglevel: 'info' }, output: () => { t.pass('output is called') }, - }) + }, t) npm.config.getCredentialsByURI = uri => { t.same(uri, npm.config.get('registry'), 'gets credentials for expected registry') return { token: 'some.registry.token' } @@ -845,7 +824,6 @@ t.test('does not run scripts on --ignore-scripts', async t => { ), }) - log.level = 'info' const Publish = t.mock('../../../lib/commands/publish.js', { '@npmcli/run-script': () => { t.fail('should not call run-script') @@ -865,11 +843,11 @@ t.test('does not run scripts on --ignore-scripts', async t => { }, }) const npm = mockNpm({ - config: { 'ignore-scripts': true }, + config: { 'ignore-scripts': true, loglevel: 'info' }, output: () => { t.pass('output is called') }, - }) + }, t) npm.config.getCredentialsByURI = uri => { t.same(uri, npm.config.get('registry'), 'gets credentials for expected registry') return { token: 'some.registry.token' } diff --git a/deps/npm/test/lib/commands/run-script.js b/deps/npm/test/lib/commands/run-script.js index ea0227cda0..834b61e747 100644 --- a/deps/npm/test/lib/commands/run-script.js +++ b/deps/npm/test/lib/commands/run-script.js @@ -10,10 +10,12 @@ const RUN_SCRIPTS = [] const flatOptions = { scriptShell: undefined, } +const defaultLoglevel = 'info' const config = { json: false, parseable: false, 'if-present': false, + loglevel: defaultLoglevel, } const npm = mockNpm({ @@ -26,20 +28,21 @@ const npm = mockNpm({ output: (...msg) => output.push(msg), }) -const output = [] - -const npmlog = { - disableProgress: () => null, - level: 'warn', +const setLoglevel = (t, level) => { + npm.config.set('loglevel', level) + t.teardown(() => { + npm.config.set('loglevel', defaultLoglevel) + }) } +const output = [] + const log = { error: () => null, } t.afterEach(() => { npm.color = false - npmlog.level = 'warn' log.error = () => null output.length = 0 RUN_SCRIPTS.length = 0 @@ -58,7 +61,6 @@ const getRS = windows => { isServerPackage: require('@npmcli/run-script').isServerPackage, } ), - npmlog, 'proc-log': log, '../../../lib/utils/is-windows-shell.js': windows, }) @@ -359,10 +361,7 @@ t.test('skip pre/post hooks when using ignoreScripts', async t => { }) t.test('run silent', async t => { - npmlog.level = 'silent' - t.teardown(() => { - npmlog.level = 'warn' - }) + setLoglevel(t, 'silent') npm.localPrefix = t.testdir({ 'package.json': JSON.stringify({ @@ -440,12 +439,11 @@ t.test('list scripts', t => { }) t.test('silent', async t => { - npmlog.level = 'silent' + setLoglevel(t, 'silent') await runScript.exec([]) t.strictSame(output, []) }) t.test('warn json', async t => { - npmlog.level = 'warn' config.json = true await runScript.exec([]) t.strictSame(output, [[JSON.stringify(scripts, 0, 2)]], 'json report') @@ -723,7 +721,7 @@ t.test('workspaces', t => { }) t.test('list no scripts --loglevel=silent', async t => { - npmlog.level = 'silent' + setLoglevel(t, 'silent') await runScript.execWorkspaces([], []) t.strictSame(output, []) }) @@ -860,7 +858,6 @@ t.test('workspaces', t => { '@npmcli/run-script': () => { throw new Error('err') }, - npmlog, 'proc-log': log, '../../../lib/utils/is-windows-shell.js': false, }) @@ -879,7 +876,6 @@ t.test('workspaces', t => { RUN_SCRIPTS.push(opts) }, - npmlog, 'proc-log': log, '../../../lib/utils/is-windows-shell.js': false, }) diff --git a/deps/npm/test/lib/commands/star.js b/deps/npm/test/lib/commands/star.js index 2f4ddc9dc6..4d19b32e1d 100644 --- a/deps/npm/test/lib/commands/star.js +++ b/deps/npm/test/lib/commands/star.js @@ -42,10 +42,9 @@ t.test('no args', async t => { }) t.test('star a package', async t => { - t.plan(6) + t.plan(4) const pkgName = '@npmcli/arborist' npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') return { _id: pkgName, _rev: 'hash', @@ -70,11 +69,10 @@ t.test('star a package', async t => { }) t.test('unstar a package', async t => { - t.plan(6) + t.plan(4) const pkgName = '@npmcli/arborist' config['star.unstar'] = true npmFetch.json = async (uri, opts) => { - t.ok(opts.log, 'is passed a logger') return { _id: pkgName, _rev: 'hash', diff --git a/deps/npm/test/lib/commands/team.js b/deps/npm/test/lib/commands/team.js index 96260835fa..0d5378b530 100644 --- a/deps/npm/test/lib/commands/team.js +++ b/deps/npm/test/lib/commands/team.js @@ -1,4 +1,5 @@ const t = require('tap') +const { fake: mockNpm } = require('../../fixtures/mock-npm') let result = '' const libnpmteam = { @@ -9,12 +10,15 @@ const libnpmteam = { async lsUsers () {}, async rm () {}, } -const npm = { +const npm = mockNpm({ flatOptions: {}, + config: { + loglevel: 'info', + }, output: (...msg) => { result += msg.join('\n') }, -} +}) const mocks = { libnpmteam, 'cli-columns': a => a.join(' '), @@ -25,6 +29,7 @@ const mocks = { t.afterEach(() => { result = '' npm.flatOptions = {} + npm.config.set('loglevel', 'info') }) const Team = t.mock('../../../lib/commands/team.js', mocks) @@ -73,7 +78,7 @@ t.test('team add <scope:team> <user>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['add', '@npmcli:developers', 'foo']) @@ -115,7 +120,7 @@ t.test('team create <scope:team>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['create', '@npmcli:newteam']) @@ -149,7 +154,7 @@ t.test('team destroy <scope:team>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['destroy', '@npmcli:newteam']) t.same(result, '', 'should not output destroy if silent') }) @@ -198,7 +203,7 @@ t.test('team ls <scope>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['ls', '@npmcli']) t.same(result, '', 'should not list teams if silent') }) @@ -278,7 +283,7 @@ t.test('team ls <scope:team>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['ls', '@npmcli:developers']) t.same(result, '', 'should not output users if silent') }) @@ -345,7 +350,7 @@ t.test('team rm <scope:team> <user>', async t => { }) t.test('--silent', async t => { - npm.flatOptions.silent = true + npm.config.set('loglevel', 'silent') await team.exec(['rm', '@npmcli:newteam', 'foo']) t.same(result, '', 'should not output rm result if silent') }) diff --git a/deps/npm/test/lib/commands/unpublish.js b/deps/npm/test/lib/commands/unpublish.js index 99d55294fb..b9c94e5d52 100644 --- a/deps/npm/test/lib/commands/unpublish.js +++ b/deps/npm/test/lib/commands/unpublish.js @@ -22,7 +22,6 @@ const singleVersion = async () => { const config = { force: false, - loglevel: 'silly', } const testDir = t.testdir({ @@ -54,7 +53,7 @@ t.afterEach(() => { result = '' config['dry-run'] = false config.force = false - config.loglevel = 'silly' + npm.config.set('loglevel', 'info') }) t.test('no args --force', async t => { @@ -76,7 +75,6 @@ t.test('no args --force', async t => { const libnpmpublish = { unpublish (spec, opts) { - t.ok(opts.log, 'gets passed a logger') t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected spec') t.match( opts, @@ -178,7 +176,6 @@ t.test('unpublish <pkg>@version', async t => { const libnpmpublish = { unpublish (spec, opts) { - t.ok(opts.log, 'gets passed a logger') t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected parsed spec') }, } @@ -240,7 +237,7 @@ t.test('unpublish <pkg> --force no version set', async t => { }) t.test('silent', async t => { - config.loglevel = 'silent' + npm.config.set('loglevel', 'silent') const Unpublish = t.mock('../../../lib/commands/unpublish.js', { ...mocks, diff --git a/deps/npm/test/lib/commands/update.js b/deps/npm/test/lib/commands/update.js index 2b464bfabb..ae93764661 100644 --- a/deps/npm/test/lib/commands/update.js +++ b/deps/npm/test/lib/commands/update.js @@ -27,7 +27,7 @@ t.afterEach(() => { }) t.test('no args', async t => { - t.plan(5) + t.plan(4) npm.prefix = '/project/a' @@ -44,7 +44,6 @@ t.test('no args', async t => { }, 'should call arborist contructor with expected args' ) - t.match(log, {}, 'log is passed in') } reify ({ save, update }) { @@ -66,7 +65,7 @@ t.test('no args', async t => { }) t.test('with args', async t => { - t.plan(5) + t.plan(4) npm.prefix = '/project/a' config.save = true @@ -84,7 +83,6 @@ t.test('with args', async t => { }, 'should call arborist contructor with expected args' ) - t.match(log, {}, 'log is passed in') } reify ({ save, update }) { @@ -130,7 +128,7 @@ t.test('update --depth=<number>', async t => { }) t.test('update --global', async t => { - t.plan(3) + t.plan(2) const normalizePath = p => p.replace(/\\+/g, '/') const redactCwd = (path) => normalizePath(path) @@ -149,8 +147,6 @@ t.test('update --global', async t => { 'should call arborist contructor with expected options' ) - t.match(log, {}, 'log is passed in') - t.equal( redactCwd(path), '{CWD}/global/lib', |