Skip to content

Commit 157a857

Browse files
Adding support for < v6 cypress_version
1 parent f980c2d commit 157a857

File tree

2 files changed

+108
-7
lines changed

2 files changed

+108
-7
lines changed

bin/helpers/reporterHTML.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,39 @@ async function cypressReportData(report_data) {
223223
let specSessions = report_data.rows[spec]["sessions"];
224224
if (specSessions.length > 0) {
225225
for (let combination of specSessions) {
226-
combinationPromises.push(generateCypressCombinationSpecReportData(combination));
226+
if(utils.isUndefined(report_data.cypress_version) || report_data.cypress_version < "6"){
227+
combinationPromises.push(generateCypressCombinationSpecReportDataWithoutConfigJson(combination));
228+
}else{
229+
combinationPromises.push(generateCypressCombinationSpecReportDataWithConfigJson(combination));
230+
}
227231
}
228232
}
229233
}
230234
await Promise.all(combinationPromises);
231235
return report_data;
232236
}
233237

234-
function generateCypressCombinationSpecReportData(combination){
238+
function generateCypressCombinationSpecReportDataWithConfigJson(combination){
235239
return new Promise(async (resolve, reject) => {
236240
try {
241+
let configJsonError, resultsJsonError;
237242
let [configJsonResponse, resultsJsonResponse] = await axios.all([
238-
axios.get(combination.tests.config_json),
239-
axios.get(combination.tests.result_json)
243+
axios.get(combination.tests.config_json).catch(function (error) {
244+
configJsonError = true;
245+
}),
246+
axios.get(combination.tests.result_json).catch(function(error){
247+
resultsJsonError = true;
248+
})
240249
]);
250+
if(resultsJsonError || configJsonError){
251+
resolve();
252+
}
241253
let tests = {};
242254
let configJson = configJsonResponse.data;
243255
let resultsJson = resultsJsonResponse.data;
256+
if(utils.isUndefined(configJson.tests) || utils.isUndefined(resultsJson.tests)){
257+
resolve();
258+
}
244259
configJson.tests.forEach((test) => {
245260
tests[test["clientId"]] = test;
246261
});
@@ -266,4 +281,34 @@ function generateCypressCombinationSpecReportData(combination){
266281
})
267282
}
268283

284+
function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
285+
return new Promise(async (resolve, reject) => {
286+
try {
287+
let resultsJsonError;
288+
let resultsJsonResponse = await axios.get(combination.tests.result_json).catch(function(error){
289+
resultsJsonError = true;
290+
});
291+
if(resultsJsonError || utils.isUndefined(resultsJsonResponse)){
292+
resolve();
293+
}
294+
let resultsJson = resultsJsonResponse.data;
295+
let sessionTests = [];
296+
if(utils.isUndefined(resultsJson.tests)){
297+
resolve();
298+
}
299+
resultsJson.tests.forEach((test) => {
300+
sessionTests.push({
301+
name: test["title"].pop(),
302+
status: test["state"],
303+
duration: parseFloat(
304+
test["attempts"].pop()["wallClockDuration"] / 1000
305+
).toFixed(2)
306+
})
307+
});
308+
combination.tests = sessionTests;
309+
resolve(combination.tests);
310+
} catch (error) { reject(error) }
311+
})
312+
}
313+
269314
exports.reportGenerator = reportGenerator;

test/unit/bin/helpers/reporterHTML.js

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ describe("reportHTML", () => {
276276
describe("Modify Cypress Report Data", ()=> {
277277
const reporterHTML = rewire('../../../../bin/helpers/reporterHTML');
278278
const cypressReportData = reporterHTML.__get__('cypressReportData');
279-
const cypress_report_data = {
279+
const cypress_report_data_with_config = {
280+
cypress_version: "6.8.0",
280281
rows: {
281282
"todo.spec.js": {
282283
"sessions": [
@@ -290,7 +291,22 @@ describe("reportHTML", () => {
290291
}
291292
}
292293
}
293-
it("Generate Report Data for each combination in a separate promise ", async ()=>{
294+
const cypress_report_data_without_config = {
295+
cypress_version: "5.6.0",
296+
rows: {
297+
"todo.spec.js": {
298+
"sessions": [
299+
{
300+
"tests": {
301+
"config_json": "config_json",
302+
"result_json": "result_json",
303+
}
304+
}
305+
]
306+
}
307+
}
308+
}
309+
it("Generate Report Data for cypress version > 6", async ()=>{
294310
let configResponse = { data: {
295311
tests: [
296312
{
@@ -317,6 +333,7 @@ describe("reportHTML", () => {
317333
]
318334
} }
319335
let expectedResponse = {
336+
cypress_version: "6.8.0",
320337
rows:{
321338
"todo.spec.js": {
322339
"sessions":[{
@@ -331,10 +348,49 @@ describe("reportHTML", () => {
331348
let axiosGetStub = sandbox.stub(axios, "get")
332349
let axiosConfigStub = axiosGetStub.withArgs("config_json").resolves(configResponse);
333350
let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse);
334-
let result = await cypressReportData(cypress_report_data);
351+
let result = await cypressReportData(cypress_report_data_with_config);
335352
sinon.assert.calledOnce(axiosConfigStub);
336353
sinon.assert.calledOnce(axiosResultStub);
337354
expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse));
338355
});
356+
357+
it("Generate Report Data for cypress version < 6", async ()=>{
358+
let resultsResponse = { data: {
359+
tests: [
360+
{
361+
clientId: "r3",
362+
state: "passed",
363+
title:[
364+
"file_name",
365+
"test_case"
366+
],
367+
attempts:[
368+
{
369+
"state": "passed",
370+
"wallClockDuration": 62
371+
}
372+
]
373+
}
374+
]
375+
} }
376+
let expectedResponse = {
377+
cypress_version: "5.6.0",
378+
rows:{
379+
"todo.spec.js": {
380+
"sessions":[{
381+
"tests":[{
382+
"name":"test_case",
383+
"status":"passed",
384+
"duration":"0.06"}]
385+
}]
386+
}
387+
}
388+
}
389+
let axiosGetStub = sandbox.stub(axios, "get")
390+
let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse);
391+
let result = await cypressReportData(cypress_report_data_without_config);
392+
sinon.assert.calledOnce(axiosResultStub);
393+
expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse));
394+
});
339395
});
340396
});

0 commit comments

Comments
 (0)