Skip to content

Commit 9dc85c4

Browse files
Unit test cases fix for cli log changes
1 parent 0bcdf1c commit 9dc85c4

File tree

7 files changed

+72
-67
lines changed

7 files changed

+72
-67
lines changed

test/unit/bin/commands/runs.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,6 @@ describe("runs", () => {
481481
messageType,
482482
errorCode
483483
);
484-
})
485-
.finally(function () {
486-
sinon.assert.calledOnce(deleteZipStub);
487484
});
488485
});
489486
});
@@ -607,9 +604,6 @@ describe("runs", () => {
607604
messageType,
608605
errorCode
609606
);
610-
})
611-
.finally(function () {
612-
sinon.assert.calledOnce(deleteZipStub);
613607
});
614608
});
615609
});

test/unit/bin/helpers/fileHelpers.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const chai = require("chai"),
2-
sinon = require("sinon"),
1+
const chai = require('chai'),
2+
sinon = require('sinon'),
33
expect = chai.expect,
44
assert = chai.assert,
5-
chaiAsPromised = require("chai-as-promised");
5+
chaiAsPromised = require('chai-as-promised'),
6+
fs = require('fs-extra'),
7+
fileHelpers = require('../../../../bin/helpers/fileHelpers');
68

79
const logger = require("../../../../bin/helpers/logger").winstonLogger,
810
proxyquire = require("proxyquire").noCallThru();
@@ -82,30 +84,19 @@ describe("fileHelpers", () => {
8284
});
8385

8486
it("deleteZip returns 0 on success", () => {
85-
let unlinkStub = sandbox.stub().yields();
86-
87-
const fileHelpers = proxyquire("../../../../bin/helpers/fileHelpers", {
88-
"fs-extra": {
89-
unlink: unlinkStub,
90-
},
91-
});
87+
let unlinkStub = sinon.stub(fs, 'unlinkSync').returns(true);
9288

9389
let result = fileHelpers.deleteZip();
9490
sinon.assert.calledOnce(unlinkStub);
9591
assert.equal(result, 0);
92+
fs.unlinkSync.restore();
9693
});
9794

9895
it("deleteZip returns 1 on failure", () => {
99-
let unlinkStub = sandbox.stub().yields(new Error("random-error"));
100-
101-
const fileHelpers = proxyquire("../../../../bin/helpers/fileHelpers", {
102-
"fs-extra": {
103-
unlink: unlinkStub,
104-
},
105-
});
106-
96+
let unlinkStub = sinon.stub(fs, 'unlinkSync').yields(new Error("random-error"));
10797
let result = fileHelpers.deleteZip();
10898
sinon.assert.calledOnce(unlinkStub);
10999
assert.equal(result, 1);
100+
fs.unlinkSync.restore();
110101
});
111102
});

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,41 @@ describe("failedSpecsDetails", () => {
2121
});
2222

