diff options
author | Gar <gar+gh@danger.computer> | 2022-03-24 23:23:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 23:23:02 +0300 |
commit | 716a07fde7905bb69e4c6f1991bb7289589a6669 (patch) | |
tree | a415c2acb0c4a08cc4338dcf17a0cdc6fda18680 /test | |
parent | 6dd1139c9f302ac71f47a75e70bbe9cdf2e64960 (diff) |
fix: 100% coverage in tests (#4607)
* fix: 100% coverage in tests
* Removed dead code in `lib/utils/usage.js`.
* Removed dead code in `lib/base-command.js`.
* Removed "load-all" test, we currently have 100% coverage and new PRs
without tests will be rejected if they don't add coverage for new
files.
* Removed `check-coverage` script as a separate command.
* Removed separate coverage test in ci.yml.
* Removed `coverage` flag from tap config, the default is already to
enforce 100% coverage.
Removed a tiny bit of dead code resulting from this
* fix: clean up usage output
Removed usage lib, rolled logic into base-command.js
Cleaned up usage output to be less redundant
Diffstat (limited to 'test')
-rw-r--r-- | test/coverage-map.js | 27 | ||||
-rw-r--r-- | test/lib/commands/access.js | 16 | ||||
-rw-r--r-- | test/lib/commands/cache.js | 2 | ||||
-rw-r--r-- | test/lib/commands/diff.js | 1 | ||||
-rw-r--r-- | test/lib/commands/init.js | 1 | ||||
-rw-r--r-- | test/lib/commands/owner.js | 1 | ||||
-rw-r--r-- | test/lib/commands/profile.js | 1 | ||||
-rw-r--r-- | test/lib/commands/search.js | 1 | ||||
-rw-r--r-- | test/lib/commands/star.js | 5 | ||||
-rw-r--r-- | test/lib/commands/stars.js | 1 | ||||
-rw-r--r-- | test/lib/commands/team.js | 1 | ||||
-rw-r--r-- | test/lib/commands/unpublish.js | 8 | ||||
-rw-r--r-- | test/lib/commands/update.js | 1 | ||||
-rw-r--r-- | test/lib/load-all.js | 31 |
14 files changed, 31 insertions, 66 deletions
diff --git a/test/coverage-map.js b/test/coverage-map.js index b29fcd861..0ea909818 100644 --- a/test/coverage-map.js +++ b/test/coverage-map.js @@ -1,17 +1,22 @@ -const full = process.env.npm_lifecycle_event === 'check-coverage' const coverageMap = (filename) => { - if (full && /load-all.js$/.test(filename)) { - const glob = require('glob') - const { resolve, relative } = require('path') - const dir = resolve(__dirname, '../lib') - return glob.sync(`${dir}/**/*.js`) - .map(f => relative(process.cwd(), f)) + const { basename } = require('path') + const testbase = basename(filename) + if (filename === 'test/index.js') { + return ['index.js'] } - if (/windows-shims\.js$/.test(filename)) { - // this one doesn't provide any coverage nyc can track - return [] + 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\/|bin\/|index\.js$)/.test(filename)) { + if (/^test\/lib\/commands/.test(filename) || filename === 'test/lib/npm.js') { + return [ + filename.replace(/^test\//, ''), + 'lib/base-command.js', + 'lib/exec/get-workspace-location-msg.js', + ] + } + if (/^test\/(lib|bin)\//.test(filename)) { return filename.replace(/^test\//, '') } return [] diff --git a/test/lib/commands/access.js b/test/lib/commands/access.js index 81e29146b..f89b53e96 100644 --- a/test/lib/commands/access.js +++ b/test/lib/commands/access.js @@ -45,7 +45,7 @@ t.test('unrecognized subcommand', async t => { const { npm } = await loadMockNpm(t) await t.rejects( npm.exec('access', ['blerg']), - /Usage: blerg is not a recognized subcommand/, + /blerg is not a recognized subcommand/, 'should throw EUSAGE on missing subcommand' ) }) @@ -69,7 +69,7 @@ t.test('access public on unscoped package', async t => { }) await t.rejects( npm.exec('access', ['public']), - /Usage: This command is only available for scoped packages/, + /This command is only available for scoped packages/, 'should throw scoped-restricted error' ) }) @@ -131,7 +131,7 @@ t.test('access restricted on unscoped package', async t => { }) await t.rejects( npm.exec('access', ['public']), - /Usage: This command is only available for scoped packages/, + /This command is only available for scoped packages/, 'should throw scoped-restricted error' ) }) @@ -262,7 +262,7 @@ t.test('access grant others', async t => { 'myorg:myteam', '@scoped/another', ]), - /Usage: First argument must be either `read-only` or `read-write`./, + /First argument must be either `read-only` or `read-write`./, 'should throw unrecognized argument error' ) }) @@ -276,7 +276,7 @@ t.test('access grant missing team args', async t => { undefined, '@scoped/another', ]), - /Usage: `<scope:team>` argument is required./, + /`<scope:team>` argument is required./, 'should throw missing argument error' ) }) @@ -290,7 +290,7 @@ t.test('access grant malformed team arg', async t => { 'foo', '@scoped/another', ]), - /Usage: Second argument used incorrect format.\n/, + /Second argument used incorrect format.\n/, 'should throw malformed arg error' ) }) @@ -343,7 +343,7 @@ t.test('access revoke missing team args', async t => { undefined, '@scoped/another', ]), - /Usage: `<scope:team>` argument is required./, + /`<scope:team>` argument is required./, 'should throw missing argument error' ) }) @@ -356,7 +356,7 @@ t.test('access revoke malformed team arg', async t => { 'foo', '@scoped/another', ]), - /Usage: First argument used incorrect format.\n/, + /First argument used incorrect format.\n/, 'should throw malformed arg error' ) }) diff --git a/test/lib/commands/cache.js b/test/lib/commands/cache.js index fc92facff..602312769 100644 --- a/test/lib/commands/cache.js +++ b/test/lib/commands/cache.js @@ -196,7 +196,7 @@ t.test('cache add no arg', async t => { cache.exec(['add']), { code: 'EUSAGE', - message: 'Usage: First argument to `add` is required', + message: 'First argument to `add` is required', }, 'throws usage error' ) diff --git a/test/lib/commands/diff.js b/test/lib/commands/diff.js index ed0702e37..c2b1a935d 100644 --- a/test/lib/commands/diff.js +++ b/test/lib/commands/diff.js @@ -34,7 +34,6 @@ const mocks = { 'proc-log': { info: noop, verbose: noop }, libnpmdiff: (...args) => libnpmdiff(...args), 'npm-registry-fetch': async () => ({}), - '../../../lib/utils/usage.js': () => 'usage instructions', } t.afterEach(() => { diff --git a/test/lib/commands/init.js b/test/lib/commands/init.js index 215ebc581..82e7e0524 100644 --- a/test/lib/commands/init.js +++ b/test/lib/commands/init.js @@ -17,7 +17,6 @@ const npm = mockNpm({ config, }) const mocks = { - '../../../lib/utils/usage.js': () => 'usage instructions', npmlog: { disableProgress: () => null, enableProgress: () => null, diff --git a/test/lib/commands/owner.js b/test/lib/commands/owner.js index b5d4d1584..83f4d880f 100644 --- a/test/lib/commands/owner.js +++ b/test/lib/commands/owner.js @@ -26,7 +26,6 @@ const mocks = { readPackageNamePrefix = prefix return readPackageNameResponse }, - '../../../lib/utils/usage.js': () => 'usage instructions', } const npmcliMaintainers = [ diff --git a/test/lib/commands/profile.js b/test/lib/commands/profile.js index 3d55a37dd..82ac49542 100644 --- a/test/lib/commands/profile.js +++ b/test/lib/commands/profile.js @@ -45,7 +45,6 @@ const mocks = { withPromise: async a => a, }, '../../../lib/utils/otplease.js': async (opts, fn) => fn(opts), - '../../../lib/utils/usage.js': () => 'usage instructions', '../../../lib/utils/read-user-info.js': { async password () {}, async otp () {}, diff --git a/test/lib/commands/search.js b/test/lib/commands/search.js index c8dbc1b3b..d2462b1ae 100644 --- a/test/lib/commands/search.js +++ b/test/lib/commands/search.js @@ -33,7 +33,6 @@ const libnpmsearch = { const mocks = { npmlog, libnpmsearch, - '../../../lib/utils/usage.js': () => 'usage instructions', } t.afterEach(() => { diff --git a/test/lib/commands/star.js b/test/lib/commands/star.js index 4d19b32e1..5b79c0776 100644 --- a/test/lib/commands/star.js +++ b/test/lib/commands/star.js @@ -20,7 +20,6 @@ const mocks = { 'proc-log': log, 'npm-registry-fetch': npmFetch, '../../../lib/utils/get-identity.js': async () => 'foo', - '../../../lib/utils/usage.js': () => 'usage instructions', } const Star = t.mock('../../../lib/commands/star.js', mocks) @@ -36,8 +35,8 @@ t.afterEach(() => { t.test('no args', async t => { await t.rejects( star.exec([]), - /usage instructions/, - 'should throw usage instructions' + { code: 'EUSAGE' }, + 'should throw usage error' ) }) diff --git a/test/lib/commands/stars.js b/test/lib/commands/stars.js index 959739653..094b530d8 100644 --- a/test/lib/commands/stars.js +++ b/test/lib/commands/stars.js @@ -16,7 +16,6 @@ const mocks = { 'proc-log': log, 'npm-registry-fetch': npmFetch, '../../../lib/utils/get-identity.js': async () => 'foo', - '../../../lib/utils/usage.js': () => 'usage instructions', } const Stars = t.mock('../../../lib/commands/stars.js', mocks) diff --git a/test/lib/commands/team.js b/test/lib/commands/team.js index 0d5378b53..592dbc3a0 100644 --- a/test/lib/commands/team.js +++ b/test/lib/commands/team.js @@ -23,7 +23,6 @@ const mocks = { libnpmteam, 'cli-columns': a => a.join(' '), '../../../lib/utils/otplease.js': async (opts, fn) => fn(opts), - '../../../lib/utils/usage.js': () => 'usage instructions', } t.afterEach(() => { diff --git a/test/lib/commands/unpublish.js b/test/lib/commands/unpublish.js index ce6ce82f6..71be4a5d6 100644 --- a/test/lib/commands/unpublish.js +++ b/test/lib/commands/unpublish.js @@ -68,7 +68,7 @@ t.test('no args --force missing package.json', async t => { await t.rejects( npm.exec('unpublish', []), - /Usage: npm unpublish/, + { code: 'EUSAGE' }, 'should throw usage instructions on missing package.json' ) }) @@ -95,7 +95,7 @@ t.test('no args entire project', async t => { await t.rejects( npm.exec('unpublish', []), - /Usage: Refusing to delete entire project/ + /Refusing to delete entire project/ ) }) @@ -104,7 +104,7 @@ t.test('too many args', async t => { await t.rejects( npm.exec('unpublish', ['a', 'b']), - /Usage: npm unpublish/, + { code: 'EUSAGE' }, 'should throw usage instructions if too many args' ) }) @@ -248,7 +248,7 @@ t.test('workspaces', async t => { }) await t.rejects( npm.exec('unpublish', []), - /Usage: Refusing to delete entire project/ + /Refusing to delete entire project/ ) }) diff --git a/test/lib/commands/update.js b/test/lib/commands/update.js index ae9376466..fe52554c9 100644 --- a/test/lib/commands/update.js +++ b/test/lib/commands/update.js @@ -17,7 +17,6 @@ const mocks = { reify () {} }, '../../../lib/utils/reify-finish.js': noop, - '../../../lib/utils/usage.js': () => 'usage instructions', } t.afterEach(() => { diff --git a/test/lib/load-all.js b/test/lib/load-all.js deleted file mode 100644 index e5d7b558c..000000000 --- a/test/lib/load-all.js +++ /dev/null @@ -1,31 +0,0 @@ -const t = require('tap') -const glob = require('glob') -const { resolve } = require('path') -const { load: loadMockNpm } = require('../fixtures/mock-npm') - -const full = process.env.npm_lifecycle_event === 'check-coverage' - -if (!full) { - t.pass('nothing to do here, not checking for full coverage') -} else { - t.test('load all', async (t) => { - const { npm } = await loadMockNpm(t, { }) - - t.teardown(() => { - const exitHandler = require('../../lib/utils/exit-handler.js') - exitHandler.setNpm(npm) - exitHandler() - }) - - t.test('load all the files', t => { - // just load all the files so we measure coverage for the missing tests - const dir = resolve(__dirname, '../../lib') - for (const f of glob.sync(`${dir}/**/*.js`)) { - require(f) - t.pass('loaded ' + f) - } - t.pass('loaded all files') - t.end() - }) - }) -} |