-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
150 lines (123 loc) · 4.85 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Adapted from the Karma junit reporter
var os = require('os');
var path = require('path');
var fs = require('fs');
var builder = require('xmlbuilder');
var moment = require('moment');
var CDashReporter = function (baseReporterDecorator, config, logger, helper, formatError) {
var log = logger.create('reporter.xml');
var reporterConfig = config.cdashReporter || {};
// CDash site config for report
var siteConfigPath = helper.normalizeWinPath(path.resolve(config.basePath, reporterConfig.siteConfig));
var cdashConfig = JSON.parse(fs.readFileSync(siteConfigPath, 'utf8'));
var siteConfig = cdashConfig.site;
var testConfig = cdashConfig.testConfig;
// output file
var outputFileName = reporterConfig.outputFileName || ('cdash-result' + (siteConfig.BuildStamp ? '-' + siteConfig.BuildStamp : '') + '.xml');
var outputFilePath = (reporterConfig.outputFolder || '.') + '/' + outputFileName;
var outputFile = helper.normalizeWinPath(path.resolve(config.basePath, outputFilePath));
var site;
var testing;
var testList;
var startTime;
var pendingFileWritings = 0;
var fileWritingFinished = function () { };
var allMessages = [];
baseReporterDecorator(this);
this.adapters = [function (msg) {
allMessages.push(msg);
}];
this.onRunStart = function () {
site = builder.create('Site',
{version: '1.0', encoding: 'UTF-8'}); // XML root
site.att('BuildName', siteConfig.BuildName);
site.att('BuildStamp', siteConfig.BuildStamp);
site.att('Name', siteConfig.Name);
site.att('Generator', siteConfig.Generator);
site.att('CompilerName', siteConfig.CompilerName);
site.att('OSName', siteConfig.OSName);
site.att('Hostname', siteConfig.Hostname);
site.att('OSRelease', siteConfig.OSRelease);
site.att('OSVersion', siteConfig.OSVersion);
site.att('OSPlatform', siteConfig.OSPlatform);
site.att('Is64Bits', siteConfig.Is64Bits);
site.att('VendorString', siteConfig.VendorString);
site.att('VendorID', siteConfig.VendorID);
site.att('FamilyID', siteConfig.FamilyID);
site.att('ModelID', siteConfig.ModelID);
site.att('ProcessorCacheSize', siteConfig.ProcessorCacheSize);
site.att('NumberOfLogicalCPU', siteConfig.NumberOfLogicalCPU);
site.att('NumberOfPhysicalCPU', siteConfig.NumberOfPhysicalCPU);
site.att('TotalVirtualMemory', siteConfig.TotalVirtualMemory);
site.att('TotalPhysicalMemory', siteConfig.TotalPhysicalMemory);
site.att('LogicalProcessorsPerPhysical', siteConfig.LogicalProcessorsPerPhysical);
site.att('ProcessorClockFrequency', siteConfig.ProcessorClockFrequency);
// TODO: set attibutes to the site node
testing = site.ele('Testing');
startTime = moment();
testing.ele('StartTestTime', startTime.format('X'));
testing.ele('StartDateTime', startTime.format('MMM D HH:mm Z')); //TODO display timezone in letters
testList = testing.ele('TestList');
};
this.onBrowserStart = function(browser) {
};
this.onBrowserComplete = function(browser) {
};
this.onRunComplete = function () {
var endTime = moment();
testing.ele('EndTestTime', endTime.format('X'));
testing.ele('EndDateTime', endTime.format('MMM D HH:mm Z'));
testing.ele('ElapsedMinutes', (endTime.diff(startTime, 'minutes')).toString());
var xmlToOutput = site;
pendingFileWritings++;
helper.mkdirIfNotExists(path.dirname(outputFile), function () {
fs.writeFile(outputFile, xmlToOutput.end({ pretty: true }), function (err) {
if (err) {
log.warn('Cannot write xml\n\t' + err.message);
} else {
log.debug('XML results written to "%s".', outputFile);
}
if (!--pendingFileWritings) {
fileWritingFinished();
}
});
});
allMessages.length = 0;
};
this.specSuccess = this.specSkipped = this.specFailure = function (browser, result) { //for each test
var testFullName = result.suite + ' ' + result.description + ' (' + browser.name + ')';
var pass;
if (result.success) {
pass = 'passed';
}
else if (result.skipped) {
pass = 'skipped';
}
else { // Test failed
pass = 'failed';
}
testList.ele('Test', testFullName);
var test = testing.ele('Test');
test.att('Status', pass);
test.ele('Name', result.description);
test.ele('FullName', testFullName);
test.ele('Path', testConfig.Path);
test.ele('FullCommandLine', testConfig.FullCommandLine);
test.ele('Results', pass);
};
// wait for writing all the xml files, before exiting
this.onExit = function (done) {
if (pendingFileWritings) {
fileWritingFinished = done;
} else {
done();
}
};
this.makeTestNode = function() {
}
};
CDashReporter.$inject = ['baseReporterDecorator', 'config', 'logger', 'helper', 'formatError'];
// PUBLISH DI MODULE
module.exports = {
'reporter:cdash': ['type', CDashReporter]
};