From c67b6445a7f693462657941fc976bad302164d80 Mon Sep 17 00:00:00 2001 From: Anton Usmansky Date: Tue, 31 Oct 2017 22:54:06 +0300 Subject: [PATCH] feat: AFTER_TESTS_READ event with suite tree --- doc/events.md | 3 +++ lib/constants/events.js | 2 ++ lib/gemini.js | 4 +++- test/unit/gemini.js | 22 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/doc/events.md b/doc/events.md index 44e6127b1..e290d2a5d 100644 --- a/doc/events.md +++ b/doc/events.md @@ -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 diff --git a/lib/constants/events.js b/lib/constants/events.js index 68d0dcdd0..dd62194fb 100644 --- a/lib/constants/events.js +++ b/lib/constants/events.js @@ -1,6 +1,8 @@ 'use strict'; module.exports = { + AFTER_TESTS_READ: 'afterTestsRead', + START_RUNNER: 'startRunner', END_RUNNER: 'endRunner', diff --git a/lib/gemini.js b/lib/gemini.js index f008b1702..8955bbf22 100644 --- a/lib/gemini.js +++ b/lib/gemini.js @@ -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) { diff --git a/test/unit/gemini.js b/test/unit/gemini.js index 84aeabecf..b93061e26 100644 --- a/test/unit/gemini.js +++ b/test/unit/gemini.js @@ -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', () => { @@ -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', () => {