-
-
Save noonat/234693 to your computer and use it in GitHub Desktop.
JUnit XML output for JSpec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Output: | |
<?xml version="1.0" encoding="UTF-8"?> | |
<testsuites> | |
<testsuite name="core.events" tests="2" assertions="2" failures="0" specs="2"> | |
<testcase name="should be an instance of QueuedEventPool" assertions="1"/> | |
<testcase name="should have the correct name" assertions="1"/> | |
</testsuite> | |
... | |
</testsuites> | |
*/ | |
(function(){ | |
JSpec.include({ | |
name: 'JUnit', | |
formatters: { | |
JUnitXml: function(results, options) { | |
var w = new java.io.FileWriter('jspec.xml'); | |
w.write('<?xml version="1.0" encoding="UTF-8"?>\n'); | |
w.write('<testsuites>\n'); | |
JSpec.each(results.allSuites, function(suite) { | |
var attribs = { | |
name: suite.description, | |
tests: suite.specs.length, | |
assertions: 0, | |
failures: 0, | |
specs: 0}; | |
var content = JSpec.inject(suite.specs, '', function(content, spec) { | |
attribs.assertions += spec.assertions.length; | |
attribs.failures += spec.passed() ? 0 : 1; | |
attribs.specs += 1; | |
return content +' <testcase name="'+spec.description+'" assertions="'+spec.assertions.length+'"/>\n'; | |
}); | |
w.write(' <testsuite'); | |
for (var key in attribs) { | |
w.write(' ' + key + '="' + attribs[key] + '"'); | |
} | |
w.write('>\n'); | |
w.write(content); | |
w.write(' </testsuite>\n'); | |
}); | |
w.write('</testsuites>\n'); | |
w.close(); | |
quit(results.stats.failures); | |
} | |
} | |
}); | |
})(); | |
... | |
function runSuites() { | |
JSpec | |
.exec('spec.js') | |
.run({ formatter : JSpec.formatters.JUnitXML }) | |
.report(); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment