-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (63 loc) · 1.56 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
'use strict';
function formatLoc(line, column) {
let res = '';
if (line) res += line;
if (column) res += ':' + column;
return res;
}
function formatRange(el) {
let res = '';
if (el.line || el.column) res += formatLoc(el.line, el.column);
if (el.endLine || el.endColumn) res += '-' + formatLoc(el.endLine, el.endColumn);
return res;
}
module.exports = results => {
let output = '';
let suitePassed = true;
let timestamp = new Date().toISOString();
let suiteId = '0';
results.forEach((result, i) => {
let filePath = result.filePath;
let testId = `${suiteId}.${i}`;
let testPassed = true;
result.messages.forEach((el, i) => {
let assertionId = `${testId}.${i}`;
let event = 'passed';
if (el.fatal || el.severity === 2) {
event = 'failed';
testPassed = false;
}
let source = filePath;
let range = formatRange(el);
if (range) source += ':' + range;
output += JSON.stringify({
kind: 'assertion',
event,
id: assertionId,
source,
message: el.message, // include el.ruleId?
timestamp,
});
output += '\n';
});
output += JSON.stringify({
kind: 'test',
event: testPassed ? 'passed' : 'failed',
id: testId,
source: filePath,
timestamp,
});
output += '\n';
if (!testPassed) {
suitePassed = false;
}
});
output += JSON.stringify({
kind: 'suite',
event: suitePassed ? 'passed' : 'failed',
id: suiteId,
timestamp,
});
output += '\n';
return output;
};