imports.test.cjs
This file
Path
tests/imports.test.cjs
133 lines · 3.0 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134const { program, Command, Option, Argument, Help, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, createCommand, createOption, createArgument,} = require('../index.js');const commander = require('../index.js');const { describe, test } = require('node:test');const assert = require('node:assert/strict');
// Do some testing of the default export(s).// Same tests in imports.test.mjs.
function checkClass(obj, name) { assert.equal(typeof obj, 'object'); assert.equal(obj.constructor.name, name);}
describe('named imports from .cjs', () => { test('program', () => { checkClass(program, 'Command'); });
test('Command', () => { checkClass(new Command('name'), 'Command'); });
test('Option', () => { checkClass(new Option('-e, --example', 'description'), 'Option'); });
test('Argument', () => { checkClass(new Argument('<foo>', 'description'), 'Argument'); });
test('Help', () => { checkClass(new Help(), 'Help'); });
test('CommanderError', () => { checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError'); });
test('InvalidArgumentError', () => { checkClass(new InvalidArgumentError('failed'), 'InvalidArgumentError'); });
test('InvalidOptionArgumentError', () => { // Deprecated checkClass( new InvalidOptionArgumentError('failed'), 'InvalidArgumentError', ); });
test('createCommand', () => { checkClass(createCommand('foo'), 'Command'); });
test('createOption', () => { checkClass(createOption('-e, --example', 'description'), 'Option'); });
test('createArgument', () => { checkClass(createArgument('<foo>', 'description'), 'Argument'); });});
describe('unnamed imports from .cjs', () => { test('program', () => { checkClass(commander.program, 'Command'); });
test('Command', () => { checkClass(new commander.Command('name'), 'Command'); });
test('Option', () => { checkClass(new commander.Option('-e, --example', 'description'), 'Option'); });
test('Argument', () => { checkClass(new commander.Argument('<foo>', 'description'), 'Argument'); });
test('Help', () => { checkClass(new commander.Help(), 'Help'); });
test('CommanderError', () => { checkClass( new commander.CommanderError(1, 'code', 'failed'), 'CommanderError', ); });
test('InvalidArgumentError', () => { checkClass( new commander.InvalidArgumentError('failed'), 'InvalidArgumentError', ); });
test('InvalidOptionArgumentError', () => { // Deprecated checkClass( new commander.InvalidOptionArgumentError('failed'), 'InvalidArgumentError', ); });
test('createCommand', () => { checkClass(commander.createCommand('foo'), 'Command'); });
test('createOption', () => { checkClass( commander.createOption('-e, --example', 'description'), 'Option', ); });
test('createArgument', () => { checkClass(commander.createArgument('<foo>', 'description'), 'Argument'); });});