forked from DHI/karma-vsts-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (72 loc) · 1.97 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
76
77
78
79
80
81
82
const path = require("path");
const fs = require("fs");
const mkpath = require("mkpath");
const trx = require("./trx").trx;
const VstsReporter = function(baseReporterDecorator, config, formatError) {
baseReporterDecorator(this);
let testResults;
let messages = [];
const outputDir =
config.vstsReporter && config.vstsReporter.outputDir
? config.vstsReporter.outputDir
: "coverage-vsts";
const outputFile =
config.vstsReporter && config.vstsReporter.outputFile
? config.vstsReporter.outputFile
: "coverage-${date}.xml";
this.onRunStart = function(browsers) {
testResults = {
name: path.join(
outputDir,
outputFile.replace(
"${date}",
new Date().toISOString().replace(/:/g, "")
)
),
agent: {},
specs: []
};
};
this.onBrowserStart = function(browser) {
testResults.agent = {
id: browser.id,
name: browser.name,
fullName: browser.fullName
};
};
this.specSuccess = this.specSkipped = this.specFailure = function(
browser,
result
) {
messages.push(result);
const now = Date.now();
testResults.specs.push({
id: result.id,
suite: result.suite.length
? result.suite.join(" ")
: "Results not in a list",
description: result.description,
start: new Date(now),
finish: new Date(now + result.time),
time: result.time,
outcome: result.skipped
? "NotExecuted"
: result.success
? "Passed"
: "Failed",
message: result.log.join("\n"),
stackTrace: result.log.join("\n")
});
};
this.onBrowserComplete = function(browser) {};
this.onRunComplete = function() {};
this.onExit = function(done) {
mkpath.sync(outputDir);
fs.writeFileSync(testResults.name, trx(testResults));
done();
};
};
VstsReporter.$inject = ["baseReporterDecorator", "config", "formatError"];
module.exports = {
"reporter:vsts": ["type", VstsReporter]
};