Skip to content

Commit

Permalink
feat(reporter): add useBrowserName parameter
Browse files Browse the repository at this point in the history
I use one browser to test my javascript and do not need browser name in report file name and class name.
  • Loading branch information
Nikita Shirin committed Oct 20, 2015
1 parent d9660d8 commit 2327234
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = function(config) {
junitReporter: {
outputDir: '', // results will be saved as $outputDir/$browserName.xml
outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: '' // suite will become the package name attribute in xml testsuite element
suite: '', // suite will become the package name attribute in xml testsuite element
useBrowserName: true // add browser name to report and classes names
}
});
};
Expand Down
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
var pkgName = reporterConfig.suite || ''
var outputDir = reporterConfig.outputDir
var outputFile = reporterConfig.outputFile
var useBrowserName = reporterConfig.useBrowserName

var suites
var pendingFileWritings = 0
Expand All @@ -21,6 +22,10 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for

outputDir = helper.normalizeWinPath(path.resolve(config.basePath, outputDir)) + path.sep

if (typeof useBrowserName === 'undefined') {
useBrowserName = true
}

baseReporterDecorator(this)

this.adapters = [
Expand All @@ -46,10 +51,13 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
var safeBrowserName = browser.name.replace(/ /g, '_')
var newOutputFile
if (outputFile != null) {
var dir = path.join(outputDir, safeBrowserName)
var dir = useBrowserName ? path.join(outputDir, safeBrowserName)
: outputDir
newOutputFile = path.join(dir, outputFile)
} else {
} else if (useBrowserName) {
newOutputFile = path.join(outputDir, 'TESTS-' + safeBrowserName + '.xml')
} else {
newOutputFile = path.join(outputDir, 'TESTS.xml')
}

var xmlToOutput = suites[browser.id]
Expand All @@ -73,6 +81,12 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
})
}

var getClassName = function (browser, result) {
var browserName = browser.name.replace(/ /g, '_').replace(/\./g, '_') + '.'

return (useBrowserName ? browserName : '') + (pkgName ? pkgName + '.' : '') + result.suite[0]
}

this.onRunStart = function (browsers) {
suites = Object.create(null)

Expand Down Expand Up @@ -110,7 +124,7 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
this.specSuccess = this.specSkipped = this.specFailure = function (browser, result) {
var spec = suites[browser.id].ele('testcase', {
name: result.description, time: ((result.time || 0) / 1000),
classname: browser.name.replace(/ /g, '_').replace(/\./g, '_') + '.' + (pkgName ? pkgName + '.' : '') + result.suite[0]
classname: getClassName(browser, result)
})

if (result.skipped) {
Expand Down

0 comments on commit 2327234

Please sign in to comment.