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

Commit c67b644

Browse files
committed
feat: AFTER_TESTS_READ event with suite tree
1 parent d475d98 commit c67b644

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

doc/events.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Gemini events
22

3+
* `AFTER_TESTS_READ` - emitted after all tests were read (during `run`, `update` or `readTests` call). The event is emitted with 1 argument `data`:
4+
* `data.suiteCollection` - suite collection with all suites parsed from test files
5+
36
* `UPDATE_RESULT` — emitted always during update. The event is emitted with 1 argument `result`:
47
* `result.imagePath` — absolute path to the reference image
58
* `result.updated` — boolean value which is `true` when reference image have been changed and `false` when not

lib/constants/events.js

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

33
module.exports = {
4+
AFTER_TESTS_READ: 'afterTestsRead',
5+
46
START_RUNNER: 'startRunner',
57
END_RUNNER: 'endRunner',
68

lib/gemini.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ module.exports = class Gemini extends PassthroughEmitter {
116116
applyGrep_(options.grep, rootSuite);
117117
}
118118

119-
return new SuiteCollection(rootSuite.children);
119+
const suiteCollection = new SuiteCollection(rootSuite.children);
120+
this.emit(Events.AFTER_TESTS_READ, {suiteCollection});
121+
return suiteCollection;
120122
});
121123

122124
function applyGrep_(grep, suite) {

test/unit/gemini.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,16 @@ describe('gemini', () => {
230230

231231
it('should return SuiteCollection instance', () => {
232232
return readTests_()
233-
.then((result) => {
234-
assert.instanceOf(result, SuiteCollection);
235-
});
233+
.then((result) => assert.instanceOf(result, SuiteCollection));
234+
});
235+
236+
it('should emit AFTER_TESTS_READ event with created suite collection', () => {
237+
const onAfterTestRead = sinon.spy();
238+
gemini = initGemini();
239+
gemini.on(Events.AFTER_TESTS_READ, onAfterTestRead);
240+
241+
return gemini.readTests()
242+
.then((suiteCollection) => assert.calledOnceWith(onAfterTestRead, {suiteCollection}));
236243
});
237244

238245
it('should add to suite collection all read tests excluding root', () => {
@@ -353,6 +360,15 @@ describe('gemini', () => {
353360
);
354361
});
355362
});
363+
364+
it('should emit AFTER_TESTS_READ event with suite collection', () => {
365+
const onAfterTestRead = sinon.spy();
366+
gemini = initGemini();
367+
gemini.on(Events.AFTER_TESTS_READ, onAfterTestRead);
368+
369+
return gemini.test()
370+
.then(() => assert.calledOnceWith(onAfterTestRead, {suiteCollection: sinon.match.instanceOf(SuiteCollection)}));
371+
});
356372
});
357373

358374
describe('environment variables', () => {

0 commit comments

Comments
 (0)