diff --git a/index.js b/index.js index 0252186..f3bf7b8 100644 --- a/index.js +++ b/index.js @@ -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')); @@ -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 diff --git a/test.zip b/test.zip new file mode 100644 index 0000000..7a2932e Binary files /dev/null and b/test.zip differ