Commit 57c41923 57c419236dda01390569a56b922068eb96309cd8 by Nicolas Perriault

Merge pull request #759 from n1k0/fix-gecko-unit

Fix XUnit output with Gecko (@laurentj) - closes #753 #754
2 parents dc4dbf15 b959e8ce
......@@ -1619,7 +1619,7 @@ Tester.prototype.saveResults = function saveResults(filepath) {
var exporter = require('xunit').create();
exporter.setResults(this.suiteResults);
try {
fs.write(filepath, exporter.getXML(), 'w');
fs.write(filepath, exporter.getSerializedXML(), 'w');
this.casper.echo(f('Result log stored in %s', filepath), 'INFO', 80);
} catch (e) {
this.casper.echo(f('Unable to write results to %s: %s', filepath, e), 'ERROR', 80);
......
......@@ -82,10 +82,6 @@ function XUnitExporter() {
"use strict";
this.results = undefined;
this._xml = utils.node('testsuites');
this._xml.toString = function toString() {
var serializer = new XMLSerializer();
return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this);
};
}
exports.XUnitExporter = XUnitExporter;
......@@ -158,6 +154,17 @@ XUnitExporter.prototype.getXML = function getXML() {
};
/**
* Retrieves generated Xunit XML
*
* @return string
*/
XUnitExporter.prototype.getSerializedXML = function getSerializedXML(xml) {
"use strict";
var serializer = new XMLSerializer();
return '<?xml version="1.0" encoding="UTF-8"?>' + serializer.serializeToString(this.getXML());
}
/**
* Sets test results.
*
* @param TestSuite results
......
......@@ -408,5 +408,30 @@ class TestCommandOutputTest(CasperExecTestBase):
], failing=True)
class XUnitReportTest(CasperExecTestBase):
XUNIT_LOG = os.path.join(TEST_ROOT, '__log.xml')
def setUp(self):
self.clean()
def tearDown(self):
self.clean()
def clean(self):
if os.path.exists(self.XUNIT_LOG):
os.remove(self.XUNIT_LOG)
def test_xunit_report_passing(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'passing.js')
command = 'test %s --xunit=%s' % (script_path, self.XUNIT_LOG)
self.runCommand(command, failing=False)
self.assertTrue(os.path.exists(self.XUNIT_LOG))
def test_xunit_report_failing(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'failing.js')
command = 'test %s --xunit=%s' % (script_path, self.XUNIT_LOG)
self.runCommand(command, failing=True)
self.assertTrue(os.path.exists(self.XUNIT_LOG))
if __name__ == '__main__':
unittest.main()
......
......@@ -7,7 +7,7 @@ casper.test.begin('XUnitReporter() initialization', 1, function suite(test) {
var xunit = require('xunit').create();
var results = new tester.TestSuiteResult();
xunit.setResults(results);
test.assertTruthy(xunit.getXML());
test.assertTruthy(xunit.getSerializedXML());
test.done();
});
......@@ -25,7 +25,7 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite(test
});
results.push(suite2);
xunit.setResults(results);
casper.start().setContent(xunit.getXML());
casper.start().setContent(xunit.getSerializedXML());
test.assertEvalEquals(function() {
return __utils__.findAll('testsuite').length;
}, 2);
......@@ -50,7 +50,7 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f
});
results.push(suite1);
xunit.setResults(results);
casper.start().setContent(xunit.getXML());
casper.start().setContent(xunit.getSerializedXML());
test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]');
test.done();
});
......@@ -70,7 +70,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(
});
results.push(suite1);
xunit.setResults(results);
casper.start().setContent(xunit.getXML());
casper.start().setContent(xunit.getSerializedXML());
test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]');
test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
test.done();
......