Skip to content

Commit

Permalink
feat: use EventEmitter2 instead of AsyncEmitter from gemini-core
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn committed Aug 30, 2022
1 parent 4d666ae commit 3c41ab7
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 40 deletions.
4 changes: 2 additions & 2 deletions lib/gui/api/facade.js
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/gui/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
4 changes: 2 additions & 2 deletions lib/plugin-api.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 15 additions & 15 deletions test/unit/hermione.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand All @@ -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()};
}
Expand Down Expand Up @@ -138,15 +138,15 @@ 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'});
});

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'});
});
Expand All @@ -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'});
});
Expand All @@ -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'});
});
Expand All @@ -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'});
});
Expand All @@ -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'});
});
Expand All @@ -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');
});
Expand All @@ -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');
});
Expand All @@ -238,15 +238,15 @@ 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');
});

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()};
}
Expand All @@ -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');
});
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/gui/api/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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', () => {
Expand Down
18 changes: 9 additions & 9 deletions test/unit/lib/gui/tool-runner/report-subsciber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

Expand All @@ -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));
});
Expand Down Expand Up @@ -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);
});
Expand All @@ -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');
});
Expand All @@ -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});
});
Expand All @@ -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);
});
Expand All @@ -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');
});
Expand Down
10 changes: 5 additions & 5 deletions test/unit/lib/plugin-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'} = {}) {
Expand All @@ -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']) {
Expand Down Expand Up @@ -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);
});
});
Expand All @@ -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');
});
});
Expand All @@ -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'));
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/utils.js
Original file line number Diff line number Diff line change
@@ -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 || {};
Expand All @@ -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;
Expand Down

0 comments on commit 3c41ab7

Please sign in to comment.