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 /lib | |
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 'lib')
-rw-r--r-- | lib/base-command.js | 48 | ||||
-rw-r--r-- | lib/utils/usage.js | 32 |
2 files changed, 32 insertions, 48 deletions
diff --git a/lib/base-command.js b/lib/base-command.js index b6e3d6d23..3ab800adb 100644 --- a/lib/base-command.js +++ b/lib/base-command.js @@ -2,10 +2,11 @@ const { relative } = require('path') -const usageUtil = require('./utils/usage.js') const ConfigDefinitions = require('./utils/config/definitions.js') const getWorkspaces = require('./workspaces/get-workspaces.js') +const cmdAliases = require('./utils/cmd-list').aliases + class BaseCommand { constructor (npm) { this.wrapWidth = 80 @@ -25,28 +26,43 @@ class BaseCommand { } get usage () { - let usage = `npm ${this.constructor.name}\n\n` - if (this.constructor.description) { - usage = `${usage}${this.constructor.description}\n\n` - } + const usage = [ + `${this.constructor.description}`, + '', + 'Usage:', + ] - usage = `${usage}Usage:\n` if (!this.constructor.usage) { - usage = `${usage}npm ${this.constructor.name}` + usage.push(`npm ${this.constructor.name}`) } else { - usage = `${usage}${this.constructor.usage - .map(u => `npm ${this.constructor.name} ${u}`) - .join('\n')}` + usage.push(...this.constructor.usage.map(u => `npm ${this.constructor.name} ${u}`)) } if (this.constructor.params) { - usage = `${usage}\n\nOptions:\n${this.wrappedParams}` + usage.push('') + usage.push('Options:') + usage.push(this.wrappedParams) + } + + const aliases = Object.keys(cmdAliases).reduce((p, c) => { + if (cmdAliases[c] === this.constructor.name) { + p.push(c) + } + return p + }, []) + + if (aliases.length === 1) { + usage.push('') + usage.push(`alias: ${aliases.join(', ')}`) + } else if (aliases.length > 1) { + usage.push('') + usage.push(`aliases: ${aliases.join(', ')}`) } - // Mostly this just appends aliases, this could be more clear - usage = usageUtil(this.constructor.name, usage) - usage = `${usage}\n\nRun "npm help ${this.constructor.name}" for more info` - return usage + usage.push('') + usage.push(`Run "npm help ${this.constructor.name}" for more info`) + + return usage.join('\n') } get wrappedParams () { @@ -69,7 +85,7 @@ class BaseCommand { if (prefix) { prefix += '\n\n' } - return Object.assign(new Error(`\nUsage: ${prefix}${this.usage}`), { + return Object.assign(new Error(`\n${prefix}${this.usage}`), { code: 'EUSAGE', }) } diff --git a/lib/utils/usage.js b/lib/utils/usage.js deleted file mode 100644 index 39eaa45e4..000000000 --- a/lib/utils/usage.js +++ /dev/null @@ -1,32 +0,0 @@ -const aliases = require('./cmd-list').aliases - -module.exports = function usage (cmd, txt, opt) { - const post = Object.keys(aliases).reduce(function (p, c) { - var val = aliases[c] - if (val !== cmd) { - return p - } - return p.concat(c) - }, []) - - if (opt || post.length > 0) { - txt += '\n\n' - } - - if (post.length === 1) { - txt += 'alias: ' - txt += post.join(', ') - } else if (post.length > 1) { - txt += 'aliases: ' - txt += post.join(', ') - } - - if (opt) { - if (post.length > 0) { - txt += '\n' - } - txt += 'common options: ' + opt - } - - return txt -} |