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:
parent
ef8f191c46
commit
f19d07a209
@ -208,16 +208,41 @@ 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) {
|
||||
return grunt.util._.template(
|
||||
src,
|
||||
|
||||
if (options.junit.consolidate) {
|
||||
|
||||
grunt.util._(junitData.consolidatedSuites).each(
|
||||
function(suites)
|
||||
{
|
||||
testsuites: junitData
|
||||
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: 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]
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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,45 +32,48 @@
|
||||
reportRunnerStarting: function(runner) {
|
||||
},
|
||||
reportRunnerResults: function(runner) {
|
||||
var suites = runner.suites().map(
|
||||
function(suite)
|
||||
{
|
||||
var failures = 0,
|
||||
data = {
|
||||
name: getNestedSuiteName(suite),
|
||||
time: suite.duration / 1000,
|
||||
timestamp: suite.timestamp,
|
||||
tests: suite.specs().length,
|
||||
errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things
|
||||
testcases: suite.specs().map(
|
||||
function(spec)
|
||||
{
|
||||
var failureMessages = [];
|
||||
if (spec.results().failedCount) {
|
||||
failures ++;
|
||||
spec.results().items_.forEach(
|
||||
function(expectation)
|
||||
{
|
||||
if (!expectation.passed()) {
|
||||
failureMessages.push(expectation.message);
|
||||
}
|
||||
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,
|
||||
tests: suite.specs().length,
|
||||
errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things
|
||||
testcases: suite.specs().map(
|
||||
function(spec)
|
||||
{
|
||||
var failureMessages = [];
|
||||
if (spec.results().failedCount) {
|
||||
failures ++;
|
||||
spec.results().items_.forEach(
|
||||
function(expectation)
|
||||
{
|
||||
if (!expectation.passed()) {
|
||||
failureMessages.push(expectation.message);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
return {
|
||||
assertions: spec.results().items_.length,
|
||||
className: getNestedSuiteName(spec.suite),
|
||||
name: spec.description,
|
||||
time: spec.duration / 1000,
|
||||
failureMessages: failureMessages
|
||||
};
|
||||
}
|
||||
)
|
||||
};
|
||||
data.failures = failures;
|
||||
return data;
|
||||
}
|
||||
);
|
||||
return {
|
||||
assertions: spec.results().items_.length,
|
||||
className: getNestedSuiteName(spec.suite),
|
||||
name: spec.description,
|
||||
time: spec.duration / 1000,
|
||||
failureMessages: failureMessages
|
||||
};
|
||||
}
|
||||
)
|
||||
};
|
||||
data.failures = failures;
|
||||
suitesById[suite.id] = data;
|
||||
return data;
|
||||
}
|
||||
);
|
||||
console.log('Suites:', suites);
|
||||
},
|
||||
reportSuiteResults: function(suite) {
|
||||
|
@ -204,46 +204,67 @@
|
||||
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(
|
||||
function(suite)
|
||||
{
|
||||
var failures = 0,
|
||||
data = {
|
||||
name: getNestedSuiteName(suite),
|
||||
time: suite.duration / 1000,
|
||||
timestamp: suite.timestamp,
|
||||
tests: suite.specs().length,
|
||||
errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things
|
||||
testcases: suite.specs().map(
|
||||
function(spec)
|
||||
{
|
||||
var failureMessages = [];
|
||||
if (spec.results().failedCount) {
|
||||
failures ++;
|
||||
spec.results().items_.forEach(
|
||||
function(expectation)
|
||||
{
|
||||
if (!expectation.passed()) {
|
||||
failureMessages.push(expectation.message);
|
||||
}
|
||||
var consolidatedSuites = {},
|
||||
suites = runner.suites().map(
|
||||
function(suite)
|
||||
{
|
||||
var failures = 0,
|
||||
data = {
|
||||
name: getNestedSuiteName(suite),
|
||||
time: suite.duration / 1000,
|
||||
timestamp: suite.timestamp,
|
||||
tests: suite.specs().length,
|
||||
errors: 0, // TODO: These exist in the JUnit XML but not sure how they map to jasmine things
|
||||
testcases: suite.specs().map(
|
||||
function(spec)
|
||||
{
|
||||
var failureMessages = [];
|
||||
if (spec.results().failedCount) {
|
||||
failures ++;
|
||||
spec.results().items_.forEach(
|
||||
function(expectation)
|
||||
{
|
||||
if (!expectation.passed()) {
|
||||
failureMessages.push(expectation.message);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
return {
|
||||
assertions: spec.results().items_.length,
|
||||
className: getNestedSuiteName(spec.suite),
|
||||
name: spec.description,
|
||||
time: spec.duration / 1000,
|
||||
failureMessages: failureMessages
|
||||
};
|
||||
}
|
||||
)
|
||||
};
|
||||
data.failures = failures;
|
||||
return data;
|
||||
}
|
||||
);
|
||||
return {
|
||||
assertions: spec.results().items_.length,
|
||||
className: getNestedSuiteName(spec.suite),
|
||||
name: spec.description,
|
||||
time: spec.duration / 1000,
|
||||
failureMessages: failureMessages
|
||||
};
|
||||
}
|
||||
)
|
||||
};
|
||||
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() );
|
||||
|
Loading…
Reference in New Issue
Block a user