commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / bower_components / qunit / addons / junitlogger / junitlogger.js
1 (function() {
2 var count = 0, suiteCount = 0, currentSuite, currentTest, suites = [], assertCount, start, results = {failed:0, passed:0, total:0, time:0};
3
4 QUnit.jUnitReport = function(data) {
5 // Gets called when a report is generated
6 };
7
8 QUnit.moduleStart(function(data) {
9 currentSuite = {
10 name: data.name,
11 tests: [],
12 failures: 0,
13 time: 0,
14 stdout : '',
15 stderr : ''
16 };
17
18 suites.push(currentSuite);
19 });
20
21 QUnit.moduleDone(function(data) {
22 });
23
24 QUnit.testStart(function(data) {
25 if(!start){ start = new Date(); }
26
27 assertCount = 0;
28
29 currentTest = {
30 name: data.name,
31 failures: [],
32 start: new Date()
33 };
34
35 // Setup default suite if no module was specified
36 if (!currentSuite) {
37 currentSuite = {
38 name: "default",
39 tests: [],
40 failures: 0,
41 time: 0,
42 stdout : '',
43 stderr : ''
44 };
45
46 suites.push(currentSuite);
47 }
48
49 currentSuite.tests.push(currentTest);
50 });
51
52 QUnit.testDone(function(data) {
53 currentTest.failed = data.failed;
54 currentTest.total = data.total;
55 currentSuite.failures += data.failed;
56
57 results.failed += data.failed;
58 results.passed += data.passed;
59 results.total += data.total;
60 });
61
62 QUnit.log(function(data) {
63 assertCount++;
64
65 if (!data.result) {
66 currentTest.failures.push(data.message);
67
68 // Add log message of failure to make it easier to find in jenkins UI
69 currentSuite.stdout += '[' + currentSuite.name + ', ' + currentTest.name + ', ' + assertCount + '] ' + data.message + '\n';
70 }
71 });
72
73 QUnit.done(function(data) {
74 function ISODateString(d) {
75 function pad(n) {
76 return n < 10 ? '0' + n : n;
77 }
78
79 return d.getUTCFullYear() + '-' +
80 pad(d.getUTCMonth() + 1)+'-' +
81 pad(d.getUTCDate()) + 'T' +
82 pad(d.getUTCHours()) + ':' +
83 pad(d.getUTCMinutes()) + ':' +
84 pad(d.getUTCSeconds()) + 'Z';
85 }
86
87 // Generate XML report
88 var i, ti, fi, test, suite,
89 xmlWriter = new XmlWriter({
90 linebreak_at : "testsuites,testsuite,testcase,failure,system-out,system-err"
91 }),
92 now = new Date();
93
94 xmlWriter.start('testsuites');
95
96 for (i = 0; i < suites.length; i++) {
97 suite = suites[i];
98
99 // Calculate time
100 for (ti = 0; ti < suite.tests.length; ti++) {
101 test = suite.tests[ti];
102
103 test.time = (now.getTime() - test.start.getTime()) / 1000;
104 suite.time += test.time;
105 }
106
107 xmlWriter.start('testsuite', {
108 id: "" + i,
109 name: suite.name,
110 errors: "0",
111 failures: suite.failures,
112 hostname: "localhost",
113 tests: suite.tests.length,
114 time: Math.round(suite.time * 1000) / 1000,
115 timestamp: ISODateString(now)
116 });
117
118 for (ti = 0; ti < suite.tests.length; ti++) {
119 test = suite.tests[ti];
120
121 xmlWriter.start('testcase', {
122 name: test.name,
123 total: test.total,
124 failed: test.failed,
125 time: Math.round(test.time * 1000) / 1000
126 });
127
128 for (fi = 0; fi < test.failures.length; fi++) {
129 xmlWriter.start('failure', {type: "AssertionFailedError", message: test.failures[fi]}, true);
130 }
131
132 xmlWriter.end('testcase');
133 }
134
135 if (suite.stdout) {
136 xmlWriter.start('system-out');
137 xmlWriter.cdata('\n' + suite.stdout);
138 xmlWriter.end('system-out');
139 }
140
141 if (suite.stderr) {
142 xmlWriter.start('system-err');
143 xmlWriter.cdata('\n' + suite.stderr);
144 xmlWriter.end('system-err');
145 }
146
147 xmlWriter.end('testsuite');
148 }
149
150 xmlWriter.end('testsuites');
151
152 results.time = new Date() - start;
153
154 QUnit.jUnitReport({
155 results:results,
156 xml: xmlWriter.getString()
157 });
158 });
159
160 function XmlWriter(settings) {
161 function addLineBreak(name) {
162 if (lineBreakAt[name] && data[data.length - 1] !== '\n') {
163 data.push('\n');
164 }
165 }
166
167 function makeMap(items, delim, map) {
168 var i;
169
170 items = items || [];
171
172 if (typeof(items) === "string") {
173 items = items.split(',');
174 }
175
176 map = map || {};
177
178 i = items.length;
179 while (i--) {
180 map[items[i]] = {};
181 }
182
183 return map;
184 }
185
186 function encode(text) {
187 var baseEntities = {
188 '"' : '&quot;',
189 "'" : '&apos;',
190 '<' : '&lt;',
191 '>' : '&gt;',
192 '&' : '&amp;'
193 };
194
195 return ('' + text).replace(/[<>&\"\']/g, function(chr) {
196 return baseEntities[chr] || chr;
197 });
198 }
199
200 var data = [], stack = [], lineBreakAt;
201
202 settings = settings || {};
203 lineBreakAt = makeMap(settings.linebreak_at || 'mytag');
204
205 this.start = function(name, attrs, empty) {
206 if (!empty) {
207 stack.push(name);
208 }
209
210 data.push('<', name);
211
212 for (var aname in attrs) {
213 data.push(" " + encode(aname), '="', encode(attrs[aname]), '"');
214 }
215
216 data.push(empty ? ' />' : '>');
217 addLineBreak(name);
218 };
219
220 this.end = function(name) {
221 stack.pop();
222 addLineBreak(name);
223 data.push('</', name, '>');
224 addLineBreak(name);
225 };
226
227 this.text = function(text) {
228 data.push(encode(text));
229 };
230
231 this.cdata = function(text) {
232 data.push('<![CDATA[', text, ']]>');
233 };
234
235 this.comment = function(text) {
236 data.push('<!--', text, '-->');
237 };
238
239 this.pi = function(name, text) {
240 if (text) {
241 data.push('<?', name, ' ', text, '?>\n');
242 } else {
243 data.push('<?', name, '?>\n');
244 }
245 };
246
247 this.doctype = function(text) {
248 data.push('<!DOCTYPE', text, '>\n');
249 };
250
251 this.getString = function() {
252 for (var i = stack.length - 1; i >= 0; i--) {
253 this.end(stack[i]);
254 }
255
256 stack = [];
257
258 return data.join('').replace(/\n$/, '');
259 };
260
261 this.reset = function() {
262 data = [];
263 stack = [];
264 };
265
266 this.pi(settings.xmldecl || 'xml version="1.0" encoding="UTF-8"');
267 }
268 })();