Skip to content

Commit

Permalink
Multiple custom reports
Browse files Browse the repository at this point in the history
  • Loading branch information
justyna-olszak-wttech committed Jan 17, 2022
1 parent 4788b30 commit 0649e32
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
25 changes: 16 additions & 9 deletions core/command/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/util/extendConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 0 additions & 6 deletions test/configs/backstop.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"selectorExpansion": true,
"misMatchThreshold": 0.1,
"requireSameDimensions": true,
"metadata": ["TEST-1"]
}
],
"paths": {
Expand All @@ -47,11 +46,6 @@
"engineOptions": {
"args": ["--no-sandbox"]
},
"customReport": {
"script": "customReports/xrayReport.js",
"reportLocation": "backstop_data/xray_report",
"reportName": "xrayReport.json"
},
"asyncCaptureLimit": 5,
"asyncCompareLimit": 50,
"debug": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 0649e32

Please sign in to comment.