forked from gemini-testing/html-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemini.js
79 lines (59 loc) · 2.6 KB
/
gemini.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
const Promise = require('bluebird');
const PluginAdapter = require('./lib/plugin-adapter');
const utils = require('./lib/server-utils');
const {saveTestImages} = require('./lib/reporter-helpers');
module.exports = (gemini, opts) => {
const plugin = PluginAdapter.create(gemini, opts, 'gemini');
if (!plugin.isEnabled()) {
return;
}
plugin
.addApi()
.addCliCommands()
.init(prepareData, prepareImages);
};
function prepareData(gemini, reportBuilder) {
return new Promise((resolve) => {
gemini.on(gemini.events.SKIP_STATE, (result) => reportBuilder.addSkipped(result));
gemini.on(gemini.events.TEST_RESULT, (result) => {
return result.equal ? reportBuilder.addSuccess(result) : reportBuilder.addFail(result);
});
gemini.on(gemini.events.UPDATE_RESULT, (result) => reportBuilder.addSuccess(result));
gemini.on(gemini.events.RETRY, (result) => reportBuilder.addRetry(result));
gemini.on(gemini.events.ERROR, (result) => reportBuilder.addError(result));
gemini.on(gemini.events.END, (stats) => resolve(
reportBuilder
.setStats(stats)
.setApiValues(gemini.htmlReporter.values)
));
});
}
function prepareImages(gemini, pluginConfig, reportBuilder) {
const {path: reportPath} = pluginConfig;
function handleErrorEvent(result) {
const src = result.getCurrImg().path || result.getErrImg().path;
return src && utils.copyImageAsync(src, utils.getCurrentAbsolutePath(result, reportPath));
}
return new Promise((resolve, reject) => {
let queue = Promise.resolve();
gemini.on(gemini.events.ERROR, (testResult) => {
queue = queue.then(() => handleErrorEvent(reportBuilder.format(testResult)));
});
gemini.on(gemini.events.RETRY, (testResult) => {
const formattedResult = reportBuilder.format(testResult);
queue = queue.then(() => {
return formattedResult.hasDiff()
? saveTestImages(formattedResult, reportPath)
: handleErrorEvent(formattedResult);
});
});
gemini.on(gemini.events.TEST_RESULT, (testResult) => {
queue = queue.then(() => saveTestImages(reportBuilder.format(testResult), reportPath));
});
gemini.on(gemini.events.UPDATE_RESULT, (testResult) => {
queue = queue.then(() => saveTestImages(reportBuilder.format(testResult), reportPath));
});
gemini.on(gemini.events.END, () => queue.then(resolve, reject));
});
}