Skip to content

Commit

Permalink
Merge branch 'feature/createOption-in-helpOption' into feature/obscur…
Browse files Browse the repository at this point in the history
…ed-help-option-warnings
  • Loading branch information
aweebit committed Aug 12, 2023
2 parents d0d2c5e + 7335a9c commit daa3fed
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions tests/command.helpOption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,121 @@ describe('helpOption', () => {
}).toThrow("error: unknown command 'UNKNOWN'");
});
});

describe('obscured help flags', () => {
test('when obscured default help short flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.option('-h');
expect(() => {
program.parse(['-h'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when obscured default help long flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.option('--help');
expect(() => {
program.parse(['--help'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when both default help flags obscured and short flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.option('-h, --help');
expect(() => {
program.parse(['-h'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when both default help flags obscured and long flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.option('-h, --help');
expect(() => {
program.parse(['--help'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when obscured custom help short flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.helpOption('-c, --custom-help')
.option('-c');
expect(() => {
program.parse(['-c'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when obscured custom help long flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.helpOption('-c, --custom-help')
.option('--custom-help');
expect(() => {
program.parse(['--custom-help'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when both custom help flags obscured and short flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.helpOption('-c, --custom-help')
.option('-c, --custom-help');
expect(() => {
program.parse(['-c'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});

test('when both custom help flags obscured and long flag parsed then outputHelp() not called', () => {
const program = new commander.Command();
program.outputHelp = jest.fn().mockImplementation(
program.outputHelp.bind(program)
);
program
.exitOverride()
.helpOption('-c, --custom-help')
.option('-c, --custom-help');
expect(() => {
program.parse(['--custom-help'], { from: 'user' });
}).not.toThrow();
expect(program.outputHelp).not.toHaveBeenCalled();
});
});

0 comments on commit daa3fed

Please sign in to comment.