-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove default export of global program (#2017)
- Loading branch information
1 parent
f570b08
commit c876dee
Showing
8 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,67 @@ | ||
const commander = require('../'); | ||
const { | ||
program, | ||
Command, | ||
Option, | ||
Argument, | ||
Help, | ||
CommanderError, | ||
InvalidArgumentError, | ||
InvalidOptionArgumentError, | ||
createCommand, | ||
createOption, | ||
createArgument | ||
} = require('../index.js'); | ||
|
||
// Do some testing of the default export(s). | ||
// Similar tests to ts-imports.test.ts and esm-imports-test.js. | ||
|
||
test('when require commander then is a Command (default export of global)', () => { | ||
// Deprecated global command | ||
const program = commander; | ||
expect(program.constructor.name).toBe('Command'); | ||
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "checkClass"] }] */ | ||
|
||
function checkClass(obj, name) { | ||
expect(typeof obj).toEqual('object'); | ||
expect(obj.constructor.name).toEqual(name); | ||
} | ||
|
||
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('when require commander then has program (named export of global)', () => { | ||
// program added in v5 | ||
const program = commander.program; | ||
expect(program.constructor.name).toBe('Command'); | ||
test('createOption', () => { | ||
checkClass(createOption('-e, --example', 'description'), 'Option'); | ||
}); | ||
|
||
test('when require commander then has newable Command', () => { | ||
const cmd = new commander.Command(); | ||
expect(cmd.constructor.name).toBe('Command'); | ||
test('createArgument', () => { | ||
checkClass(createArgument('<foo>', 'description'), 'Argument'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters