Skip to content

Commit

Permalink
fix: up
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Mar 15, 2018
1 parent be71dcb commit f9d8cb4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/cli/index.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
79 changes: 50 additions & 29 deletions test/lib/cli/index.js
Expand Up @@ -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(() => {
Expand All @@ -41,6 +38,7 @@ describe('cli', () => {

sandbox.stub(Command.prototype, 'parse');
sandbox.stub(Command.prototype, 'action');
sandbox.stub(Hermione.prototype, 'run').resolves();

onParse();
});
Expand All @@ -49,129 +47,152 @@ 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);
});

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');
});
Expand Down

0 comments on commit f9d8cb4

Please sign in to comment.