Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Commander exports a global object which is convenient for quick programs.
This is used in the examples in this README for brevity.

```js
const program = require('commander');
const program = require('commander').program;
program.version('0.0.1');
```

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ class Command extends EventEmitter {
*/

exports = module.exports = new Command();
exports.program = exports; // More explicit access to global command.

/**
* Expose classes
Expand Down
20 changes: 20 additions & 0 deletions tests/program.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const commander = require('../');

// Do some testing of the default export(s).

test('when require commander then is a Command (default export of global)', () => {
// Legacy global command
const program = commander;
expect(program.constructor.name).toBe('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('when require commander then has newable Command', () => {
const cmd = new commander.Command();
expect(cmd.constructor.name).toBe('Command');
});