diff --git a/lib/cli/index.js b/lib/cli/index.js index 84a88475..1ca36f34 100644 --- a/lib/cli/index.js +++ b/lib/cli/index.js @@ -33,7 +33,7 @@ exports.run = () => { .option('--update-refs', 'update screenshot references or gather them if they do not exist ("assertView" command)') .arguments('[paths...]') .action((paths) => { - hermione + return hermione .run(paths, { reporters: program.reporter || defaults.reporters, browsers: program.browser, diff --git a/package-lock.json b/package-lock.json index ee57912c..8a3feaf1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -866,7 +866,7 @@ } }, "commander": { - "version": "github:gemini-testing/commander.js#41e43afc72132ab9bd18fca63897c36da57185ce" + "version": "github:gemini-testing/commander.js#cfc28b28f7a6989f7a572f131f993189c407f2d4" }, "compare-func": { "version": "1.3.2", diff --git a/package.json b/package.json index 8e9571cd..3bb8478a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "bluebird-q": "^2.1.1", "chalk": "^1.1.1", "clear-require": "^1.0.1", - "commander": "gemini-testing/commander.js", + "commander": "gemini-testing/commander.js#fix-general-command", "fs-extra": "^5.0.0", "gemini-configparser": "^1.0.0", "gemini-core": "^2.9.0", diff --git a/test/lib/cli/index.js b/test/lib/cli/index.js index ea059e5b..0052d06a 100644 --- a/test/lib/cli/index.js +++ b/test/lib/cli/index.js @@ -14,20 +14,17 @@ const any = sinon.match.any; describe('cli', () => { const sandbox = sinon.sandbox.create(); let parser; + let actionPromise; + const onParse = (fn = _.noop) => { - let actionFn; Command.prototype.parse.callsFake(function() { parser = fn(this); - actionFn && actionFn(_.get(parser, 'args')); + if (Command.prototype.action.lastCall) { + const actionFn = Command.prototype.action.lastCall.args[0]; + actionPromise = actionFn(_.get(parser, 'args')); + } }); - - Command.prototype.action.callsFake((fn) => actionFn = fn); - }; - - const run_ = async (promise = q(true)) => { - sandbox.stub(Hermione.prototype, 'run').returns(promise); - hermioneCli.run(); }; beforeEach(() => { @@ -41,6 +38,7 @@ describe('cli', () => { sandbox.stub(Command.prototype, 'parse'); sandbox.stub(Command.prototype, 'action'); + sandbox.stub(Hermione.prototype, 'run').resolves(); onParse(); }); @@ -49,20 +47,22 @@ describe('cli', () => { it('should show information about config overriding on "--help"', async () => { onParse((parser) => parser.emit('--help')); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledOnce(logger.log); assert.calledWith(logger.log, info.configOverriding); }); it('should create Hermione instance', async () => { - await run_(); + hermioneCli.run(); assert.calledOnce(Hermione.create); }); it('should create Hermione without config by default', async () => { - await run_(); + hermioneCli.run(); assert.calledWith(Hermione.create, undefined); }); @@ -70,108 +70,129 @@ describe('cli', () => { it('should use config path from cli', async () => { onParse((parser) => _.set(parser, 'config', '.conf.hermione.js')); - await run_(); + hermioneCli.run(); + await actionPromise; assert.calledWith(Hermione.create, '.conf.hermione.js'); }); it('should run hermione', async () => { - await run_(); + hermioneCli.run(); assert.calledOnce(Hermione.prototype.run); }); it('should run hermione with paths from args', async () => { onParse((parser) => _.set(parser, 'args', ['first.hermione.js', 'second.hermione.js'])); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledWith(Hermione.prototype.run, ['first.hermione.js', 'second.hermione.js']); }); it('should use default reporters when running hermione', async () => { - await run_(); + hermioneCli.run(); assert.calledWithMatch(Hermione.prototype.run, any, {reporters: defaults.reporters}); }); it('should use reporters from cli', async () => { onParse((parser) => parser.reporter = ['first', 'second']); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledWithMatch(Hermione.prototype.run, any, {reporters: ['first', 'second']}); }); it('should not pass any browsers if they were not specified from cli', async () => { - await run_(); + hermioneCli.run(); assert.calledWithMatch(Hermione.prototype.run, any, {browsers: undefined}); }); it('should use browsers from cli', async () => { onParse((parser) => parser.browser = ['first', 'second']); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledWithMatch(Hermione.prototype.run, any, {browsers: ['first', 'second']}); }); it('should not pass any grep rule if it was not specified from cli', async () => { - await run_(); + hermioneCli.run(); assert.calledWithMatch(Hermione.prototype.run, any, {grep: undefined}); }); it('should use grep rule from cli', async () => { onParse((parser) => parser.grep = 'some-rule'); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledWithMatch(Hermione.prototype.run, any, {grep: 'some-rule'}); }); it('should use update refs mode from cli', async () => { onParse((parser) => parser.updateRefs = true); - await run_(); + + hermioneCli.run(); + await actionPromise; assert.calledWithMatch(Hermione.prototype.run, any, {updateRefs: true}); }); it('should allow hermione to extend cli', async () => { - await run_(); + hermioneCli.run(); assert.calledOnceWith(Hermione.prototype.extendCli, sinon.match.instanceOf(Command)); }); it('should extend cli before parse', async () => { - await run_(); + hermioneCli.run(); assert.callOrder(Hermione.prototype.extendCli, Command.prototype.parse); }); it('should exit with code 0 if tests pass', async () => { - await run_(); + Hermione.prototype.run.returns(q(true)); + hermioneCli.run(); + await actionPromise; assert.calledWith(process.exit, 0); }); it('should exit with code 1 if tests fail', async () => { - await run_(q(false)); + Hermione.prototype.run.returns(q(false)); + hermioneCli.run(); + await actionPromise; assert.calledWith(process.exit, 1); }); it('should exit with code 1 on reject', async () => { - await run_(q.reject({})); + Hermione.prototype.run.rejects(); + hermioneCli.run(); + await actionPromise; assert.calledWith(process.exit, 1); }); it('should log an error stack on reject', async () => { - await run_(q.reject({stack: 'some-stack'})); + Hermione.prototype.run.rejects({stack: 'some-stack'}); + hermioneCli.run(); + await actionPromise; assert.calledWith(logger.error, 'some-stack'); }); it('should log an error on reject if stack does not exist', async () => { - await run_(q.reject('some-error')); + Hermione.prototype.run.returns(q.reject('some-error')); + hermioneCli.run(); + await actionPromise; assert.calledWith(logger.error, 'some-error'); });