From 3c41ab7a038c344425e7f5625c661bc9a39e36df Mon Sep 17 00:00:00 2001 From: Anton Usmansky Date: Mon, 29 Aug 2022 19:14:44 +0300 Subject: [PATCH] feat: use EventEmitter2 instead of AsyncEmitter from gemini-core --- lib/gui/api/facade.js | 4 +-- lib/gui/api/index.js | 4 +-- lib/plugin-api.js | 4 +-- package-lock.json | 13 +++++++- package.json | 1 + test/unit/hermione.js | 30 +++++++++---------- test/unit/lib/gui/api/index.js | 4 +-- .../lib/gui/tool-runner/report-subsciber.js | 18 +++++------ test/unit/lib/plugin-adapter.js | 10 +++---- test/unit/utils.js | 4 +-- 10 files changed, 52 insertions(+), 40 deletions(-) diff --git a/lib/gui/api/facade.js b/lib/gui/api/facade.js index a8d06731a..fd3b0cc63 100644 --- a/lib/gui/api/facade.js +++ b/lib/gui/api/facade.js @@ -1,9 +1,9 @@ 'use strict'; -const {AsyncEmitter} = require('gemini-core').events; +const EventEmitter2 = require('eventemitter2'); const guiEvents = require('../constants/gui-events'); -module.exports = class ApiFacade extends AsyncEmitter { +module.exports = class ApiFacade extends EventEmitter2 { static create() { return new ApiFacade(); } diff --git a/lib/gui/api/index.js b/lib/gui/api/index.js index 4710ccdc9..178a9f79c 100644 --- a/lib/gui/api/index.js +++ b/lib/gui/api/index.js @@ -12,10 +12,10 @@ module.exports = class Api { } async initServer(server) { - await this._gui.emitAndWait(this._gui.events.SERVER_INIT, server); + await this._gui.emitAsync(this._gui.events.SERVER_INIT, server); } async serverReady(data) { - await this._gui.emitAndWait(this._gui.events.SERVER_READY, data); + await this._gui.emitAsync(this._gui.events.SERVER_READY, data); } }; diff --git a/lib/plugin-api.js b/lib/plugin-api.js index 7be5b8072..ecc373648 100644 --- a/lib/plugin-api.js +++ b/lib/plugin-api.js @@ -1,10 +1,10 @@ 'use strict'; -const AsyncEmitter = require('gemini-core').events.AsyncEmitter; +const EventsEmitter = require('events'); const pluginEvents = require('./constants/plugin-events'); const {downloadDatabases, mergeDatabases, getTestsTreeFromDatabase} = require('./db-utils/server'); -module.exports = class HtmlReporter extends AsyncEmitter { +module.exports = class HtmlReporter extends EventsEmitter { static create(config) { return new this(config); } diff --git a/package-lock.json b/package-lock.json index 103eef275..6de1bc678 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "html-reporter", - "version": "9.2.1", + "version": "9.2.2", "license": "MIT", "dependencies": { "@gemini-testing/sql.js": "^1.0.1", @@ -16,6 +16,7 @@ "body-parser": "^1.18.2", "chalk": "^1.1.3", "debug": "^4.1.1", + "eventemitter2": "6.4.7", "express": "^4.16.2", "filesize": "^8.0.6", "fs-extra": "^7.0.1", @@ -7484,6 +7485,11 @@ "es5-ext": "~0.10.14" } }, + "node_modules/eventemitter2": { + "version": "6.4.7", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.7.tgz", + "integrity": "sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==" + }, "node_modules/eventemitter3": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz", @@ -28807,6 +28813,11 @@ "es5-ext": "~0.10.14" } }, + "eventemitter2": { + "version": "6.4.7", + "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.7.tgz", + "integrity": "sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==" + }, "eventemitter3": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz", diff --git a/package.json b/package.json index 9b91bf9f9..0460036c3 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "body-parser": "^1.18.2", "chalk": "^1.1.3", "debug": "^4.1.1", + "eventemitter2": "6.4.7", "express": "^4.16.2", "filesize": "^8.0.6", "fs-extra": "^7.0.1", diff --git a/test/unit/hermione.js b/test/unit/hermione.js index 5410558cb..ad41d9452 100644 --- a/test/unit/hermione.js +++ b/test/unit/hermione.js @@ -58,7 +58,7 @@ describe('lib/hermione', () => { HermioneReporter(hermione, opts); - return hermione.emitAndWait(hermione.events.INIT); + return hermione.emitAsync(hermione.events.INIT); } function mkStubResult_(options = {}) { @@ -73,7 +73,7 @@ describe('lib/hermione', () => { } async function stubWorkers() { - await hermione.emitAndWait(events.RUNNER_START, { + await hermione.emitAsync(events.RUNNER_START, { registerWorkers: () => { return {saveDiffTo: sandbox.stub()}; } @@ -138,7 +138,7 @@ describe('lib/hermione', () => { it('should add skipped test to result', async () => { await initReporter_(); hermione.emit(events.TEST_PENDING, mkStubResult_({title: 'some-title'})); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addSkipped.args[0][0].state, {name: 'some-title'}); }); @@ -146,7 +146,7 @@ describe('lib/hermione', () => { it('should add passed test to result', async () => { await initReporter_(); hermione.emit(events.TEST_PASS, mkStubResult_({title: 'some-title'})); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addSuccess.args[0][0].state, {name: 'some-title'}); }); @@ -158,7 +158,7 @@ describe('lib/hermione', () => { await initReporter_(); hermione.emit(events[event], testResult); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addError.args[0][0].state, {name: 'some-title'}); }); @@ -169,7 +169,7 @@ describe('lib/hermione', () => { err.stateName = 'state-name'; hermione.emit(events[event], mkStubResult_({title: 'some-title', assertViewResults: [err]})); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addError.args[0][0].state, {name: 'some-title'}); }); @@ -185,7 +185,7 @@ describe('lib/hermione', () => { }); hermione.emit(events[event], testResult); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addFail.args[0][0].state, {name: 'some-title'}); }); @@ -197,7 +197,7 @@ describe('lib/hermione', () => { err.stateName = 'state-name'; hermione.emit(events[event], mkStubResult_({title: 'some-title', assertViewResults: [err]})); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.deepEqual(StaticReportBuilder.prototype.addFail.args[0][0].state, {name: 'some-title'}); }); @@ -210,7 +210,7 @@ describe('lib/hermione', () => { await initReporter_({path: '/absolute'}); const testData = mkStubResult_({assertViewResults: [{refImg: {path: 'ref/path'}, stateName: 'plain'}]}); hermione.emit(events.TEST_PASS, testData); - await hermione.emitAndWait(events.RUNNER_END); + await hermione.emitAsync(events.RUNNER_END); assert.calledOnceWith(utils.copyFileAsync, 'ref/path', 'report/plain', '/absolute'); }); @@ -223,7 +223,7 @@ describe('lib/hermione', () => { err.currImg = {path: 'current/path'}; hermione.emit(events.RETRY, mkStubResult_({assertViewResults: [err]})); - await hermione.emitAndWait(events.RUNNER_END); + await hermione.emitAsync(events.RUNNER_END); assert.calledOnceWith(utils.copyFileAsync, 'current/path', 'report/plain', '/absolute'); }); @@ -238,7 +238,7 @@ describe('lib/hermione', () => { err.refImg = {path: 'reference/path'}; hermione.emit(events.TEST_FAIL, mkStubResult_({assertViewResults: [err]})); - await hermione.emitAndWait(events.RUNNER_END); + await hermione.emitAsync(events.RUNNER_END); assert.calledWith(utils.copyFileAsync, 'reference/path', 'report/plain', '/absolute'); }); @@ -246,7 +246,7 @@ describe('lib/hermione', () => { it('should save current image from assert view fail', async () => { utils.getCurrentPath.callsFake((test, stateName) => `report/${stateName}`); await initReporter_({path: '/absolute'}); - await hermione.emitAndWait(events.RUNNER_START, { + await hermione.emitAsync(events.RUNNER_START, { registerWorkers: () => { return {saveDiffTo: sandbox.stub()}; } @@ -256,7 +256,7 @@ describe('lib/hermione', () => { err.currImg = {path: 'current/path'}; hermione.emit(events.TEST_FAIL, mkStubResult_({assertViewResults: [err]})); - await hermione.emitAndWait(events.RUNNER_END); + await hermione.emitAsync(events.RUNNER_END); assert.calledWith(utils.copyFileAsync, 'current/path', 'report/plain', '/absolute'); }); @@ -270,13 +270,13 @@ describe('lib/hermione', () => { await initReporter_(); - await hermione.emitAndWait(events.RUNNER_START, { + await hermione.emitAsync(events.RUNNER_START, { registerWorkers: () => { return {saveDiffTo}; } }); hermione.emit(events.TEST_FAIL, mkStubResult_({assertViewResults: [err]})); - await hermione.emitAndWait(events.RUNNER_END); + await hermione.emitAsync(events.RUNNER_END); assert.calledWith( saveDiffTo, sinon.match.instanceOf(ImageDiffError), sinon.match('/report/plain') diff --git a/test/unit/lib/gui/api/index.js b/test/unit/lib/gui/api/index.js index 71b082abf..cd2e2c853 100644 --- a/test/unit/lib/gui/api/index.js +++ b/test/unit/lib/gui/api/index.js @@ -1,6 +1,6 @@ 'use strict'; -const {EventEmitter} = require('events'); +const EventEmitter2 = require('eventemitter2'); const guiEvents = require('lib/gui/constants/gui-events'); const Api = require('lib/gui/api'); const {stubTool} = require('../../../utils'); @@ -12,7 +12,7 @@ describe('lig/gui/api', () => { Api.create(tool); - assert.instanceOf(tool.gui, EventEmitter); + assert.instanceOf(tool.gui, EventEmitter2); }); it('should add events to gui api', () => { diff --git a/test/unit/lib/gui/tool-runner/report-subsciber.js b/test/unit/lib/gui/tool-runner/report-subsciber.js index ebf2a6e8b..404094d52 100644 --- a/test/unit/lib/gui/tool-runner/report-subsciber.js +++ b/test/unit/lib/gui/tool-runner/report-subsciber.js @@ -46,7 +46,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportSubscriber(hermione, reportBuilder, client); - return hermione.emitAndWait(hermione.events.RUNNER_END) + return hermione.emitAsync(hermione.events.RUNNER_END) .then(() => assert.calledOnceWith(client.emit, clientEvents.END)); }); @@ -61,7 +61,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportSubscriber(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testResult); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.callOrder(mediator, client.emit.withArgs(clientEvents.END)); }); @@ -91,8 +91,8 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.format.withArgs(testData, hermione.events.TEST_PENDING).returns(formattedResult); reportSubscriber(hermione, reportBuilder, client); - hermione.emitAndWait(hermione.events.TEST_PENDING, testData); - await hermione.emitAndWait(hermione.events.RUNNER_END); + hermione.emitAsync(hermione.events.TEST_PENDING, testData); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.calledOnceWith(reportBuilder.addSkipped, formattedResult); }); @@ -106,8 +106,8 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportBuilder.getTestBranch.withArgs('some-id').returns('test-tree-branch'); reportSubscriber(hermione, reportBuilder, client); - hermione.emitAndWait(hermione.events.TEST_PENDING, testData); - await hermione.emitAndWait(hermione.events.RUNNER_END); + hermione.emitAsync(hermione.events.TEST_PENDING, testData); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.calledWith(client.emit, clientEvents.TEST_RESULT, 'test-tree-branch'); }); @@ -124,7 +124,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportSubscriber(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testData); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.calledWithMatch(reportBuilder.addFail, {attempt: 1}); }); @@ -138,7 +138,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportSubscriber(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testData); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.callOrder(formattedResult.saveTestImages, reportBuilder.addFail); }); @@ -153,7 +153,7 @@ describe('lib/gui/tool-runner/hermione/report-subscriber', () => { reportSubscriber(hermione, reportBuilder, client); hermione.emit(hermione.events.TEST_FAIL, testData); - await hermione.emitAndWait(hermione.events.RUNNER_END); + await hermione.emitAsync(hermione.events.RUNNER_END); assert.calledWith(client.emit, clientEvents.TEST_RESULT, 'test-tree-branch'); }); diff --git a/test/unit/lib/plugin-adapter.js b/test/unit/lib/plugin-adapter.js index dd343c92f..6dc0d65bc 100644 --- a/test/unit/lib/plugin-adapter.js +++ b/test/unit/lib/plugin-adapter.js @@ -38,7 +38,7 @@ describe('lib/plugin-adapter', () => { function initApiReporter_(opts) { initReporter_(opts); - return tool.emitAndWait(tool.events.INIT); + return tool.emitAsync(tool.events.INIT); } function initCliReporter_(opts, {command = 'foo'} = {}) { @@ -48,7 +48,7 @@ describe('lib/plugin-adapter', () => { tool.emit(tool.events.CLI, commander); commander.emit(`command:${command}`); - return tool.emitAndWait(tool.events.INIT); + return tool.emitAsync(tool.events.INIT); } function mkCommander_(commands = ['default-command']) { @@ -168,7 +168,7 @@ describe('lib/plugin-adapter', () => { .then(() => { tool.emit(tool.events.END); - return tool.emitAndWait(tool.events.RUNNER_END).then(() => { + return tool.emitAsync(tool.events.RUNNER_END).then(() => { assert.calledOnce(StaticReportBuilder.prototype.finalize); }); }); @@ -179,7 +179,7 @@ describe('lib/plugin-adapter', () => { .then(() => { tool.emit(tool.events.END); - return tool.emitAndWait(tool.events.RUNNER_END).then(() => { + return tool.emitAsync(tool.events.RUNNER_END).then(() => { assert.calledWithMatch(logger.log, 'some/path'); }); }); @@ -192,7 +192,7 @@ describe('lib/plugin-adapter', () => { .then(() => { tool.emit(tool.events.END); - return tool.emitAndWait(tool.events.RUNNER_END).then(() => { + return tool.emitAsync(tool.events.RUNNER_END).then(() => { assert.calledWith(logger.error, sinon.match('Html-reporter runtime error: some-error')); }); }); diff --git a/test/unit/utils.js b/test/unit/utils.js index a2c4a5c72..0bab474e7 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -1,7 +1,7 @@ 'use strict'; const _ = require('lodash'); -const {AsyncEmitter} = require('gemini-core').events; +const EventEmitter2 = require('eventemitter2'); function stubConfig(config = {}) { const browsers = config.browsers || {}; @@ -22,7 +22,7 @@ const stubTestCollection = (testsTree = {}) => { }; function stubTool(config = stubConfig(), events = {}, errors = {}, htmlReporter) { - const tool = new AsyncEmitter(); + const tool = new EventEmitter2(); tool.config = config; tool.events = events;