cli-retrospective
Version:
Recall what you did on the last milestone
132 lines (126 loc) • 4.42 kB
JavaScript
mock('../log');
jest.mock('../command');
jest.mock('../config');
var _exit = process.exit;
var log;
var command;
var config;
var setup = function setup(configExistValue) {
log = require('../log');
log.error = jest.fn();
log.bold = jest.fn(function (s) {
return s;
});
command = require('../command');
command.setupProgram = jest.fn(function (a) {
a();
});
command.lsMilestone = jest.fn();
command.getMilestone = jest.fn();
config = require('../config');
if (typeof configExistValue === 'undefined') {
configExistValue = true;
}
config.configExist = jest.fn(function () {
return configExistValue;
});
config.configGetValues = jest.fn();
require('../cli');
};
describe('cli', function () {
beforeEach(function () {
process.exit = jest.fn();
global.console = {
log: jest.fn(),
error: jest.fn()
};
});
afterEach(function () {
process.exit = _exit;
jest.resetModules();
});
it('should call didYouMean when the command is similar to specific commands', function () {
process.argv = ['node', 'bin/cli.js', 'mileston'];
setup();
expect(log.error.mock.calls.length).toBe(2);
expect(log.error.mock.calls[0][0]).toBe("Unknown command: ".concat(log.bold('mileston')));
expect(log.error.mock.calls[1][0]).toBe("Did you mean ".concat(log.bold('milestone'), " ?"));
expect(process.exit).toBeCalledWith(1);
});
it('should call error when the command not matched', function () {
process.argv = ['node', 'bin/cli.js', 'mm'];
setup();
expect(log.error).toBeCalledWith("Unknown command: ".concat(log.bold('mm')));
expect(process.exit).toBeCalledWith(1);
});
describe('setup command', function () {
it('should call setup', function () {
process.argv = ['node', 'bin/cli.js', 'setup'];
setup();
expect(command.setupProgram.mock.calls.length).toBe(1);
});
it('should call setup with --help', function () {
process.argv = ['node', 'bin/cli.js', 'setup', '--help'];
setup();
expect(global.console.log).toHaveBeenCalledWith(' Setup your cli-retrospective');
});
it('view initial message when call program without options and parameters first time', function () {
process.argv = ['node', 'bin/cli.js'];
setup(false);
jest.spyOn(global.console, 'log');
expect(global.console.log).toHaveBeenCalledWith('');
});
});
describe('ls-milestone command', function () {
it('should call ls-milestone', function () {
process.argv = ['node', 'bin/cli.js', 'ls-milestone'];
setup();
expect(command.lsMilestone.mock.calls.length).toBe(1);
});
it('should call ls-milestone with --help', function () {
process.argv = ['node', 'bin/cli.js', 'ls-milestone', '--help'];
setup();
expect(global.console.log).toHaveBeenCalledWith(' Get list of all milestone.');
});
});
describe('milestone command', function () {
it('should call milestone', function () {
process.argv = ['node', 'bin/cli.js', 'milestone', '10.10.x'];
setup();
expect(command.getMilestone.mock.calls.length).toBe(1);
});
it('should call milestone with --help', function () {
process.argv = ['node', 'bin/cli.js', 'milestone', '--help'];
setup();
expect(global.console.log).toHaveBeenCalledWith(' Get list of issue in milestone.');
});
});
describe('--help options', function () {
it('view help when call program without options and parameters', function () {
process.argv = ['node', 'bin/cli.js'];
setup();
jest.spyOn(global.console, 'log');
expect(global.console.log).toHaveBeenCalledWith('');
});
it('should call --help', function () {
process.argv = ['node', 'bin/cli.js', '--help'];
setup();
jest.spyOn(global.console, 'log');
expect(global.console.log).toHaveBeenCalledWith('');
expect(process.exit).toBeCalledWith(1);
});
});
describe('--version options', function () {
it('view version when call program without options and parameters', function () {
process.argv = ['node', 'bin/cli.js'];
setup();
jest.spyOn(global.console, 'log');
expect(global.console.log).toHaveBeenCalledWith('');
});
it('should call --version', function () {
process.argv = ['node', 'bin/cli.js', '--version'];
setup();
});
});
});
;
jest.