Merge pull request #1063 from shadowspawn/feature/test-main
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add tests on action handler for program
authored by Tomoaki Abe · committed by GitHub · parents 9499d47, 03b0034 · Browse files · 2 files·+75 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+75 added−6 removed
- tests:+75 added−6 removed
Provenance
- Commit
a45d676- Tree
f12b46d- Author
Tomoaki Abe <abe@enzou.tokyo>- Committer
GitHub <noreply@github.com>- Parent 1
9499d47- Parent 2
03b0034
2 files changed+75 added−6 removed
modified:tests/command.action.test.js+54 added
32 unmodified lines3334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899032 unmodified lines .action(actionMock); program.parse(['node', 'test', 'info', 'my-file', 'a']); expect(actionMock).toHaveBeenCalledWith('my-file', cmd, ['a']);});
test('when .action on program with argument then action called', () => { const actionMock = jest.fn(); const program = new commander.Command(); program .arguments('<file>') .action(actionMock); program.parse(['node', 'test', 'my-file']); expect(actionMock).toHaveBeenCalledWith('my-file', program);});
// Changes made in #729 to call program action handlertest('when .action on program and no arguments then action called', () => { const actionMock = jest.fn(); const program = new commander.Command(); program .action(actionMock); program.parse(['node', 'test']); expect(actionMock).toHaveBeenCalledWith(program);});
test('when .action on program with optional argument supplied then action called', () => { const actionMock = jest.fn(); const program = new commander.Command(); program .arguments('[file]') .action(actionMock); program.parse(['node', 'test', 'my-file']); expect(actionMock).toHaveBeenCalledWith('my-file', program);});
test('when .action on program without optional argument supplied then action called', () => { const actionMock = jest.fn(); const program = new commander.Command(); program .arguments('[file]') .action(actionMock); program.parse(['node', 'test']); expect(actionMock).toHaveBeenCalledWith(undefined, program);});
test('when .action on program with subcommand and program argument then program action called', () => { const actionMock = jest.fn(); const program = new commander.Command(); program .arguments('[file]') .action(actionMock); program .command('subcommand');
program.parse(['node', 'test', 'a']);
expect(actionMock).toHaveBeenCalledWith('a', program);});modified:tests/openIssues.test.js.skip+21 added-6 removed
2 unmodified lines3 const path = require('path');4 5 describe('open issues', () => {6 // https://github.com/tj/commander.js/issues/10397- test('#1039: when unknown option then unknown option detected', () => {7+ test.skip('#1039: when unknown option then unknown option detected', () => {8 const program = new commander.Command();9 program10 .exitOverride();11 expect(() => {12 program.parse(['node', 'text', '--bug']);13 }).toThrow();14 });15 16- test('#1039: when unknown option and multiple arguments then unknown option detected', () => {16+ test.skip('#1039: when unknown option and multiple arguments then unknown option detected', () => {17 const program = new commander.Command();18 program19 .exitOverride();20 expect(() => {11 unmodified lines32 });33 return program;34 };35 36- test('#1032: when specify subcommand then args not empty', () => {36+ test.skip('#1032: when specify subcommand then args not empty', () => {37 const program = createProgram1032();38 program.parse(['node', 'test.js', 'doit', 'myid']);39 expect(program.args.length).toBeGreaterThan(0);40 });41 42- test('#1032: when specify subcommand and option then args not empty', () => {42+ test.skip('#1032: when specify subcommand and option then args not empty', () => {43 const program = createProgram1032();44 program.parse(['node', 'test.js', 'doit', '--better', 'myid']);45 expect(program.args.length).toBeGreaterThan(0);46 });47 48 // https://github.com/tj/commander.js/issues/56149- test('#561: when specify argument and unknown option then error', () => {49+ test.skip('#561: when specify argument and unknown option then error', () => {50 const program = new commander.Command();51 program52 .exitOverride()53 .option('-x, --x-flag', 'A flag')4 unmodified lines58 }).toThrow();59 });60 61 // https://github.com/tj/commander.js/issues/50862- test('#508: when arguments to executable include option flags then argument order preserved', (done) => {62+ test.skip('#508: when arguments to executable include option flags then argument order preserved', (done) => {63 const pm = path.join(__dirname, 'fixtures/pm');64 childProcess.execFile('node', [pm, 'echo', '1', '2', '--dry-run', '3', '4', '5', '6'], function(_error, stdout, stderr) {65 expect(stdout).toBe("[ '1', '2', '--dry-run', '3', '4', '5', '6' ]\n");66 done();67 });68 });69+70+ // https://github.com/tj/commander.js/pull/106271+ test.skip('#1062 when .action on program with subcommands and no program argument then program action called', () => {72+ const actionMock = jest.fn();73+ const program = new commander.Command();74+ program75+ .arguments('[file]')76+ .action(actionMock);77+ program78+ .command('subcommand');79+80+ program.parse(['node', 'test']);81+82+ expect(actionMock).toHaveBeenCalledWith(undefined, program);83+ });84 });