From 23272345692de95f3637d622def38360ce924a03 Mon Sep 17 00:00:00 2001 From: Nikita Shirin Date: Thu, 15 Oct 2015 23:14:00 +0300 Subject: [PATCH] feat(reporter): add useBrowserName parameter I use one browser to test my javascript and do not need browser name in report file name and class name. --- README.md | 3 ++- index.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c7447c4..cb3fd0c 100644 --- a/README.md +++ b/README.md @@ -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 } }); }; diff --git a/index.js b/index.js index 0723629..86b74fe 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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 = [ @@ -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] @@ -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) @@ -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) {