|
1 | | -var module, moduleStart, testStart, testCases = [], |
2 | | - current_test_assertions = []; |
3 | | -console.log('<?xml version="1.0" encoding="UTF-8"?>'); |
4 | | -console.log('<testsuites name="testsuites">'); |
5 | | -QUnit.begin = function() { |
6 | | - // That does not work when invoked in PhantomJS |
7 | | -} |
| 1 | +/*global QUnit, console */ |
| 2 | +(function() { |
| 3 | + var module, moduleStart, testStart, testCases = [], current_test_assertions = []; |
| 4 | + console.log('<?xml version="1.0" encoding="UTF-8"?>'); |
| 5 | + console.log('<testsuites name="testsuites">'); |
8 | 6 |
|
9 | | -QUnit.moduleStart = function(context) { |
10 | | - moduleStart = new Date(); |
11 | | - module = context.name; |
12 | | - testCases = []; |
13 | | -} |
| 7 | + QUnit.begin(function() { |
| 8 | + // That does not work when invoked in PhantomJS |
| 9 | + }); |
14 | 10 |
|
15 | | -QUnit.moduleDone = function(context) { |
16 | | - // context = { name, failed, passed, total } |
17 | | - var xml = '\t<testsuite name="' + context.name + '" errors="0" failures="' + context.failed + '" tests="' + context.total + '" time="' + (new Date() - moduleStart) / 1000 + '"'; |
18 | | - if (testCases.length) { |
19 | | - xml += '>\n'; |
20 | | - for (var i = 0, l = testCases.length; i < l; i++) { |
21 | | - xml += testCases[i]; |
22 | | - } |
23 | | - xml += '\t</testsuite>'; |
24 | | - } else { |
25 | | - xml += '/>\n'; |
26 | | - } |
27 | | - console.log(xml); |
28 | | -} |
| 11 | + QUnit.moduleStart(function(context) { |
| 12 | + // context = { name } |
| 13 | + moduleStart = new Date(); |
| 14 | + module = context.name; |
| 15 | + testCases = []; |
| 16 | + }); |
29 | 17 |
|
30 | | -QUnit.testStart = function() { |
31 | | - testStart = new Date(); |
32 | | -} |
| 18 | + QUnit.moduleDone(function(context) { |
| 19 | + // context = { name, failed, passed, total } |
| 20 | + var xml = '\t<testsuite name="' + context.name + '" errors="0" failures="' + context.failed + '" tests="' + context.total + '" time="' + (new Date() - moduleStart) / 1000 + '"'; |
| 21 | + if (testCases.length) { |
| 22 | + xml += '>\n'; |
| 23 | + for (var i = 0, l = testCases.length; i < l; i++) { |
| 24 | + xml += testCases[i]; |
| 25 | + } |
| 26 | + xml += '\t</testsuite>'; |
| 27 | + } else { |
| 28 | + xml += '/>\n'; |
| 29 | + } |
| 30 | + console.log(xml); |
| 31 | + }); |
33 | 32 |
|
34 | | -QUnit.testDone = function(result) { |
35 | | - // result = { name, failed, passed, total } |
36 | | - var xml = '\t\t<testcase classname="' + module + '" name="' + result.name + '" time="' + (new Date() - testStart) / 1000 + '"'; |
37 | | - if (result.failed) { |
38 | | - xml += '>\n'; |
39 | | - for (var i = 0; i < current_test_assertions.length; i++) { |
40 | | - xml += "\t\t\t" + current_test_assertions[i]; |
41 | | - } |
42 | | - xml += '\t\t</testcase>\n'; |
43 | | - } else { |
44 | | - xml += '/>\n'; |
45 | | - } |
46 | | - current_test_assertions = []; |
47 | | - testCases.push(xml); |
48 | | -}; |
| 33 | + QUnit.testStart(function() { |
| 34 | + // context = { name } |
| 35 | + testStart = new Date(); |
| 36 | + }); |
49 | 37 |
|
50 | | -QUnit.log = function(details) { |
51 | | - //details = { result , actual, expected, message } |
52 | | - if (details.result) { |
53 | | - return; |
54 | | - } |
55 | | - var message = details.message || ""; |
56 | | - if (details.expected) { |
57 | | - if (message) { |
58 | | - message += ", "; |
59 | | - } |
60 | | - message = "expected: " + details.expected + ", but was: " + details.actual; |
61 | | - } |
62 | | - var xml = '<failure type="failed" message="' + message + '"/>\n' |
| 38 | + QUnit.testDone(function(result) { |
| 39 | + // result = { name, failed, passed, total } |
| 40 | + var xml = '\t\t<testcase classname="' + module + '" name="' + result.name + '" time="' + (new Date() - testStart) / 1000 + '"'; |
| 41 | + if (result.failed) { |
| 42 | + xml += '>\n'; |
| 43 | + for (var i = 0; i < current_test_assertions.length; i++) { |
| 44 | + xml += "\t\t\t" + current_test_assertions[i]; |
| 45 | + } |
| 46 | + xml += '\t\t</testcase>\n'; |
| 47 | + } else { |
| 48 | + xml += '/>\n'; |
| 49 | + } |
| 50 | + current_test_assertions = []; |
| 51 | + testCases.push(xml); |
| 52 | + }); |
63 | 53 |
|
64 | | - current_test_assertions.push(xml); |
65 | | -}; |
| 54 | + QUnit.log(function(details) { |
| 55 | + // details = { result, actual, expected, message } |
| 56 | + if (details.result) { |
| 57 | + return; |
| 58 | + } |
| 59 | + var message = details.message || ""; |
| 60 | + if (details.expected) { |
| 61 | + if (message) { |
| 62 | + message += ", "; |
| 63 | + } |
| 64 | + message += "expected: " + details.expected + ", but was: " + details.actual; |
| 65 | + } |
| 66 | + var xml = '<failure type="failed" message="' + message + '"/>\n'; |
66 | 67 |
|
67 | | -QUnit.done = function(result) { |
68 | | - console.log('</testsuites>'); |
69 | | - return result.failed > 0 ? 1 : 0; |
70 | | -}; |
| 68 | + current_test_assertions.push(xml); |
| 69 | + }); |
| 70 | + |
| 71 | + QUnit.done(function(result) { |
| 72 | + // result = { failed, passed, total, runtime } |
| 73 | + console.log('</testsuites>'); |
| 74 | + return result.failed > 0 ? 1 : 0; |
| 75 | + }); |
| 76 | +}()); |
0 commit comments