Skip to content

Commit 37d7936

Browse files
committed
fix test cases and handle some edge cases
1 parent 1ec2908 commit 37d7936

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ let showSpecsStatus = (data) => {
119119
if (specDetails == "created") {
120120
printInitialLog();
121121
} else {
122-
try {
123-
printSpecData(JSON.parse(specDetails))
124-
} catch (error) {
125-
}
122+
printSpecData(JSON.parse(specDetails))
126123
}
127124
});
128125
}

test/unit/bin/commands/runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ describe("runs", () => {
517517
let messageType = Constants.messageTypes.SUCCESS;
518518
let errorCode = null;
519519
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
520-
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}random_build_id`;
520+
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`;
521521

522522
const runs = proxyquire("../../../../bin/commands/runs", {
523523
"../helpers/utils": {
@@ -564,7 +564,7 @@ describe("runs", () => {
564564
);
565565
archiverStub.returns(Promise.resolve("Zipping completed"));
566566
zipUploadStub.returns(Promise.resolve("zip uploaded"));
567-
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id' }));
567+
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl }));
568568

569569
return runs(args)
570570
.then(function (_bsConfig) {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ const chai = require("chai"),
33
expect = chai.expect,
44
chaiAsPromised = require("chai-as-promised");
55

6+
const sinon = require("sinon");
67
chai.use(chaiAsPromised);
78
const specDetails = require('../../../../../bin/helpers/sync/failedSpecsDetails');
9+
var logger = require("../../../../../bin/helpers/logger").syncCliLogger;
810

911
describe("failedSpecsDetails", () => {
12+
var sandbox;
13+
14+
beforeEach(() => {
15+
sandbox = sinon.createSandbox();
16+
sandbox.stub(logger, 'info');
17+
});
18+
19+
afterEach(() => {
20+
sandbox.restore();
21+
});
22+
1023
context("data is empty", () => {
1124
let data = [];
1225
it('returns 0 exit code', () => {
@@ -30,7 +43,8 @@ describe("failedSpecsDetails", () => {
3043

3144
context("data has failed specs", () => {
3245
let data = [
33-
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
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...'}
3448
];
3549

3650
it("returns 1 exit code", () => {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const chai = require("chai"),
77
request = require("request");
88

99
const sinon = require("sinon");
10-
// var sandbox = require('sinon').createSandbox();
1110

1211
chai.use(chaiAsPromised);
1312

test/unit/bin/helpers/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,19 @@ describe("utils", () => {
140140
describe("validateBstackJson", () => {
141141
it("should reject with SyntaxError for empty file", () => {
142142
let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack.json');
143-
expect(utils.validateBstackJson(bsConfigPath)).to.be.rejectedWith(SyntaxError);
143+
return utils.validateBstackJson(bsConfigPath).catch((error)=>{
144+
sinon.match(error, "Invalid browserstack.json file")
145+
});
144146
});
145147
it("should resolve with data for valid json", () => {
146148
let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack_2.json');
147149
expect(utils.validateBstackJson(bsConfigPath)).to.be.eventually.eql({});
148150
});
149151
it("should reject with SyntaxError for invalid json file", () => {
150152
let bsConfigPath = path.join(process.cwd(), 'test', 'test_files', 'dummy_bstack_3.json');
151-
expect(utils.validateBstackJson(bsConfigPath)).to.be.rejectedWith(SyntaxError);
153+
return utils.validateBstackJson(bsConfigPath).catch((error) => {
154+
sinon.match(error, "Invalid browserstack.json file")
155+
});
152156
});
153157
});
154158

0 commit comments

Comments
 (0)