Skip to content

Commit f8ad55b

Browse files
committed
add specs
1 parent 98a120b commit f8ad55b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

test/unit/bin/helpers/sync/specSummary.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const chai = require("chai"),
66

77
chai.use(chaiAsPromised);
88
var logger = require("../../../../../bin/helpers/logger").syncCliLogger;
9+
var winstonLogger = require("../../../../../bin/helpers/logger").winstonLogger;
910
var specSummary = require('../../../../../bin/helpers/sync/specsSummary');
1011

1112
describe("printSpecsRunSummary", () => {
@@ -52,4 +53,36 @@ describe("printSpecsRunSummary", () => {
5253
loggerInfoSpy.restore();
5354
});
5455
});
56+
57+
context("with custom error data", () => {
58+
let time = 6000,
59+
machines = 2,
60+
specs = [
61+
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
62+
{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
63+
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
64+
{specName: 'spec2.name.js', status: 'Passed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
65+
],
66+
data = {
67+
specs: specs,
68+
duration: time,
69+
exitCode: 0
70+
},
71+
customErrorsToPrint = [
72+
{ id: "custom_error", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" }
73+
];
74+
75+
it('prints the custom error message along with build details', () => {
76+
var loggerInfoSpy = sinon.spy(logger, 'info');
77+
var loggerWarnSpy = sinon.spy(winstonLogger, 'warn');
78+
79+
specSummary.printSpecsRunSummary(data, machines, customErrorsToPrint);
80+
sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1');
81+
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`);
82+
sinon.assert.calledWith(loggerWarnSpy, `custom error message`);
83+
84+
loggerInfoSpy.restore();
85+
loggerWarnSpy.restore();
86+
});
87+
});
5588
});

test/unit/bin/helpers/sync/syncSpecsLogs.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,42 @@ describe("syncSpecsLogs", () => {
8787
});
8888
});
8989

90+
context("addCustomErrorToPrint", () => {
91+
const addCustomErrorToPrint = syncSpecsLogs.__get__("addCustomErrorToPrint");
92+
let specSummary = {
93+
"buildError": null,
94+
"specs": [],
95+
"duration": null,
96+
"customErrorsToPrint": [
97+
{ id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" }
98+
]
99+
}
100+
const uniqueError = { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" };
101+
const notUniqueError = { id: "custom_error_2", type: "custom_errors_to_print", level: "warn", should_be_unique: false, message: "custom error message" };
102+
103+
it('should add a new Error if its meant to be unique and not added to the error list', () => {
104+
addCustomErrorToPrint(uniqueError);
105+
expect(JSON.stringify(syncSpecsLogs.__get__("specSummary"))).to.equal(JSON.stringify(specSummary));
106+
});
107+
108+
it('should not add a new Error if its meant to be unique and already added to the error list', () => {
109+
addCustomErrorToPrint(uniqueError);
110+
expect(JSON.stringify(syncSpecsLogs.__get__("specSummary"))).to.equal(JSON.stringify(specSummary));
111+
});
112+
113+
it('should add a new Error if its not meant to be unique and not added to the error list', () => {
114+
addCustomErrorToPrint(notUniqueError);
115+
specSummary.customErrorsToPrint.push(notUniqueError);
116+
expect(JSON.stringify(syncSpecsLogs.__get__("specSummary"))).to.equal(JSON.stringify(specSummary));
117+
});
118+
119+
it('should not add a new Error if its not meant to not be unique and already added to the error list', () => {
120+
addCustomErrorToPrint(notUniqueError);
121+
specSummary.customErrorsToPrint.push(notUniqueError);
122+
expect(JSON.stringify(syncSpecsLogs.__get__("specSummary"))).to.equal(JSON.stringify(specSummary));
123+
});
124+
});
125+
90126
context("getTableConfig", () => {
91127
const getTableConfig = syncSpecsLogs.__get__("getTableConfig");
92128

@@ -212,6 +248,23 @@ describe("syncSpecsLogs", () => {
212248
expect(printSpecData.calledOnce).to.be.true;
213249
expect(printInitialLog.calledOnce).to.be.true;
214250
});
251+
252+
it('should add custom error, print initial and spec details when spec related data is sent in polling response', () => {
253+
let specResult = JSON.stringify({"path": "path"})
254+
let customError = { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" }
255+
syncSpecsLogs.__set__('buildStarted', false)
256+
let data = JSON.stringify(["created", specResult, customError])
257+
var printSpecData = sandbox.stub();
258+
syncSpecsLogs.__set__('printSpecData', printSpecData);
259+
var printInitialLog = sandbox.stub();
260+
syncSpecsLogs.__set__('printInitialLog', printInitialLog);
261+
var addCustomErrorToPrint = sandbox.stub();
262+
syncSpecsLogs.__set__('addCustomErrorToPrint', addCustomErrorToPrint);
263+
showSpecsStatus(data);
264+
expect(printSpecData.calledOnce).to.be.true;
265+
expect(printInitialLog.calledOnce).to.be.true;
266+
expect(addCustomErrorToPrint.calledOnce).to.be.true;
267+
});
215268
});
216269

217270
context("printSpecsStatus", () => {

0 commit comments

Comments
 (0)