ADD unit tests, split and refactor source code

This commit is contained in:
RecuencoJones
2019-03-25 20:38:29 +01:00
parent 6eaf5fc9af
commit 8257010937
18 changed files with 782 additions and 392 deletions

40
__test__/cli.spec.js Normal file
View File

@@ -0,0 +1,40 @@
const cli = require('../src/cli');
const install = require('../src/actions/install');
jest.mock('../src/actions/install');
describe('cli()', () => {
let exit;
beforeEach(() => {
exit = jest.fn();
});
it('should exit with error if not enough args are supplied', () => {
cli({ argv: [], exit });
expect(exit).toHaveBeenCalledWith(1);
});
it('should exit with error if command does not exist', () => {
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'command' ], exit });
expect(exit).toHaveBeenCalledWith(1);
});
it('should exit with error if command returns error', () => {
install.mockImplementationOnce((cb) => cb(new Error()));
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'install' ], exit });
expect(exit).toHaveBeenCalledWith(1);
});
it('should exit with success if command runs fine', () => {
install.mockImplementationOnce((cb) => cb(null));
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'install' ], exit });
expect(exit).toHaveBeenCalledWith(0);
});
});