Skip to content

Commit ba13f29

Browse files
authored
Merge pull request #435 from gemini-testing/HERMIONE-113.add-report-saved-event
feat: add REPORT_SAVED event
2 parents 24d3b34 + cd16aa6 commit ba13f29

File tree

10 files changed

+53
-10
lines changed

10 files changed

+53
-10
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ Property name | Description
534534
Event | Description
535535
------------------------- | -------------
536536
`DATABASE_CREATED` | Will be triggered after sqlite database is created. The handler accepts a database instance. The event is synchronous.
537-
`TEST_SCREENSHOTS_SAVED` | Will be triggered after test screenshots were saved. The handler accepts test id and screenshots info. The event is synchronous.
537+
`TEST_SCREENSHOTS_SAVED` | Will be triggered after test screenshots were saved. The handler accepts test id and screenshots info. The event is asynchronous, so your handler can return a promise.
538+
`REPORT_SAVED` | Will be triggered after all test files were saved. The event is asynchronous, so your handler can return a promise.
538539
539540
### events
540541
@@ -558,7 +559,7 @@ module.exports = (hermione, opts) => {
558559
Example of a subscription to an event `TEST_SCREENSHOTS_SAVED`:
559560
560561
```js
561-
hermione.htmlReporter.on(hermione.htmlReporter.events.TEST_SCREENSHOTS_SAVED, ({testId, attempt, imagesInfo}) => {
562+
hermione.htmlReporter.on(hermione.htmlReporter.events.TEST_SCREENSHOTS_SAVED, async ({testId, attempt, imagesInfo}) => {
562563
console.log(`Screenshots for test "${testId}" (attempt #${attempt}) were saved:`, imagesInfo);
563564
/* Expected output:
564565
Screenshots for test "Feature Test.chrome-desktop" (attempt #0) were saved:
@@ -578,6 +579,13 @@ hermione.htmlReporter.on(hermione.htmlReporter.events.TEST_SCREENSHOTS_SAVED, ({
578579
});
579580
```
580581
582+
Example of a subscription to an event `REPORT_SAVED`:
583+
```js
584+
hermione.htmlReporter.on(hermione.htmlReporter.events.REPORT_SAVED, async ({reportPath}) => {
585+
await uploadDirToS3(reportPath);
586+
});
587+
```
588+
581589
### addExtraItem
582590
583591
Adds item to html report as link:

lib/constants/plugin-events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const getSyncEvents = () => ({
44
DATABASE_CREATED: 'databaseCreated',
5-
TEST_SCREENSHOTS_SAVED: 'testScreenshotsSaved'
5+
TEST_SCREENSHOTS_SAVED: 'testScreenshotsSaved',
6+
REPORT_SAVED: 'reportSaved'
67
});
78

89
const events = getSyncEvents();

lib/merge-reports/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module.exports = async (pluginConfig, hermione, srcPaths, {destination: destPath
99
serverUtils.saveStaticFilesToReportDir(hermione, pluginConfig, destPath),
1010
serverUtils.writeDatabaseUrlsFile(destPath, srcPaths)
1111
]);
12+
13+
await hermione.htmlReporter.emitAsync(hermione.htmlReporter.events.REPORT_SAVED, {reportPath: destPath});
1214
};
1315

1416
function validateOpts(srcPaths, destPath) {

lib/plugin-adapter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ module.exports = class PluginAdapter {
5555
staticReportBuilder.saveStaticFiles(),
5656
prepareData(this._hermione, staticReportBuilder, this._config)
5757
])
58-
.then(() => staticReportBuilder.finalize());
58+
.then(() => staticReportBuilder.finalize())
59+
.then(async () => {
60+
const htmlReporter = this._hermione.htmlReporter;
61+
62+
await htmlReporter.emitAsync(htmlReporter.events.REPORT_SAVED, {reportPath: this._config.path});
63+
});
5964
}
6065

6166
async _run(prepareData) {

lib/plugin-api.js

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

3-
const EventsEmitter = require('events');
3+
const EventsEmitter2 = require('eventemitter2');
44
const pluginEvents = require('./constants/plugin-events');
55
const {downloadDatabases, mergeDatabases, getTestsTreeFromDatabase} = require('./db-utils/server');
66

7-
module.exports = class HtmlReporter extends EventsEmitter {
7+
module.exports = class HtmlReporter extends EventsEmitter2 {
88
static create(config) {
99
return new this(config);
1010
}

lib/test-adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ module.exports = class TestAdapter {
368368
}
369369

370370
const htmlReporter = this._hermione.htmlReporter;
371-
htmlReporter.emit(htmlReporter.events.TEST_SCREENSHOTS_SAVED, {
371+
await htmlReporter.emitAsync(htmlReporter.events.TEST_SCREENSHOTS_SAVED, {
372372
testId: this._testId,
373373
attempt: this.attempt,
374374
imagesInfo: this.getImagesInfo()

test/unit/lib/merge-reports/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const serverUtils = require('lib/server-utils');
77

88
describe('lib/merge-reports', () => {
99
const sandbox = sinon.sandbox.create();
10+
let htmlReporter;
1011

1112
const execMergeReports_ = async ({pluginConfig = stubConfig(), hermione = stubTool(stubConfig()), paths = [], opts = {}}) => {
1213
opts = _.defaults(opts, {destination: 'default-dest-report/path'});
@@ -17,6 +18,10 @@ describe('lib/merge-reports', () => {
1718
beforeEach(() => {
1819
sandbox.stub(serverUtils, 'saveStaticFilesToReportDir').resolves();
1920
sandbox.stub(serverUtils, 'writeDatabaseUrlsFile').resolves();
21+
22+
htmlReporter = sinon.stub();
23+
htmlReporter.events = {REPORT_SAVED: 'reportSaved'};
24+
htmlReporter.emitAsync = sinon.stub();
2025
});
2126

2227
afterEach(() => sandbox.restore());
@@ -39,7 +44,7 @@ describe('lib/merge-reports', () => {
3944

4045
it('should merge reports', async () => {
4146
const pluginConfig = stubConfig();
42-
const hermione = stubTool(pluginConfig);
47+
const hermione = stubTool(pluginConfig, {}, {}, htmlReporter);
4348
const paths = ['src-report/path-1', 'src-report/path-2'];
4449
const destination = 'dest-report/path';
4550

@@ -48,4 +53,13 @@ describe('lib/merge-reports', () => {
4853
assert.calledOnceWith(serverUtils.saveStaticFilesToReportDir, hermione, pluginConfig, destination);
4954
assert.calledOnceWith(serverUtils.writeDatabaseUrlsFile, destination, paths);
5055
});
56+
57+
it('should emit REPORT_SAVED event', async () => {
58+
const hermione = stubTool({}, {}, {}, htmlReporter);
59+
const destination = 'dest-report/path';
60+
61+
await execMergeReports_({pluginConfig: {}, hermione, paths: [''], opts: {destination}});
62+
63+
assert.calledOnceWith(hermione.htmlReporter.emitAsync, 'reportSaved', {reportPath: destination});
64+
});
5165
});

test/unit/lib/plugin-adapter.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ describe('lib/plugin-adapter', () => {
174174
});
175175
});
176176

177+
it('should emit REPORT_SAVED event', async () => {
178+
await initCliReporter_({path: '/some/report/path'}, {});
179+
180+
tool.emit(tool.events.END);
181+
await tool.emitAsync(tool.events.RUNNER_END);
182+
183+
assert.calledOnceWith(tool.htmlReporter.emitAsync, 'reportSaved', {reportPath: '/some/report/path'});
184+
});
185+
177186
it('should log correct path to html report', () => {
178187
return initCliReporter_({path: 'some/path'}, {})
179188
.then(() => {

test/unit/lib/test-adapter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('hermione test adapter', () => {
3232
Object.assign({
3333
imagesSaver: {saveImg: sandbox.stub()},
3434
events: {TEST_SCREENSHOTS_SAVED: 'testScreenshotsSaved'},
35-
emit: sinon.stub()
35+
emitAsync: sinon.stub()
3636
}, htmlReporter)
3737
);
3838

@@ -308,7 +308,7 @@ describe('hermione test adapter', () => {
308308
const htmlReporterEmitStub = sinon.stub();
309309
const hermioneTestAdapter = mkHermioneTestResultAdapter(testResult, {
310310
htmlReporter: {
311-
emit: htmlReporterEmitStub
311+
emitAsync: htmlReporterEmitStub
312312
}
313313
});
314314
sinon.stub(hermioneTestAdapter, 'getImagesInfo').returns([{test: 123}]);

test/unit/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function stubTool(config = stubConfig(), events = {}, errors = {}, htmlReporter)
3131
tool.run = sinon.stub().resolves(false);
3232
tool.readTests = sinon.stub().resolves(stubTestCollection());
3333
tool.htmlReporter = htmlReporter || sinon.stub();
34+
_.defaultsDeep(tool.htmlReporter, {
35+
emitAsync: sinon.stub(),
36+
events: {REPORT_SAVED: 'reportSaved'}
37+
});
3438
tool.isWorker = () => {
3539
return false;
3640
};

0 commit comments

Comments
 (0)