Skip to content

Commit

Permalink
Merge pull request #1 from justyna-olszak-wttech/Custom-Xray-JSON-report
Browse files Browse the repository at this point in the history
Details for Xray format
  • Loading branch information
justyna-olszak-wttech committed Jan 5, 2022
2 parents e914db8 + 82f7567 commit 4a3e46b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
14 changes: 8 additions & 6 deletions core/command/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const allSettled = require('../util/allSettled');
const fs = require('../util/fs');
const logger = require('../util/logger')('report');
const compare = require('../util/compare/');
const writeXrayReport = require('../util/writeXrayReport');

function replaceInFile (file, search, replace) {
return new Promise((resolve, reject) => {
Expand All @@ -30,14 +31,15 @@ function writeReport (config, reporter) {

if (config.report && config.report.indexOf('CI') > -1 && config.ciReport.format === 'junit') {
promises.push(writeJunitReport(config, reporter));
} else if (config.report && config.report.indexOf('Xray') > -1) {
promises.push(writeXrayReport(config, reporter))
} else {
if (config.report && config.report.indexOf('json') > -1) {
promises.push(writeJsonReport(config, reporter));
}
promises.push(writeBrowserReport(config, reporter));
}

if (config.report && config.report.indexOf('json') > -1) {
promises.push(writeJsonReport(config, reporter));
}

promises.push(writeBrowserReport(config, reporter));

return allSettled(promises);
}

Expand Down
69 changes: 69 additions & 0 deletions core/util/writeXrayReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require('../util/fs');
const path = require('path');
const logger = require('../util/logger')('Xray report');
const _ = require('lodash');
const cloneDeep = require('lodash/cloneDeep');
const { stat } = require('fs');

module.exports = function (config, reporter) {
const jsonReporter = cloneDeep(reporter);

function toAbsolute (p) {
return path.isAbsolute(p) ? p : path.join(config.projectPath, p);
}

function transformTestCases (testCases) {
const transformedTestCases = [];

for (const testName in testCases) {
let testStatus = 'PASSED';
const testCase = testCases[testName];
const xrayTestResult = {
'iterations': [],
'testInfo': {}
};

testCase.forEach((testedViewport) => {
let { pair: { viewportLabel: name }, status } = testedViewport;

status = `${status}ed`.toUpperCase();
if (status === 'FAILED') {
testStatus = status;
}
xrayTestResult.iterations.push({ name, status });
});

xrayTestResult.status = testStatus;
xrayTestResult.testInfo.requirementKeys = testCase[0].pair.metadata;
xrayTestResult.testInfo.summary = testCase[0].pair.label;
xrayTestResult.testInfo.type = "Generic";
transformedTestCases.push(
xrayTestResult
);
}

return transformedTestCases;
}

function transformToXrayJson (json) {
const results = {}
const namedTestCases = _.groupBy(json, 'pair.label');
return results.tests = transformTestCases(namedTestCases);
}

logger.log('Writing Xray json report');

return fs.ensureDir(toAbsolute(config.json_report)).then(function () {
const res = transformToXrayJson(jsonReporter.tests);

return fs.writeFile(toAbsolute(config.compareJsonFileName), JSON.stringify(res, null, 2)).then(
function () {
logger.log('Wrote Xray Json report to: ' + toAbsolute(config.compareJsonFileName));
},
function (err) {
logger.error('Failed writing Xray Json report to: ' + toAbsolute(config.compareJsonFileName));
throw err;
}
);
});
};
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV \
RUN apt-get update && \
apt-get install -y git sudo software-properties-common

RUN sudo npm install -g --unsafe-perm=true --allow-root https://github.com/justyna-olszak-wttech/BackstopJS.git
RUN sudo npm install -g --unsafe-perm=true --allow-root https://github.com/justyna-olszak-wttech/BackstopJS.git#5.4.5

RUN wget https://dl-ssl.google.com/linux/linux_signing_key.pub && sudo apt-key add linux_signing_key.pub
RUN sudo add-apt-repository "deb http://dl.google.com/linux/chrome/deb/ stable main"
Expand Down

0 comments on commit 4a3e46b

Please sign in to comment.