diff --git a/core/command/report.js b/core/command/report.js index c999efe31..b13a16880 100644 --- a/core/command/report.js +++ b/core/command/report.js @@ -25,17 +25,24 @@ function replaceInFile (file, search, replace) { }); } -async function processCustomReport (config, reporter) { +async function processCustomReports (config, reporter) { const engineScriptsPath = config.engine_scripts; - const customReport = config.customReport; - if (customReport) { - const customReportScript = path.resolve(engineScriptsPath, customReport.script); - if (fs.existsSync(customReportScript)) { - return await require(customReportScript)(config, reporter); - } else { - console.warn('WARNING: reporting script not found: ' + customReportScript); + const customReports = config.customReports.reports; + const results = []; + + if (customReports) { + for (let i = 0; i < customReports.length; i++) { + const customReportScript = path.resolve(engineScriptsPath, customReports[i].script); + + if (fs.existsSync(customReportScript)) { + const res = await require(customReportScript)(config, reporter, customReports[i].name); + results.push(res); + } else { + console.warn('WARNING: reporting script not found: ' + customReportScript); + } } } + return results; } function writeReport (config, reporter) { @@ -50,7 +57,7 @@ function writeReport (config, reporter) { } promises.push(writeBrowserReport(config, reporter)); - promises.push(processCustomReport(config, reporter)); + promises.push(processCustomReports(config, reporter)); return allSettled(promises); } diff --git a/core/util/extendConfig.js b/core/util/extendConfig.js index fd91ecd38..18ec429e9 100644 --- a/core/util/extendConfig.js +++ b/core/util/extendConfig.js @@ -23,7 +23,7 @@ function extendConfig (config, userConfig) { config.asyncCompareLimit = userConfig.asyncCompareLimit; config.backstopVersion = version; config.dockerCommandTemplate = userConfig.dockerCommandTemplate; - config.customReport = userConfig.customReport; + config.customReports = userConfig.customReports; return config; } diff --git a/test/configs/backstop.json b/test/configs/backstop.json index ef2a839b8..682306a14 100644 --- a/test/configs/backstop.json +++ b/test/configs/backstop.json @@ -47,10 +47,14 @@ "engineOptions": { "args": ["--no-sandbox"] }, - "customReport": { - "script": "customReports/xrayReport.js", - "reportLocation": "backstop_data/xray_report", - "reportName": "xrayReport.json" + "customReports": { + "reports": [ + { + "script": "customReports/xrayReport.js", + "name": "xrayReport.json" + } + ], + "reportLocation": "backstop_data/custom_report" }, "asyncCaptureLimit": 5, "asyncCompareLimit": 50, diff --git a/test/configs/backstop_data/engine_scripts/customReports/xrayReport.js b/test/configs/backstop_data/engine_scripts/customReports/xrayReport.js index 07fd82aa2..580c20f07 100644 --- a/test/configs/backstop_data/engine_scripts/customReports/xrayReport.js +++ b/test/configs/backstop_data/engine_scripts/customReports/xrayReport.js @@ -5,7 +5,7 @@ const _ = require('lodash'); const cloneDeep = require('lodash/cloneDeep'); const util = require('util'); -module.exports = function (config, reporter) { +module.exports = function (config, reporter, resultName) { function toAbsolute (p) { return path.isAbsolute(p) ? p : path.join(config.projectPath, p); @@ -58,9 +58,9 @@ module.exports = function (config, reporter) { const ensureDirPromise = util.promisify(ensureDir); const writeFilePromise = util.promisify(writeFile); - return ensureDirPromise(toAbsolute(config.customReport.reportLocation)).then(function () { + return ensureDirPromise(toAbsolute(config.customReports.reportLocation)).then(function () { const res = transformToXrayJson(jsonReporter.tests); - const reportPath = toAbsolute(path.join(config.customReport.reportLocation, config.customReport.reportName)); + const reportPath = toAbsolute(path.join(config.customReports.reportLocation, resultName)); return writeFilePromise(reportPath, JSON.stringify(res, null, 2)).then( function () {