-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
71 lines (55 loc) · 1.82 KB
/
index.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
'use strict';
const _ = require('lodash');
const path = require('path');
const fs = require('fs-extra');
const parseConfig = require('./lib/config');
const StreamWriter = require('./lib/stream-writer');
module.exports = (testplane, opts) => {
const pluginConfig = parseConfig(opts);
if (!pluginConfig.enabled) {
return;
}
let writeStream;
const retriesMap = _(testplane.config.getBrowserIds())
.zipObject()
.mapValues(() => new Map())
.value();
testplane.on(testplane.events.RUNNER_START, () => {
writeStream = StreamWriter.create(pluginConfig.path);
});
testplane.on(testplane.events.RETRY, (test) => {
const fullTitle = test.fullTitle();
const retries = retriesMap[test.browserId];
const retry = retries.get(fullTitle) || 0;
retries.set(fullTitle, retry + 1);
});
testplane.on(testplane.events.TEST_BEGIN, (test) => {
if (test.pending) {
return;
}
test.timeStart = Date.now();
const retry = retriesMap[test.browserId].get(test.fullTitle());
if (retry) {
test.retry = retry;
}
});
testplane.on(testplane.events.TEST_END, (test) => {
if (test.pending) {
return;
}
test.timeEnd = Date.now();
writeStream.write(test);
});
testplane.on(testplane.events.ERROR, () => writeStream.end());
testplane.on(testplane.events.RUNNER_END, () => {
writeStream.end();
copyToReportDir(pluginConfig.path, ['index.html', 'bundle.min.js', 'styles.css']);
});
};
function copyToReportDir(reportDir, files) {
files.forEach((fileName) => {
const from = path.join(__dirname, 'lib', 'static', fileName);
const to = path.join(reportDir, fileName);
fs.copySync(from, to);
});
}