Skip to content

Commit 4a3e46b

Browse files
Merge pull request #1 from justyna-olszak-wttech/Custom-Xray-JSON-report
Details for Xray format
2 parents e914db8 + 82f7567 commit 4a3e46b

3 files changed

Lines changed: 78 additions & 7 deletions

File tree

core/command/report.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const allSettled = require('../util/allSettled');
77
const fs = require('../util/fs');
88
const logger = require('../util/logger')('report');
99
const compare = require('../util/compare/');
10+
const writeXrayReport = require('../util/writeXrayReport');
1011

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

3132
if (config.report && config.report.indexOf('CI') > -1 && config.ciReport.format === 'junit') {
3233
promises.push(writeJunitReport(config, reporter));
34+
} else if (config.report && config.report.indexOf('Xray') > -1) {
35+
promises.push(writeXrayReport(config, reporter))
36+
} else {
37+
if (config.report && config.report.indexOf('json') > -1) {
38+
promises.push(writeJsonReport(config, reporter));
39+
}
40+
promises.push(writeBrowserReport(config, reporter));
3341
}
3442

35-
if (config.report && config.report.indexOf('json') > -1) {
36-
promises.push(writeJsonReport(config, reporter));
37-
}
38-
39-
promises.push(writeBrowserReport(config, reporter));
40-
4143
return allSettled(promises);
4244
}
4345

core/util/writeXrayReport.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const fs = require('../util/fs');
2+
const path = require('path');
3+
const logger = require('../util/logger')('Xray report');
4+
const _ = require('lodash');
5+
const cloneDeep = require('lodash/cloneDeep');
6+
const { stat } = require('fs');
7+
8+
module.exports = function (config, reporter) {
9+
const jsonReporter = cloneDeep(reporter);
10+
11+
function toAbsolute (p) {
12+
return path.isAbsolute(p) ? p : path.join(config.projectPath, p);
13+
}
14+
15+
function transformTestCases (testCases) {
16+
const transformedTestCases = [];
17+
18+
for (const testName in testCases) {
19+
let testStatus = 'PASSED';
20+
const testCase = testCases[testName];
21+
const xrayTestResult = {
22+
'iterations': [],
23+
'testInfo': {}
24+
};
25+
26+
testCase.forEach((testedViewport) => {
27+
let { pair: { viewportLabel: name }, status } = testedViewport;
28+
29+
status = `${status}ed`.toUpperCase();
30+
if (status === 'FAILED') {
31+
testStatus = status;
32+
}
33+
xrayTestResult.iterations.push({ name, status });
34+
});
35+
36+
xrayTestResult.status = testStatus;
37+
xrayTestResult.testInfo.requirementKeys = testCase[0].pair.metadata;
38+
xrayTestResult.testInfo.summary = testCase[0].pair.label;
39+
xrayTestResult.testInfo.type = "Generic";
40+
transformedTestCases.push(
41+
xrayTestResult
42+
);
43+
}
44+
45+
return transformedTestCases;
46+
}
47+
48+
function transformToXrayJson (json) {
49+
const results = {}
50+
const namedTestCases = _.groupBy(json, 'pair.label');
51+
return results.tests = transformTestCases(namedTestCases);
52+
}
53+
54+
logger.log('Writing Xray json report');
55+
56+
return fs.ensureDir(toAbsolute(config.json_report)).then(function () {
57+
const res = transformToXrayJson(jsonReporter.tests);
58+
59+
return fs.writeFile(toAbsolute(config.compareJsonFileName), JSON.stringify(res, null, 2)).then(
60+
function () {
61+
logger.log('Wrote Xray Json report to: ' + toAbsolute(config.compareJsonFileName));
62+
},
63+
function (err) {
64+
logger.error('Failed writing Xray Json report to: ' + toAbsolute(config.compareJsonFileName));
65+
throw err;
66+
}
67+
);
68+
});
69+
};

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV \
99
RUN apt-get update && \
1010
apt-get install -y git sudo software-properties-common
1111

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

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

0 commit comments

Comments
 (0)