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) { ...@@ -91,12 +91,18 @@ XUnitExporter.prototype.addFailure = function(classname, name, message, type) {
91 * @return String 91 * @return String
92 */ 92 */
93 function generateClassName(classname) { 93 function generateClassName(classname) {
94 classname = classname.replace(phantom.casperPath, "").trim();
94 var script = classname || phantom.casperScript; 95 var script = classname || phantom.casperScript;
95 if (script.indexOf(fs.workingDirectory) === 0) { 96 if (script.indexOf(fs.workingDirectory) === 0) {
96 script = script.substring(fs.workingDirectory.length + 1); 97 script = script.substring(fs.workingDirectory.length + 1);
97 return script.substring(0, script.lastIndexOf('.'));
98 } 98 }
99 return classname || "unknown"; 99 if (script.indexOf('/') === 0) {
100 script = script.substring(1, script.length);
101 }
102 if (~script.indexOf('.')) {
103 script = script.substring(0, script.lastIndexOf('.'));
104 }
105 return script || "unknown";
100 } 106 }
101 107
102 /** 108 /**
......
...@@ -7,7 +7,10 @@ xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz'); ...@@ -7,7 +7,10 @@ xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz');
7 casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase'); 7 casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase');
8 8
9 // named classname 9 // named classname
10 xunit = require('xunit').create();
10 xunit.addSuccess(require('fs').workingDirectory + '/plop.js', 'It worked'); 11 xunit.addSuccess(require('fs').workingDirectory + '/plop.js', 'It worked');
11 casper.test.assertMatch(xunit.getXML(), /<testcase classname="plop" name="It worked"/, 'XUnitExporter.addSuccess() handles class name'); 12 casper.test.assertMatch(xunit.getXML(), /<testcase classname="plop" name="It worked"/, 'XUnitExporter.addSuccess() handles class name');
13 xunit.addSuccess(require('fs').workingDirectory + '/plip.js', 'Failure');
14 casper.test.assertMatch(xunit.getXML(), /<testcase classname="plip" name="Failure"/, 'XUnitExporter.addFailure() handles class name');
12 15
13 casper.test.done(); 16 casper.test.done();
...\ No newline at end of file ...\ No newline at end of file
......