Merge pull request #759 from n1k0/fix-gecko-unit
Fix XUnit output with Gecko (@laurentj) - closes #753 #754
Showing
4 changed files
with
41 additions
and
9 deletions
... | @@ -1619,7 +1619,7 @@ Tester.prototype.saveResults = function saveResults(filepath) { | ... | @@ -1619,7 +1619,7 @@ Tester.prototype.saveResults = function saveResults(filepath) { |
1619 | var exporter = require('xunit').create(); | 1619 | var exporter = require('xunit').create(); |
1620 | exporter.setResults(this.suiteResults); | 1620 | exporter.setResults(this.suiteResults); |
1621 | try { | 1621 | try { |
1622 | fs.write(filepath, exporter.getXML(), 'w'); | 1622 | fs.write(filepath, exporter.getSerializedXML(), 'w'); |
1623 | this.casper.echo(f('Result log stored in %s', filepath), 'INFO', 80); | 1623 | this.casper.echo(f('Result log stored in %s', filepath), 'INFO', 80); |
1624 | } catch (e) { | 1624 | } catch (e) { |
1625 | this.casper.echo(f('Unable to write results to %s: %s', filepath, e), 'ERROR', 80); | 1625 | this.casper.echo(f('Unable to write results to %s: %s', filepath, e), 'ERROR', 80); | ... | ... |
... | @@ -82,10 +82,6 @@ function XUnitExporter() { | ... | @@ -82,10 +82,6 @@ function XUnitExporter() { |
82 | "use strict"; | 82 | "use strict"; |
83 | this.results = undefined; | 83 | this.results = undefined; |
84 | this._xml = utils.node('testsuites'); | 84 | this._xml = utils.node('testsuites'); |
85 | this._xml.toString = function toString() { | ||
86 | var serializer = new XMLSerializer(); | ||
87 | return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this); | ||
88 | }; | ||
89 | } | 85 | } |
90 | exports.XUnitExporter = XUnitExporter; | 86 | exports.XUnitExporter = XUnitExporter; |
91 | 87 | ||
... | @@ -158,6 +154,17 @@ XUnitExporter.prototype.getXML = function getXML() { | ... | @@ -158,6 +154,17 @@ XUnitExporter.prototype.getXML = function getXML() { |
158 | }; | 154 | }; |
159 | 155 | ||
160 | /** | 156 | /** |
157 | * Retrieves generated Xunit XML | ||
158 | * | ||
159 | * @return string | ||
160 | */ | ||
161 | XUnitExporter.prototype.getSerializedXML = function getSerializedXML(xml) { | ||
162 | "use strict"; | ||
163 | var serializer = new XMLSerializer(); | ||
164 | return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this.getXML()); | ||
165 | } | ||
166 | |||
167 | /** | ||
161 | * Sets test results. | 168 | * Sets test results. |
162 | * | 169 | * |
163 | * @param TestSuite results | 170 | * @param TestSuite results | ... | ... |
... | @@ -408,5 +408,30 @@ class TestCommandOutputTest(CasperExecTestBase): | ... | @@ -408,5 +408,30 @@ class TestCommandOutputTest(CasperExecTestBase): |
408 | ], failing=True) | 408 | ], failing=True) |
409 | 409 | ||
410 | 410 | ||
411 | class XUnitReportTest(CasperExecTestBase): | ||
412 | XUNIT_LOG = os.path.join(TEST_ROOT, '__log.xml') | ||
413 | |||
414 | def setUp(self): | ||
415 | self.clean() | ||
416 | |||
417 | def tearDown(self): | ||
418 | self.clean() | ||
419 | |||
420 | def clean(self): | ||
421 | if os.path.exists(self.XUNIT_LOG): | ||
422 | os.remove(self.XUNIT_LOG) | ||
423 | |||
424 | def test_xunit_report_passing(self): | ||
425 | script_path = os.path.join(TEST_ROOT, 'tester', 'passing.js') | ||
426 | command = 'test %s --xunit=%s' % (script_path, self.XUNIT_LOG) | ||
427 | self.runCommand(command, failing=False) | ||
428 | self.assertTrue(os.path.exists(self.XUNIT_LOG)) | ||
429 | |||
430 | def test_xunit_report_failing(self): | ||
431 | script_path = os.path.join(TEST_ROOT, 'tester', 'failing.js') | ||
432 | command = 'test %s --xunit=%s' % (script_path, self.XUNIT_LOG) | ||
433 | self.runCommand(command, failing=True) | ||
434 | self.assertTrue(os.path.exists(self.XUNIT_LOG)) | ||
435 | |||
411 | if __name__ == '__main__': | 436 | if __name__ == '__main__': |
412 | unittest.main() | 437 | unittest.main() | ... | ... |
... | @@ -7,7 +7,7 @@ casper.test.begin('XUnitReporter() initialization', 1, function suite(test) { | ... | @@ -7,7 +7,7 @@ casper.test.begin('XUnitReporter() initialization', 1, function suite(test) { |
7 | var xunit = require('xunit').create(); | 7 | var xunit = require('xunit').create(); |
8 | var results = new tester.TestSuiteResult(); | 8 | var results = new tester.TestSuiteResult(); |
9 | xunit.setResults(results); | 9 | xunit.setResults(results); |
10 | test.assertTruthy(xunit.getXML()); | 10 | test.assertTruthy(xunit.getSerializedXML()); |
11 | test.done(); | 11 | test.done(); |
12 | }); | 12 | }); |
13 | 13 | ||
... | @@ -25,7 +25,7 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite(test | ... | @@ -25,7 +25,7 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite(test |
25 | }); | 25 | }); |
26 | results.push(suite2); | 26 | results.push(suite2); |
27 | xunit.setResults(results); | 27 | xunit.setResults(results); |
28 | casper.start().setContent(xunit.getXML()); | 28 | casper.start().setContent(xunit.getSerializedXML()); |
29 | test.assertEvalEquals(function() { | 29 | test.assertEvalEquals(function() { |
30 | return __utils__.findAll('testsuite').length; | 30 | return __utils__.findAll('testsuite').length; |
31 | }, 2); | 31 | }, 2); |
... | @@ -50,7 +50,7 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f | ... | @@ -50,7 +50,7 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f |
50 | }); | 50 | }); |
51 | results.push(suite1); | 51 | results.push(suite1); |
52 | xunit.setResults(results); | 52 | xunit.setResults(results); |
53 | casper.start().setContent(xunit.getXML()); | 53 | casper.start().setContent(xunit.getSerializedXML()); |
54 | test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'); | 54 | test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'); |
55 | test.done(); | 55 | test.done(); |
56 | }); | 56 | }); |
... | @@ -70,7 +70,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite( | ... | @@ -70,7 +70,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite( |
70 | }); | 70 | }); |
71 | results.push(suite1); | 71 | results.push(suite1); |
72 | xunit.setResults(results); | 72 | xunit.setResults(results); |
73 | casper.start().setContent(xunit.getXML()); | 73 | casper.start().setContent(xunit.getSerializedXML()); |
74 | test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'); | 74 | test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'); |
75 | test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); | 75 | test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); |
76 | test.done(); | 76 | test.done(); | ... | ... |
-
Please register or sign in to post a comment