Skip to content

Commit 0649e32

Browse files
Multiple custom reports
1 parent 4788b30 commit 0649e32

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

core/command/report.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@ function replaceInFile (file, search, replace) {
2525
});
2626
}
2727

28-
async function processCustomReport (config, reporter) {
28+
async function processCustomReports (config, reporter) {
2929
const engineScriptsPath = config.engine_scripts;
30-
const customReport = config.customReport;
31-
if (customReport) {
32-
const customReportScript = path.resolve(engineScriptsPath, customReport.script);
33-
if (fs.existsSync(customReportScript)) {
34-
return await require(customReportScript)(config, reporter);
35-
} else {
36-
console.warn('WARNING: reporting script not found: ' + customReportScript);
30+
const customReports = config.customReports.reports;
31+
const results = [];
32+
33+
if (customReports) {
34+
for (let i = 0; i < customReports.length; i++) {
35+
const customReportScript = path.resolve(engineScriptsPath, customReports[i].script);
36+
37+
if (fs.existsSync(customReportScript)) {
38+
const res = await require(customReportScript)(config, reporter, customReports[i].name);
39+
results.push(res);
40+
} else {
41+
console.warn('WARNING: reporting script not found: ' + customReportScript);
42+
}
3743
}
3844
}
45+
return results;
3946
}
4047

4148
function writeReport (config, reporter) {
@@ -50,7 +57,7 @@ function writeReport (config, reporter) {
5057
}
5158

5259
promises.push(writeBrowserReport(config, reporter));
53-
promises.push(processCustomReport(config, reporter));
60+
promises.push(processCustomReports(config, reporter));
5461

5562
return allSettled(promises);
5663
}

core/util/extendConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function extendConfig (config, userConfig) {
2323
config.asyncCompareLimit = userConfig.asyncCompareLimit;
2424
config.backstopVersion = version;
2525
config.dockerCommandTemplate = userConfig.dockerCommandTemplate;
26-
config.customReport = userConfig.customReport;
26+
config.customReports = userConfig.customReports;
2727
return config;
2828
}
2929

test/configs/backstop.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"selectorExpansion": true,
3333
"misMatchThreshold": 0.1,
3434
"requireSameDimensions": true,
35-
"metadata": ["TEST-1"]
3635
}
3736
],
3837
"paths": {
@@ -47,11 +46,6 @@
4746
"engineOptions": {
4847
"args": ["--no-sandbox"]
4948
},
50-
"customReport": {
51-
"script": "customReports/xrayReport.js",
52-
"reportLocation": "backstop_data/xray_report",
53-
"reportName": "xrayReport.json"
54-
},
5549
"asyncCaptureLimit": 5,
5650
"asyncCompareLimit": 50,
5751
"debug": false,

test/configs/backstop_data/engine_scripts/customReports/xrayReport.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const _ = require('lodash');
55
const cloneDeep = require('lodash/cloneDeep');
66
const util = require('util');
77

8-
module.exports = function (config, reporter) {
8+
module.exports = function (config, reporter, resultName) {
99

1010
function toAbsolute (p) {
1111
return path.isAbsolute(p) ? p : path.join(config.projectPath, p);
@@ -58,9 +58,9 @@ module.exports = function (config, reporter) {
5858
const ensureDirPromise = util.promisify(ensureDir);
5959
const writeFilePromise = util.promisify(writeFile);
6060

61-
return ensureDirPromise(toAbsolute(config.customReport.reportLocation)).then(function () {
61+
return ensureDirPromise(toAbsolute(config.customReports.reportLocation)).then(function () {
6262
const res = transformToXrayJson(jsonReporter.tests);
63-
const reportPath = toAbsolute(path.join(config.customReport.reportLocation, config.customReport.reportName));
63+
const reportPath = toAbsolute(path.join(config.customReports.reportLocation, resultName));
6464

6565
return writeFilePromise(reportPath, JSON.stringify(res, null, 2)).then(
6666
function () {

0 commit comments

Comments
 (0)