forked from 2gis/gemini-junit-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (64 loc) · 2.09 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
72
73
74
75
var builder = require('junit-report-builder');
var path = require('path');
function getTestName(testData, state) {
return [
testData.suite.fullName.trim(),
(state || testData.state).name.trim(),
testData.browserId.replace(/ /g, '')
].join('.').replace(/ /g, '_');
}
/**
* @param {object} gemini
* @param {object} options
* @param {string} options.path
*/
module.exports = function(gemini, options) {
var finishedTests = [];
var suite = builder.testSuite().name('Suite');
var testCases = {};
gemini.on('startRunner', function(runner) {
runner.on('beginState', function(data) {
var name = getTestName(data);
testCases[name] = suite.testCase()
.name(name)
.className(name);
});
runner.on('skipState', function(data) {
var name = getTestName(data);
testCases[name] = suite.testCase()
.name(name)
.className(name)
.skipped();
finishedTests.push(name);
});
runner.on('testResult', function(data) {
var name = getTestName(data);
if(data.equal !== true) {
testCases[name].failure();
}
finishedTests.push(name);
});
runner.on('err', function(data) {
if (data.state) {
failTest(data);
} else {
failAllSuiteTests(data);
}
function failTest(data, name) {
name = name || getTestName(data);
testCases[name].error(data.message);
}
function failAllSuiteTests(data) {
data.suite.states.forEach(function(state) {
var name = getTestName(data, state);
if (finishedTests.indexOf(name) === -1) {
failTest(data, name);
}
});
}
});
});
gemini.on('endRunner', function() {
builder.writeTo(path.join(options.path || '', 'gemini-junit-report.xml'));
});
};