Skip to content

Commit f980c2d

Browse files
Add unit tests for modifying cypress report data
1 parent 6d4b35b commit f980c2d

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

test/unit/bin/helpers/reporterHTML.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
const { expect } = require("chai");
12
const chai = require("chai"),
23
chaiAsPromised = require("chai-as-promised"),
3-
sinon = require('sinon');
4+
sinon = require('sinon'),
5+
rewire = require('rewire'),
6+
axios = require('axios');
47

58
const fs = require('fs'),
69
path = require('path'),
@@ -269,4 +272,69 @@ describe("reportHTML", () => {
269272
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
270273
});
271274
});
275+
276+
describe("Modify Cypress Report Data", ()=> {
277+
const reporterHTML = rewire('../../../../bin/helpers/reporterHTML');
278+
const cypressReportData = reporterHTML.__get__('cypressReportData');
279+
const cypress_report_data = {
280+
rows: {
281+
"todo.spec.js": {
282+
"sessions": [
283+
{
284+
"tests": {
285+
"config_json": "config_json",
286+
"result_json": "result_json",
287+
}
288+
}
289+
]
290+
}
291+
}
292+
}
293+
it("Generate Report Data for each combination in a separate promise ", async ()=>{
294+
let configResponse = { data: {
295+
tests: [
296+
{
297+
clientId: "r3",
298+
title:[
299+
"file_name",
300+
"test_case"
301+
]
302+
}
303+
]
304+
} }
305+
let resultsResponse = { data: {
306+
tests: [
307+
{
308+
clientId: "r3",
309+
state: "passed",
310+
attempts:[
311+
{
312+
"state": "passed",
313+
"wallClockDuration": 62
314+
}
315+
]
316+
}
317+
]
318+
} }
319+
let expectedResponse = {
320+
rows:{
321+
"todo.spec.js": {
322+
"sessions":[{
323+
"tests":[{
324+
"name":"test_case",
325+
"status":"passed",
326+
"duration":"0.06"}]
327+
}]
328+
}
329+
}
330+
}
331+
let axiosGetStub = sandbox.stub(axios, "get")
332+
let axiosConfigStub = axiosGetStub.withArgs("config_json").resolves(configResponse);
333+
let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse);
334+
let result = await cypressReportData(cypress_report_data);
335+
sinon.assert.calledOnce(axiosConfigStub);
336+
sinon.assert.calledOnce(axiosResultStub);
337+
expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse));
338+
});
339+
});
272340
});

0 commit comments

Comments
 (0)