Commit e8e17db0 e8e17db0519e379da8b280c9c0a0a5da6a1611a5 by Nicolas Perriault

fixes #48 - XML Output file doesn't have classpath populated with file name

1 parent 062eba7b
......@@ -91,12 +91,18 @@ XUnitExporter.prototype.addFailure = function(classname, name, message, type) {
* @return String
*/
function generateClassName(classname) {
classname = classname.replace(phantom.casperPath, "").trim();
var script = classname || phantom.casperScript;
if (script.indexOf(fs.workingDirectory) === 0) {
script = script.substring(fs.workingDirectory.length + 1);
return script.substring(0, script.lastIndexOf('.'));
}
return classname || "unknown";
if (script.indexOf('/') === 0) {
script = script.substring(1, script.length);
}
if (~script.indexOf('.')) {
script = script.substring(0, script.lastIndexOf('.'));
}
return script || "unknown";
}
/**
......
......@@ -7,7 +7,10 @@ xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz');
casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase');
// named classname
xunit = require('xunit').create();
xunit.addSuccess(require('fs').workingDirectory + '/plop.js', 'It worked');
casper.test.assertMatch(xunit.getXML(), /<testcase classname="plop" name="It worked"/, 'XUnitExporter.addSuccess() handles class name');
xunit.addSuccess(require('fs').workingDirectory + '/plip.js', 'Failure');
casper.test.assertMatch(xunit.getXML(), /<testcase classname="plip" name="Failure"/, 'XUnitExporter.addFailure() handles class name');
casper.test.done();
\ No newline at end of file
......