Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

feat: use bluebird instead of q #791

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/browser/client-scripts/gemini.calibrate.min.js

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

7 changes: 4 additions & 3 deletions lib/capture-session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const inherit = require('inherit');
const _ = require('lodash');
const debug = require('debug');
const promiseUtil = require('q-promise-utils');
const Promise = require('bluebird');

const ActionsBuilder = require('../tests-api/actions-builder');
const Browser = require('../browser');
const temp = require('../temp');
Expand All @@ -25,7 +26,7 @@ var CaptureSession = inherit({

runActions: function(actions) {
this.log('run actions');
return promiseUtil.sequence(actions, this.browser, new ActionsBuilder(this._postActions));
return Promise.mapSeries(actions, (a) => a(this.browser, new ActionsBuilder(this._postActions)));
},

prepareScreenshot: function(state) {
Expand All @@ -45,7 +46,7 @@ var CaptureSession = inherit({
},

runPostActions: function() {
return promiseUtil.sequence(this._postActions.reverse(), this.browser);
return Promise.mapSeries(this._postActions.reverse(), (a) => a(this.browser));
},

extendWithPageScreenshot: function(obj) {
Expand Down
11 changes: 5 additions & 6 deletions lib/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
const debug = require('debug');
const chalk = require('chalk');
const _ = require('lodash');
const PassthroughEmitter = require('./passthrough-emitter');
const PassthroughEmitter = require('gemini-core').PassthroughEmitter;
const Promise = require('bluebird');
const q = require('bluebird-q');
const pluginsLoader = require('plugins-loader');
const gracefulFs = require('graceful-fs');

Expand Down Expand Up @@ -129,14 +128,14 @@ module.exports = class Gemini extends PassthroughEmitter {

options = _.assignIn(options, {paths});

return q(readTests(this, this.config, options)
return readTests(this, this.config, options)
.then((rootSuite) => {
if (options.grep) {
applyGrep_(options.grep, rootSuite);
}

return new SuiteCollection(rootSuite.children);
}));
});

function applyGrep_(grep, suite) {
if (!suite.hasStates) {
Expand All @@ -156,11 +155,11 @@ module.exports = class Gemini extends PassthroughEmitter {
}

update(paths, options) {
return q(this._run(StateProcessor.createScreenUpdater(options), paths, options));
return this._run(StateProcessor.createScreenUpdater(options), paths, options);
}

test(paths, options) {
return q(this._run(StateProcessor.createTester(this.config), paths, options));
return this._run(StateProcessor.createTester(this.config), paths, options);
}

getScreenshotPath(suite, stateName, browserId) {
Expand Down
35 changes: 0 additions & 35 deletions lib/passthrough-emitter.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/runner/browser-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const _ = require('lodash');
const url = require('url');
const path = require('path');
const promiseUtils = require('q-promise-utils');
const BrowserAgent = require('gemini-core').BrowserAgent;
const promiseUtils = require('gemini-core').promiseUtils;
const Runner = require('../runner');
const SuiteRunner = require('../suite-runner');
const Events = require('../../constants/events');
Expand Down
6 changes: 2 additions & 4 deletions lib/runner/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

const Promise = require('bluebird');
const _ = require('lodash');
const promiseUtils = require('q-promise-utils');

const pool = require('../browser-pool');
const BrowserRunner = require('./browser-runner');
const Events = require('../constants/events');
const Coverage = require('../coverage');
const Runner = require('./runner');
const RunnerStats = require('../stats');
const SuiteMonitor = require('../suite-monitor');
const promiseUtils = require('gemini-core').promiseUtils;

module.exports = class TestsRunner extends Runner {
static create(config, stateProcessor) {
Expand All @@ -37,7 +35,7 @@ module.exports = class TestsRunner extends Runner {
}

run(suiteCollection) {
return Promise.resolve(this.emitAndWait(Events.START_RUNNER, this))
return this.emitAndWait(Events.START_RUNNER, this)
.then(() => this.emit(Events.BEGIN, this._formatBeginEventData(suiteCollection)))
.then(() => this._stateProcessor.prepare(this))
.then(() => !this._cancelled && this._runTests(suiteCollection))
Expand Down
3 changes: 1 addition & 2 deletions lib/runner/runner.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

const PassthroughEmitter = require('../passthrough-emitter');
const PassthroughEmitter = require('gemini-core').PassthroughEmitter;

module.exports = class Runner extends PassthroughEmitter {
run() {
throw 'Not implemented';
}
};

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"gemini-configparser": "^0.4.0",
"gemini-core": "^1.3.0",
"gemini-core": "gemini-testing/gemini-core#feature/emitters",
"gemini-coverage": "^1.0.0",
"graceful-fs": "^4.1.11",
"handlebars": "^4.0.5",
Expand All @@ -32,8 +32,6 @@
"node-fetch": "^1.6.3",
"plugins-loader": "^1.0.1",
"png-img": "^2.1.0",
"q-promise-utils": "^1.1.0",
"qemitter": "^1.0.0",
"resolve": "^1.1.0",
"sizzle": "^2.2.0",
"source-map": "^0.5.3",
Expand Down
6 changes: 6 additions & 0 deletions test/assert-ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

global.assert.calledOnceWith = function() {
assert.calledOnce(arguments[0]);
assert.calledWith.apply(null, arguments);
};
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--require ./test/setup
--require ./test/assert-ext
-t 0
10 changes: 5 additions & 5 deletions test/unit/browser-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BrowserFabric = require('lib/browser');
const Calibrator = require('lib/calibrator');
const RunnerEvents = require('lib/constants/events');
const CoreBrowserPool = require('gemini-core').BrowserPool;
const QEmitter = require('qemitter');
const AsyncEmitter = require('gemini-core').AsyncEmitter;
const _ = require('lodash');
const Promise = require('bluebird');

Expand Down Expand Up @@ -120,7 +120,7 @@ describe('browser-pool', () => {

describe('events', () => {
it('should emit START_BROWSER on start', () => {
const emitter = new QEmitter();
const emitter = new AsyncEmitter();
const onBrowserStart = sinon.spy();
emitter.on(RunnerEvents.START_BROWSER, onBrowserStart);

Expand All @@ -134,7 +134,7 @@ describe('browser-pool', () => {
});

it('should wait START_BROWSER handler', () => {
const emitter = new QEmitter();
const emitter = new AsyncEmitter();
const spy1 = sinon.spy();
const spy2 = sinon.spy();

Expand All @@ -148,7 +148,7 @@ describe('browser-pool', () => {
});

it('should emit STOP_BROWSER on quit', () => {
const emitter = new QEmitter();
const emitter = new AsyncEmitter();
const onBrowserQuit = sinon.spy();
emitter.on(RunnerEvents.STOP_BROWSER, onBrowserQuit);

Expand All @@ -162,7 +162,7 @@ describe('browser-pool', () => {
});

it('should wait STOP_BROWSER handler', () => {
const emitter = new QEmitter();
const emitter = new AsyncEmitter();
const spy1 = sinon.spy();
const spy2 = sinon.spy();

Expand Down
106 changes: 57 additions & 49 deletions test/unit/capture-session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const Promise = require('bluebird');
const _ = require('lodash');
const promiseUtils = require('q-promise-utils');

const CaptureSession = require('lib/capture-session');
const ActionsBuilder = require('lib/tests-api/actions-builder');
Expand All @@ -17,15 +16,13 @@ describe('capture session', () => {

beforeEach(() => {
imageStub = sinon.createStubInstance(Image);
sandbox.stub(promiseUtils);
promiseUtils.sequence.returns(Promise.resolve());

sandbox.stub(temp);
});

afterEach(() => sandbox.restore());

describe('runActions', () => {
describe('run methods', () => {
let browser;
let session;

Expand All @@ -34,67 +31,78 @@ describe('capture session', () => {
session = new CaptureSession(browser);
});

it('should perform passed action sequence', () => {
const actions = [];
describe('runActions', () => {
it('should call action in associated browser and with "postActions"', () => {
const action = sinon.spy().named('action');

session.runActions(actions);

assert.calledOnce(promiseUtils.sequence);
assert.calledWith(promiseUtils.sequence, actions);
});

it('should perform actions sequence in associated browser', () => {
session.runActions([]);
return session.runActions([action])
.then(() => assert.calledOnceWith(action, browser, sinon.match.instanceOf(ActionsBuilder)));
});

assert.calledWith(promiseUtils.sequence, sinon.match.any, browser);
});
it('should perform all actions with the same postActions instance', () => {
const action = sinon.spy().named('action');
sandbox.stub(ActionsBuilder.prototype, '__constructor').returnsArg(0);

it('should peform actions sequence with postActions', () => {
session.runActions([]);
return session.runActions([action])
.then(() => session.runActions([action]))
.then(() => assert.deepEqual(action.firstCall.args[1], action.secondCall.args[1]));
});

assert.calledWith(promiseUtils.sequence,
sinon.match.any,
sinon.match.any,
sinon.match.instanceOf(ActionsBuilder)
);
});
it('should perform passed actions in order', () => {
const mediator = sinon.spy().named('mediator');
const action1 = sinon.stub().named('action1').callsFake(() => Promise.delay(1).then(mediator));
const action2 = sinon.spy().named('action2');

it('should perform all actions with the same postActions instance', () => {
sandbox.stub(ActionsBuilder.prototype, '__constructor').returnsArg(0);
return session.runActions([action1, action2])
.then(() => assert.callOrder(action1, mediator, action2));
});

session.runActions([]);
session.runActions([]);
it('should reject if any of passed actions rejected', () => {
const action1 = sinon.stub().named('action1').returns(Promise.resolve());
const action2 = sinon.stub().named('action2').returns(Promise.reject('foo'));

assert.equal(
promiseUtils.sequence.firstCall.args[2],
promiseUtils.sequence.secondCall.args[2]
);
return assert.isRejected(session.runActions([action1, action2]), /foo/);
});
});
});

describe('runPostActions', () => {
it('should not pass postActions while performing postActions', () => {
const browser = {config: {}};
const session = new CaptureSession(browser);
describe('runPostActions', () => {
it('should call action in associated browser', () => {
const action = sinon.spy().named('action');

session.runPostActions();
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
postActions.push(action);
});

assert.lengthOf(promiseUtils.sequence.firstCall.args, 2);
});
return session.runActions([action])
.then(() => session.runPostActions())
.then(() => assert.deepEqual(action.secondCall.args, [browser]));
});

it('should perform post actions in reverse order', () => {
const browser = {config: {}};
const session = new CaptureSession(browser);
it('should perform post actions in reverse order', () => {
const mediator = sinon.spy().named('mediator');
const action1 = sinon.spy().named('action1');
const action2 = sinon.stub().named('action2').callsFake(() => Promise.delay(1).then(mediator));

sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
postActions.push(1, 2, 3);
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
postActions.push(action1, action2);
});

return session.runActions([action1, action2])
.then(() => session.runPostActions())
.then(() => assert.callOrder(action2, mediator, action1));
});
session.runActions([]);
session.runActions([]);

session.runPostActions();
it('should reject if any of post actions rejected', () => {
const action1 = sinon.stub().named('action1').returns(Promise.resolve());
const action2 = sinon.stub().named('action2').returns(Promise.reject('foo'));

assert.calledWith(promiseUtils.sequence, [3, 2, 1, 3, 2, 1]);
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
postActions.push(action1, action2);
});

return session.runActions([action1, action2])
.catch(() => assert.isRejected(session.runPostActions(), /foo/));
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/unit/passthrough-emitter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const PassthroughEmitter = require('lib/passthrough-emitter');

const PassthroughEmitter = require('gemini-core').PassthroughEmitter;

describe('PassthroughEmitter', () => {
let runner,
Expand Down Expand Up @@ -47,4 +48,3 @@ describe('PassthroughEmitter', () => {
});
});
});