Generating an XML file from a template based on the run specs...

This commit is contained in:
Kelvin Luck 2013-01-07 23:04:44 +00:00
parent a6fd38da1b
commit 28189d7f05
2 changed files with 34 additions and 6 deletions

View File

@ -32,7 +32,8 @@ module.exports = function(grunt) {
var runners = { var runners = {
default : __dirname + '/jasmine/templates/DefaultRunner.tmpl', default : __dirname + '/jasmine/templates/DefaultRunner.tmpl',
requirejs : __dirname + '/jasmine/templates/RequireJSRunner.tmpl' requirejs : __dirname + '/jasmine/templates/RequireJSRunner.tmpl',
junit : __dirname + '/jasmine/templates/JUnit.tmpl'
}; };
var runnerOptions = { var runnerOptions = {
@ -53,7 +54,8 @@ module.exports = function(grunt) {
host : '', host : '',
template: 'default', template: 'default',
templateOptions : {}, templateOptions : {},
phantomjs : {} phantomjs : {},
junit: {}
}); });
grunt.util._.defaults(options.templateOptions, runnerOptions[options.template] || {}); grunt.util._.defaults(options.templateOptions, runnerOptions[options.template] || {});
@ -204,6 +206,21 @@ module.exports = function(grunt) {
status.skipped += skippedAssertions; status.skipped += skippedAssertions;
}); });
phantomjs.on('jasmine.reportJUnitResults',function(junitData){
if (options.junit && options.junit.path) {
grunt.file.copy(runners.junit, path.join(options.junit.path,'out-TEST.xml'), {
process : function(src) {
return grunt.util._.template(
src,
{
testsuites: junitData
}
);
}
})
}
});
phantomjs.on('jasmine.done',function(elapsed){ phantomjs.on('jasmine.done',function(elapsed){
phantomjs.halt(); phantomjs.halt();
status.duration = elapsed; status.duration = elapsed;
@ -219,7 +236,4 @@ module.exports = function(grunt) {
}); });
} }
}; };

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuites>
<% testsuites.forEach(function(testsuite) { %>
<testsuite name="<%- testsuite.name %>" errors="<%= testsuite.errors %>" tests="<%= testsuite.tests %>" failures="<%= testsuite.failures %>" time="<%= testsuite.time %>" timestamp="<%= testsuite.timestamp %>">
<% testsuite.testcases.forEach(function(testcase) { %>
<testcase classname="<%- testcase.classname %>" name="<%- testcase.name %>" time="<%= testcase.time %>">
<% if (testcase.failureMessage) { %>
<failure><%= testsuite.failureMessage %></failure>
<% } %>
</testcase>
<% }) %>
</testsuite>
<% }) %>
</testsuites>