2021-04-01 17:27:18 -04:00
|
|
|
// Our coverage mapping means that stuff like this doen't count for coverage.
|
|
|
|
// It does ensure that every command has a usage that renders, contains its
|
|
|
|
// name, a description, and if it has completion it is a function. That it
|
|
|
|
// renders also ensures that any params we've defined in our commands work.
|
2020-10-02 17:52:19 -04:00
|
|
|
const t = require('tap')
|
2021-11-04 20:42:47 +00:00
|
|
|
const util = require('util')
|
2021-06-24 21:39:48 +00:00
|
|
|
const { real: mockNpm } = require('../fixtures/mock-npm.js')
|
2020-10-02 17:52:19 -04:00
|
|
|
const { cmdList } = require('../../lib/utils/cmd-list.js')
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const { Npm, outputs } = mockNpm(t)
|
|
|
|
const npm = new Npm()
|
2021-06-24 21:39:48 +00:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('load each command', async t => {
|
|
|
|
t.afterEach(() => {
|
|
|
|
outputs.length = 0
|
2021-03-23 14:58:11 -04:00
|
|
|
})
|
2021-11-04 20:42:47 +00:00
|
|
|
t.plan(cmdList.length)
|
|
|
|
await npm.load()
|
|
|
|
npm.config.set('usage', true) // This makes npm.exec output the usage
|
|
|
|
for (const cmd of cmdList.sort((a, b) => a.localeCompare(b, 'en'))) {
|
|
|
|
t.test(cmd, async t => {
|
|
|
|
const impl = await npm.cmd(cmd)
|
2021-11-18 20:58:02 +00:00
|
|
|
if (impl.completion) {
|
2021-11-04 20:42:47 +00:00
|
|
|
t.type(impl.completion, 'function', 'completion, if present, is a function')
|
2021-11-18 20:58:02 +00:00
|
|
|
}
|
2021-11-04 20:42:47 +00:00
|
|
|
t.type(impl.exec, 'function', 'implementation has an exec function')
|
|
|
|
t.type(impl.execWorkspaces, 'function', 'implementation has an execWorkspaces function')
|
|
|
|
t.equal(util.inspect(impl.exec), '[AsyncFunction: exec]', 'exec function is async')
|
2021-11-18 20:58:02 +00:00
|
|
|
t.equal(
|
|
|
|
util.inspect(impl.execWorkspaces),
|
|
|
|
'[AsyncFunction: execWorkspaces]',
|
|
|
|
'execWorkspaces function is async'
|
|
|
|
)
|
2021-11-04 20:42:47 +00:00
|
|
|
t.ok(impl.description, 'implementation has a description')
|
|
|
|
t.ok(impl.name, 'implementation has a name')
|
|
|
|
t.match(impl.usage, cmd, 'usage contains the command')
|
|
|
|
await npm.exec(cmd, [])
|
|
|
|
t.match(outputs[0][0], impl.usage, 'usage is what is output')
|
|
|
|
// This ties usage to a snapshot so we have to re-run snap if usage
|
|
|
|
// changes, which rebuilds the man pages
|
|
|
|
t.matchSnapshot(outputs[0][0])
|
|
|
|
})
|
|
|
|
}
|
2020-10-02 17:52:19 -04:00
|
|
|
})
|