Writing the suites out to separate xml files with the option to consolidate into one file per top level suite...

This commit is contained in:
Kelvin Luck 2013-01-08 13:09:05 +00:00
parent ef8f191c46
commit f19d07a209
3 changed files with 143 additions and 84 deletions

View File

@ -208,17 +208,42 @@ module.exports = function(grunt) {
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) {
if (options.junit.consolidate) {
grunt.util._(junitData.consolidatedSuites).each(
function(suites)
{
grunt.file.copy(runners.junit, path.join(options.junit.path, suites[0].name.replace(/[^\w]/g, '') + '-TEST.xml'), {
process: function(src) {
return grunt.util._.template(
src,
{
testsuites: junitData
testsuites: suites
}
);
}
})
}
);
} else {
junitData.suites.forEach(
function(suiteData)
{
grunt.file.copy(runners.junit, path.join(options.junit.path, suiteData.name.replace(/[^\w]/g, '') + '-TEST.xml'), {
process: function(src) {
return grunt.util._.template(
src,
{
testsuites: [suiteData]
}
);
}
})
}
);
}
}
});
phantomjs.on('jasmine.done',function(elapsed){

View File

@ -13,6 +13,16 @@
return names.join(' ');
}
function getTopLevelSuiteId(suite)
{
var id;
while (suite) {
id = suite.id;
suite = suite.parentSuite;
}
return id;
}
jasmine.JUnitDataReporter = function()
{
@ -22,11 +32,13 @@
reportRunnerStarting: function(runner) {
},
reportRunnerResults: function(runner) {
var suites = runner.suites().map(
var suitesById = {},
suites = runner.suites().map(
function(suite)
{
var failures = 0,
data = {
topLevelSuiteId: getTopLevelSuiteId(suite),
name: getNestedSuiteName(suite),
time: suite.duration / 1000,
timestamp: suite.timestamp,
@ -58,6 +70,7 @@
)
};
data.failures = failures;
suitesById[suite.id] = data;
return data;
}
);

View File

@ -204,8 +204,19 @@
return names.join(' ');
}
function getTopLevelSuiteId(suite)
{
var id;
while (suite) {
id = suite.id;
suite = suite.parentSuite;
}
return id;
}
PhantomReporter.prototype.generateJUnitSummary_ = function(runner) {
return runner.suites().map(
var consolidatedSuites = {},
suites = runner.suites().map(
function(suite)
{
var failures = 0,
@ -241,9 +252,19 @@
)
};
data.failures = failures;
if (suite.parentSuite) {
consolidatedSuites[getTopLevelSuiteId(suite)].push(data);
} else {
consolidatedSuites[suite.id] = [data];
}
return data;
}
);
return {
suites: suites,
consolidatedSuites: consolidatedSuites
};
};
jasmine.getEnv().addReporter( new PhantomReporter() );