Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sonarqube JUnit XML format #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var JUnitReporter = function(baseReporterDecorator, config, logger, helper, form
var log = logger.create('reporter.junit');
var reporterConfig = config.junitReporter || {};
var pkgName = reporterConfig.suite || '';
var sonarFormatFlg = reporterConfig.sonarFormatFlg || false;
var outputFile = helper.normalizeWinPath(path.resolve(config.basePath, reporterConfig.outputFile
|| 'test-results.xml'));

Expand Down Expand Up @@ -84,22 +85,35 @@ var JUnitReporter = function(baseReporterDecorator, config, logger, helper, form
suites = xml = null;
allMessages.length = 0;
};

this.specSuccess = this.specSkipped = this.specFailure = function(browser, result) {
var spec = suites[browser.id].ele('testcase', {
function getSpec(browser,result){
return suites[browser.id].ele('testcase', {
name: result.description, time: ((result.time || 0) / 1000),
classname: (pkgName ? pkgName + ' ' : '') + browser.name + '.' + result.suite.join(' ').replace(/\./g, '_')
});

if (result.skipped) {
spec.ele('skipped');
}

if (!result.success) {
result.log.forEach(function(err) {
spec.ele('failure', {type: ''}, formatError(err));
});
}
}
this.specSuccess = this.specSkipped = this.specFailure = function(browser, result) {
if(!sonarFormatFlg) {
var spec = getSpec(browser, result);
if (result.skipped) {
spec.ele('skipped');
}
if (!result.success) {
result.log.forEach(function(err) {
spec.ele('failure', {type: ''}, formatError(err));
});
}
}else {
if (result.skipped) {
var spec = getSpec(browser, result);
spec.ele('skipped');
}
if (!result.success) {
result.log.forEach(function(err) {
var spec = getSpec(browser, result);
spec.ele('failure', {message: 'Failure'}, formatError(err));
});
}
}
};

// wait for writing all the xml files, before exiting
Expand Down
Binary file added test.zip
Binary file not shown.