From 82f75673b2ab1656a1229a18dfca2db9fbfdd9c4 Mon Sep 17 00:00:00 2001 From: Justyna Olszak Date: Mon, 3 Jan 2022 14:56:08 +0100 Subject: [PATCH] Details for Xray format --- core/command/report.js | 15 ++++---- core/util/writeXrayReport.js | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 core/util/writeXrayReport.js diff --git a/core/command/report.js b/core/command/report.js index 0bbd25093..086274736 100644 --- a/core/command/report.js +++ b/core/command/report.js @@ -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) => { @@ -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); } diff --git a/core/util/writeXrayReport.js b/core/util/writeXrayReport.js new file mode 100644 index 000000000..3224f4a57 --- /dev/null +++ b/core/util/writeXrayReport.js @@ -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; + } + ); + }); +};