2323
context("data is empty", () => {
24-
let data = [];
24+
let data = {
25+
specs: [],
26+
exitCode: 0
27+
};
28+
2529
it('returns 0 exit code', () => {
26-
return specDetails.failedSpecsDetails(data).then((status) => {
27-
expect(status).to.equal(0);
30+
return specDetails.failedSpecsDetails(data).then((result) => {
31+
expect(result).to.equal(data);
2832
});
2933
});
3034
});
3135

3236
context("data does not have failed specs", () => {
33-
let data = [
34-
{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
35-
];
37+
let data = {
38+
specs: [{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}],
39+
exitCode: 0
40+
};
3641

3742
it("returns 0 exit code", () => {
38-
return specDetails.failedSpecsDetails(data).then((status) => {
39-
expect(status).to.equal(0);
43+
return specDetails.failedSpecsDetails(data).then((result) => {
44+
expect(result).to.equal(data);
4045
});
4146
});
4247
});
4348

4449
context("data has failed specs", () => {
45-
let data = [
46-
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
47-
{specName: 'spec2.name.js', status: 'Passed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
48-
];
50+
let data = {
51+
specs: [ {specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
52+
{specName: 'spec2.name.js', status: 'Passed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}],
53+
exitCode: 1
54+
};
4955

5056
it("returns 1 exit code", () => {
51-
return specDetails.failedSpecsDetails(data)
52-
.then((status) => {
53-
chai.assert.equal(status, 1);
54-
expect(status).to.equal(1);
55-
}).catch((status) => {
56-
expect(status).to.equal(1);
57+
return specDetails.failedSpecsDetails(data).then((result) => {
58+
expect(result).to.equal(data);
5759
});
5860
});
5961
});

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@ var specSummary = require('../../../../../bin/helpers/sync/specsSummary');
1010

1111
describe("printSpecsRunSummary", () => {
1212
context("data is empty", () => {
13-
let data = [], time = 6000, machines = 2;
13+
let data = { specs: [], duration: 6000, exitCode: 0}, machines = 2;
1414
it('returns passed specs data', () => {
15-
return specSummary.printSpecsRunSummary(data, time, machines).then((specsData) => {
16-
expect(data).to.equal(specsData);
15+
return specSummary.printSpecsRunSummary(data, machines).then((specsData) => {
16+
expect(data.exitCode).to.equal(specsData);
1717
});
1818
});
1919
});
2020

2121
context("with data", () => {
2222
let time = 6000,
2323
machines = 2,
24-
data = [
24+
specs = [
2525
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
2626
{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
2727
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
2828
{specName: 'spec2.name.js', status: 'Passed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
29-
];
29+
],
30+
data = {
31+
specs: specs,
32+
duration: time,
33+
exitCode: 0
34+
};
3035

3136
it('returns passed specs data', () => {
3237
var loggerInfoSpy = sinon.spy(logger, 'info');
3338

34-
specSummary.printSpecsRunSummary(data, time, machines);
39+
specSummary.printSpecsRunSummary(data, machines);
3540
sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1');
3641
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`);
3742

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ describe("syncSpecsLogs", () => {
2929
context("getCombinationName", () => {
3030
const get_path = syncSpecsLogs.__get__("getCombinationName");;
3131
let spec = {
32-
"os": "Windows 10",
32+
"os": "Windows",
3333
"osVersion": "10",
3434
"browser": "chrome",
3535
"browserVersion": "86"
3636
}
3737
it("returns combination name", () => {
38-
let expectedCombination = `${spec["os"]} ${spec["osVersion"]} / ${spec["browser"]} ${spec["browserVersion"]}`;
38+
let expectedCombination = `Chrome 86 (Windows 10)`;
3939
expect(get_path(spec)).to.equal(expectedCombination);
4040
});
4141
});
@@ -61,15 +61,12 @@ describe("syncSpecsLogs", () => {
6161
const printInitialLog = syncSpecsLogs.__get__("printInitialLog");
6262

6363
it("should print inital logs for specs in sync", () => {
64-
var loggerInfoStub = sinon.stub(logger, 'info');
6564

6665
printInitialLog()
6766

6867
expect(syncSpecsLogs.__get__("n")).to.equal(Constants.syncCLI.INITIAL_DELAY_MULTIPLIER);
6968
expect(syncSpecsLogs.__get__("startTime")).to.not.be.null;
70-
sinon.assert.calledWith(loggerInfoStub, Constants.syncCLI.LOGS.INIT_LOG);
7169

72-
loggerInfoStub.restore();
7370
});
7471
});
7572

@@ -95,10 +92,12 @@ describe("syncSpecsLogs", () => {
9592
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);
9693

9794
let options = getTableConfig();
98-
expect(options.singleLine).to.be.true;
99-
expect(options.columnDefault.width).to.equal(50);
100-
expect(options.columns[0].alignment).to.equal('right');
101-
expect(options.columnCount).to.equal(2);
95+
expect(options.columnDefault.width).to.equal(25);
96+
expect(options.columns[1].alignment).to.equal('center');
97+
expect(options.columns[2].alignment).to.equal('left');
98+
expect(options.columns[1].width).to.equal(1);
99+
expect(options.columns[2].width).to.equal(30);
100+
expect(options.columnCount).to.equal(3);
102101
expect(getBorderConfigStub.calledOnce).to.be.true;
103102
});
104103
});
@@ -108,8 +107,8 @@ describe("syncSpecsLogs", () => {
108107

109108
it('should return proper border option for spec table', () => {
110109
let options = getBorderConfig();
111-
expect(options.topBody).to.equal("-");
112-
expect(options.bottomBody).to.equal("-");
110+
expect(options.topBody).to.equal("");
111+
expect(options.bottomBody).to.equal("");
113112
});
114113
});
115114

@@ -122,7 +121,7 @@ describe("syncSpecsLogs", () => {
122121
syncSpecsLogs.__set__('stream', stream);
123122
let combination = "Windows 10", path = "path", status = "passed";
124123
writeToTable(combination, path, status);
125-
sinon.assert.calledOnceWithExactly(stream.write, [combination + ":", `${path} ${status}`]);
124+
sinon.assert.calledOnceWithExactly(stream.write, [combination , ":", `${path} ${status}`]);
126125
});
127126
});
128127

@@ -200,7 +199,7 @@ describe("syncSpecsLogs", () => {
200199
context("printSpecsStatus", () => {
201200
const printSpecsStatus = syncSpecsLogs.__get__("printSpecsStatus");
202201
let startTime = Date.now(), endTime = Date.now() + 10, counter = 0;
203-
let specSummary = { specs: [] }, getOptions, getTableConfig, tableStream, whileProcess, loggerInfoStub;
202+
let specSummary = { specs: [] }, getOptions, getTableConfig, tableStream, whileProcess;
204203

205204
beforeEach(() => {
206205
counter = 0;
@@ -214,8 +213,6 @@ describe("syncSpecsLogs", () => {
214213
tableStream = sandbox.stub();
215214
syncSpecsLogs.__set__('tableStream', tableStream);
216215

217-
loggerInfoStub = sandbox.stub(logger, 'info');
218-
219216
whileProcess = sandbox.stub().callsFake(function (whilstCallback) {
220217
counter++
221218
if(counter >= 3) {
@@ -237,7 +234,6 @@ describe("syncSpecsLogs", () => {
237234
expect(getOptions.calledOnce).to.be.true;
238235
expect(getTableConfig.calledOnce).to.be.true;
239236
expect(tableStream.calledOnce).to.be.true;
240-
expect(loggerInfoStub.calledOnce).to.be.true;
241237
expect(whileProcess.calledOnce).to.be.false;
242238
expect(specSummary.specs).deep.to.equal([])
243239
expect(specSummary.duration).to.eql(endTime - startTime);

test/unit/bin/helpers/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,4 +931,16 @@ describe('utils', () => {
931931
expect(utils.isUndefined(bsConfig.auth)).to.be.true;
932932
});
933933
});
934+
935+
describe('capitalizeFirstLetter', () => {
936+
937+
it('should capitalize First Letter ', () => {
938+
expect(utils.capitalizeFirstLetter("chrome")).to.eq("Chrome");
939+
});
940+
941+
it('should return null if value passed is null', () => {
942+
expect(utils.capitalizeFirstLetter(null)).to.eq(null);
943+
});
944+
945+
});
934946
});

test/unit/bin/helpers/zipUpload.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("zipUpload", () => {
2222
sandbox = sinon.createSandbox();
2323
getUserAgentStub = sandbox.stub().returns("random user-agent");
2424
createReadStreamStub = sandbox.stub(fs, "createReadStream");
25+
deleteZipStub = sandbox.stub().returns(true);
2526
});
2627

2728
afterEach(() => {
@@ -119,11 +120,14 @@ describe("zipUpload", () => {
119120
.stub(request, "post")
120121
.yields(null, { statusCode: 200 }, JSON.stringify({ zip_url: zip_url }));
121122

122-
const zipUploader = proxyquire("../../../../bin/helpers/zipUpload", {
123-
"./utils": {
123+
const zipUploader = proxyquire('../../../../bin/helpers/zipUpload', {
124+
'./utils': {
124125
getUserAgent: getUserAgentStub,
125126
},
126-
request: { post: requestStub },
127+
request: {post: requestStub},
128+
'./fileHelpers': {
129+
deleteZip: deleteZipStub,
130+
},
127131
});
128132

129133
return zipUploader
@@ -132,6 +136,7 @@ describe("zipUpload", () => {
132136
sinon.assert.calledOnce(requestStub);
133137
sinon.assert.calledOnce(getUserAgentStub);
134138
sinon.assert.calledOnce(createReadStreamStub);
139+
sinon.assert.calledOnce(deleteZipStub);
135140
chai.assert.equal(data.zip_url, zip_url);
136141
})
137142
.catch((error) => {

0 commit comments

Comments
 (0)