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

Commit

Permalink
feat: Pass suiteCollection on BEGIN event to allow to modify it
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn committed Feb 10, 2017
1 parent 1f905cc commit 7d04923
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
* `START_BROWSER` - emitted on browser session start. Emitted with [browser instance](../lib/browser/new-browser.js). If handler returns a promise tests will be executed in this session only after the promise is resolved.

* `STOP_BROWSER` - emitted right before browser session end. Emitted with [browser instance](../lib/browser/new-browser.js). If handler returns a promise quit will be performed only after the promise is resolved.

* `BEGIN` - runner event. Emitted on runner start with 1 argument `data`:
* `data.suiteCollection` - suite collection which will be run
* `data.config` - gemini config
* `data.totalStates` - number of states in collection
* `data.browserIds` - all browser ids from config
1 change: 1 addition & 0 deletions lib/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = class TestsRunner extends Runner {

_formatBeginEventData(suiteCollection) {
return {
suiteCollection,
config: this.config,
totalStates: _.sumBy(suiteCollection.allSuites(), (suite) => suite.states.length),
browserIds: this.config.getBrowserIds()
Expand Down
17 changes: 14 additions & 3 deletions test/unit/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ describe('runner', () => {
return run(runner).then(() => assert.calledOnce(onBegin));
});

it('should pass total number of states when emitting "BEGIN" event', () => {
it('should pass suite collection on "BEGIN" event', () => {
const runner = createRunner();
const suiteCollection = {allSuites: sinon.stub()};
const onBegin = sinon.spy().named('onBegin');

runner.on(Events.BEGIN, onBegin);

return run(runner, suiteCollection)
.then(() => assert.calledWithMatch(onBegin, {suiteCollection}));
});

it('should pass total number of states on "BEGIN" event', () => {
const runner = createRunner();
const suiteCollection = {allSuites: sinon.stub()};
const suites = [
Expand All @@ -150,7 +161,7 @@ describe('runner', () => {
return run(runner, suiteCollection).then(() => assert.calledWithMatch(onBegin, {totalStates: 3}));
});

it('should pass all browser ids when emitting "BEGIN" event', () => {
it('should pass all browser ids on "BEGIN" event', () => {
const runner = createRunner();
const onBegin = sinon.spy().named('onBegin');

Expand All @@ -161,7 +172,7 @@ describe('runner', () => {
return run(runner).then(() => assert.calledWithMatch(onBegin, {browserIds: ['bro1', 'bro2']}));
});

it('should pass config when emitting "BEGIN" event', () => {
it('should pass config on "BEGIN" event', () => {
const runner = createRunner();
const config = runner.config;
const onBegin = sinon.spy().named('onBegin');
Expand Down

0 comments on commit 7d04923

Please sign in to comment.