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

Commit 529db7d

Browse files
committed
test: fix tests
1 parent 96ae1e8 commit 529db7d

File tree

5 files changed

+74
-67
lines changed

5 files changed

+74
-67
lines changed

test/unit/browser-pool.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BrowserFabric = require('lib/browser');
55
const Calibrator = require('lib/calibrator');
66
const RunnerEvents = require('lib/constants/events');
77
const CoreBrowserPool = require('gemini-core').BrowserPool;
8-
const QEmitter = require('qemitter');
8+
const AsyncEmitter = require('gemini-core').AsyncEmitter;
99
const _ = require('lodash');
1010
const Promise = require('bluebird');
1111

@@ -120,7 +120,7 @@ describe('browser-pool', () => {
120120

121121
describe('events', () => {
122122
it('should emit START_BROWSER on start', () => {
123-
const emitter = new QEmitter();
123+
const emitter = new AsyncEmitter();
124124
const onBrowserStart = sinon.spy();
125125
emitter.on(RunnerEvents.START_BROWSER, onBrowserStart);
126126

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

136136
it('should wait START_BROWSER handler', () => {
137-
const emitter = new QEmitter();
137+
const emitter = new AsyncEmitter();
138138
const spy1 = sinon.spy();
139139
const spy2 = sinon.spy();
140140

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

150150
it('should emit STOP_BROWSER on quit', () => {
151-
const emitter = new QEmitter();
151+
const emitter = new AsyncEmitter();
152152
const onBrowserQuit = sinon.spy();
153153
emitter.on(RunnerEvents.STOP_BROWSER, onBrowserQuit);
154154

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

164164
it('should wait STOP_BROWSER handler', () => {
165-
const emitter = new QEmitter();
165+
const emitter = new AsyncEmitter();
166166
const spy1 = sinon.spy();
167167
const spy2 = sinon.spy();
168168

test/unit/capture-session/index.js

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

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

1817
beforeEach(() => {
1918
imageStub = sinon.createStubInstance(Image);
20-
sandbox.stub(promiseUtils);
21-
promiseUtils.sequence.returns(Promise.resolve());
2219

2320
sandbox.stub(temp);
2421
});
2522

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

28-
describe('runActions', () => {
25+
describe('run methods', () => {
2926
let browser;
3027
let session;
3128

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

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

40-
session.runActions(actions);
41-
42-
assert.calledOnce(promiseUtils.sequence);
43-
assert.calledWith(promiseUtils.sequence, actions);
44-
});
45-
46-
it('should perform actions sequence in associated browser', () => {
47-
session.runActions([]);
38+
return session.runActions([action])
39+
.then(() => assert.calledOnceWith(action, browser, sinon.match.instanceOf(ActionsBuilder)));
40+
});
4841

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

52-
it('should peform actions sequence with postActions', () => {
53-
session.runActions([]);
46+
return session.runActions([action])
47+
.then(() => session.runActions([action]))
48+
.then(() => assert.deepEqual(action.firstCall.args[1], action.secondCall.args[1]));
49+
});
5450

55-
assert.calledWith(promiseUtils.sequence,
56-
sinon.match.any,
57-
sinon.match.any,
58-
sinon.match.instanceOf(ActionsBuilder)
59-
);
60-
});
51+
it('should perform passed actions in order', () => {
52+
const mediator = sinon.spy().named('mediator');
53+
const action1 = sinon.stub().named('action1').callsFake(() => Promise.delay(1).then(mediator));
54+
const action2 = sinon.spy().named('action2');
6155

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

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

68-
assert.equal(
69-
promiseUtils.sequence.firstCall.args[2],
70-
promiseUtils.sequence.secondCall.args[2]
71-
);
64+
return assert.isRejected(session.runActions([action1, action2]), /foo/);
65+
});
7266
});
73-
});
7467

75-
describe('runPostActions', () => {
76-
it('should not pass postActions while performing postActions', () => {
77-
const browser = {config: {}};
78-
const session = new CaptureSession(browser);
68+
describe('runPostActions', () => {
69+
it('should call action in associated browser', () => {
70+
const action = sinon.spy().named('action');
7971

80-
session.runPostActions();
72+
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
73+
postActions.push(action);
74+
});
8175

82-
assert.lengthOf(promiseUtils.sequence.firstCall.args, 2);
83-
});
76+
return session.runActions([action])
77+
.then(() => session.runPostActions())
78+
.then(() => assert.deepEqual(action.secondCall.args, [browser]));
79+
});
8480

85-
it('should perform post actions in reverse order', () => {
86-
const browser = {config: {}};
87-
const session = new CaptureSession(browser);
81+
it('should perform post actions in reverse order', () => {
82+
const mediator = sinon.spy().named('mediator');
83+
const action1 = sinon.spy().named('action1');
84+
const action2 = sinon.stub().named('action2').callsFake(() => Promise.delay(1).then(mediator));
8885

89-
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
90-
postActions.push(1, 2, 3);
86+
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
87+
postActions.push(action1, action2);
88+
});
89+
90+
return session.runActions([action1, action2])
91+
.then(() => session.runPostActions())
92+
.then(() => assert.callOrder(action2, mediator, action1));
9193
});
92-
session.runActions([]);
93-
session.runActions([]);
9494

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

97-
assert.calledWith(promiseUtils.sequence, [3, 2, 1, 3, 2, 1]);
99+
sandbox.stub(ActionsBuilder.prototype, '__constructor').callsFake((postActions) => {
100+
postActions.push(action1, action2);
101+
});
102+
103+
return session.runActions([action1, action2])
104+
.catch(() => assert.isRejected(session.runPostActions(), /foo/));
105+
});
98106
});
99107
});
100108

test/unit/passthrough-emitter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
2-
const PassthroughEmitter = require('lib/passthrough-emitter');
2+
3+
const PassthroughEmitter = require('gemini-core').PassthroughEmitter;
34

45
describe('PassthroughEmitter', () => {
56
let runner,
@@ -47,4 +48,3 @@ describe('PassthroughEmitter', () => {
4748
});
4849
});
4950
});
50-

test/unit/runner/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const Promise = require('bluebird');
4-
const q = require('bluebird-q');
54
const pool = require('lib/browser-pool');
65
const Config = require('lib/config');
76
const Events = require('lib/constants/events');
@@ -274,8 +273,8 @@ describe('runner', () => {
274273

275274
it('should not be immediately rejected if running of tests in some browser was rejected', () => {
276275
const runner = createRunner();
277-
const rejected = q.reject();
278-
const delayed = q.delay(50);
276+
const rejected = Promise.reject();
277+
const delayed = Promise.delay(50);
279278

280279
runner.config.getBrowserIds.returns(['bro1', 'bro2']);
281280

@@ -287,8 +286,8 @@ describe('runner', () => {
287286

288287
it('should be rejected with the first error if running of tests in several browsers were rejected', () => {
289288
const runner = createRunner();
290-
const firstReject = q.reject('first-runner');
291-
const secondReject = q.reject('second-runner');
289+
const firstReject = Promise.reject('first-runner');
290+
const secondReject = Promise.reject('second-runner');
292291

293292
runner.config.getBrowserIds.returns(['bro1', 'bro2']);
294293

@@ -313,7 +312,7 @@ describe('runner', () => {
313312

314313
runner.on(Events.END_SESSION, onEndSession);
315314

316-
BrowserRunner.prototype.run.returns(q.reject());
315+
BrowserRunner.prototype.run.returns(Promise.reject());
317316

318317
return run(runner).catch(() => assert.calledOnce(onEndSession));
319318
});
@@ -327,7 +326,7 @@ describe('runner', () => {
327326
it('should be rejected if collecting of coverage fails', () => {
328327
const runner = createRunner({config: stubConfig({isCoverageEnabled: true})});
329328

330-
Coverage.prototype.processStats.returns(q.reject());
329+
Coverage.prototype.processStats.returns(Promise.reject());
331330

332331
return assert.isRejected(run(runner));
333332
});
@@ -376,7 +375,7 @@ describe('runner', () => {
376375

377376
runner.on(Events.END, onEnd);
378377

379-
BrowserRunner.prototype.run.returns(q.reject());
378+
BrowserRunner.prototype.run.returns(Promise.reject());
380379

381380
return run(runner).catch(() => assert.calledOnce(onEnd));
382381
});
@@ -416,7 +415,7 @@ describe('runner', () => {
416415

417416
runner.on(Events.END_RUNNER, onEndRunner);
418417

419-
BrowserRunner.prototype.run.returns(q.reject());
418+
BrowserRunner.prototype.run.returns(Promise.reject());
420419

421420
return run(runner).catch(() => assert.calledOnce(onEndRunner));
422421
});

test/unit/state-processor/state-processor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var CaptureSession = require('lib/capture-session'),
77
errorUtils = require('lib/errors/utils'),
88
proxyquire = require('proxyquire').noCallThru(),
99
_ = require('lodash'),
10-
QEmitter = require('qemitter'),
10+
AsyncEmitter = require('gemini-core').AsyncEmitter,
1111
Promise = require('bluebird');
1212

1313
describe('state-processor/state-processor', () => {
@@ -56,7 +56,7 @@ describe('state-processor/state-processor', () => {
5656
var StateProcessor = proxyquire('lib/state-processor/state-processor', stubs),
5757
stateProcessor = new StateProcessor(opts.captureProcessorInfo);
5858

59-
stateProcessor.prepare(new QEmitter());
59+
stateProcessor.prepare(new AsyncEmitter());
6060
return stateProcessor.exec(opts.state, browserSession, opts.page);
6161
}
6262

0 commit comments

Comments
 (0)