Skip to content

Commit

Permalink
Details for Xray format
Browse files Browse the repository at this point in the history
  • Loading branch information
justyna-olszak-wttech committed Jan 4, 2022
1 parent e914db8 commit 82f7567
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
15 changes: 9 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,16 @@ 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) {
logger.log('Initialize Xray report');
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 = [];
let testStatus = 'PASSED';

for (const testName in testCases) {
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;
}
);
});
};

0 comments on commit 82f7567

Please sign in to comment.