Skip to content

Commit

Permalink
Add program to exports (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Feb 15, 2020
1 parent 77e511f commit 0a50bd6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Readme.md
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
Expand Up @@ -1533,6 +1533,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
@@ -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');
});

0 comments on commit 0a50bd6

Please sign in to comment.