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

Commit

Permalink
feat: AFTER_TESTS_READ event with suite tree
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn committed Oct 31, 2017
1 parent d475d98 commit c67b644
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/events.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Gemini events

* `AFTER_TESTS_READ` - emitted after all tests were read (during `run`, `update` or `readTests` call). The event is emitted with 1 argument `data`:
* `data.suiteCollection` - suite collection with all suites parsed from test files

* `UPDATE_RESULT` — emitted always during update. The event is emitted with 1 argument `result`:
* `result.imagePath` — absolute path to the reference image
* `result.updated` — boolean value which is `true` when reference image have been changed and `false` when not
Expand Down
2 changes: 2 additions & 0 deletions lib/constants/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

module.exports = {
AFTER_TESTS_READ: 'afterTestsRead',

START_RUNNER: 'startRunner',
END_RUNNER: 'endRunner',

Expand Down
4 changes: 3 additions & 1 deletion lib/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ module.exports = class Gemini extends PassthroughEmitter {
applyGrep_(options.grep, rootSuite);
}

return new SuiteCollection(rootSuite.children);
const suiteCollection = new SuiteCollection(rootSuite.children);
this.emit(Events.AFTER_TESTS_READ, {suiteCollection});
return suiteCollection;
});

function applyGrep_(grep, suite) {
Expand Down
22 changes: 19 additions & 3 deletions test/unit/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,16 @@ describe('gemini', () => {

it('should return SuiteCollection instance', () => {
return readTests_()
.then((result) => {
assert.instanceOf(result, SuiteCollection);
});
.then((result) => assert.instanceOf(result, SuiteCollection));
});

it('should emit AFTER_TESTS_READ event with created suite collection', () => {
const onAfterTestRead = sinon.spy();
gemini = initGemini();
gemini.on(Events.AFTER_TESTS_READ, onAfterTestRead);

return gemini.readTests()
.then((suiteCollection) => assert.calledOnceWith(onAfterTestRead, {suiteCollection}));
});

it('should add to suite collection all read tests excluding root', () => {
Expand Down Expand Up @@ -353,6 +360,15 @@ describe('gemini', () => {
);
});
});

it('should emit AFTER_TESTS_READ event with suite collection', () => {
const onAfterTestRead = sinon.spy();
gemini = initGemini();
gemini.on(Events.AFTER_TESTS_READ, onAfterTestRead);

return gemini.test()
.then(() => assert.calledOnceWith(onAfterTestRead, {suiteCollection: sinon.match.instanceOf(SuiteCollection)}));
});
});

describe('environment variables', () => {
Expand Down

0 comments on commit c67b644

Please sign in to comment.