Jeff Williams 0fa28300b2 refactor: reorganize @jsdoc/core
Also creates a new package, `@jsdoc/cli`.

BREAKING CHANGE: Methods in `@jsdoc/core` moved around.
2019-12-08 18:30:58 -08:00

37 lines
969 B
JavaScript

const flags = require('../../../lib/flags');
const ow = require('ow');
function validate(name, opts) {
name = `--${name}`;
if (!opts.description) {
throw new TypeError(`${name} is missing its description.`);
}
if (opts.array && opts.boolean) {
throw new TypeError(`${name} can be an array or a boolean, but not both.`);
}
try {
ow(opts.coerce, ow.optional.function);
} catch (e) {
throw new TypeError(`The coerce value for ${name} is not a function.`);
}
if (opts.choices && !opts.requiresArg) {
throw new TypeError(`${name} specifies choices, but not requiresArg.`);
}
}
describe('@jsdoc/cli/lib/flags', () => {
it('is an object', () => {
expect(flags).toBeObject();
});
it('has reasonable settings for each flag', () => {
for (let flag of Object.keys(flags)) {
expect(() => validate(flag, flags[flag])).not.toThrow();
}
});
});