Skip to content

Commit 5c4d10a

Browse files
committed
Merge branch 'master' into deploy
2 parents f648a7b + d5b209a commit 5c4d10a

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

bin/helpers/utils.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ exports.setDefaults = (bsConfig, args) => {
158158
if (bsConfig.run_settings && this.isUndefined(bsConfig.run_settings.npm_dependencies)) {
159159
bsConfig.run_settings.npm_dependencies = {}
160160
}
161+
162+
// setting connection_settings to {} if not present
163+
if (this.isUndefined(bsConfig.connection_settings)) {
164+
bsConfig.connection_settings = {};
165+
}
166+
161167
}
162168

163169
exports.setUsername = (bsConfig, args) => {
@@ -329,7 +335,6 @@ exports.getLocalFlag = (connectionSettings) => {
329335
};
330336

331337
exports.setLocal = (bsConfig, args) => {
332-
let localInferred = !(this.searchForOption('--local-mode'));
333338
if (!this.isUndefined(args.local)) {
334339
let local = false;
335340
if (String(args.local).toLowerCase() === 'true') {
@@ -345,12 +350,19 @@ exports.setLocal = (bsConfig, args) => {
345350
logger.info(
346351
'Reading local setting from the environment variable BROWSERSTACK_LOCAL'
347352
);
353+
} else if (!this.isUndefined(bsConfig['connection_settings']['local'])) {
354+
let local = false;
355+
if (String(bsConfig['connection_settings']['local']).toLowerCase() === 'true') {
356+
local = true;
357+
}
358+
bsConfig['connection_settings']['local'] = local;
348359
} else if (
349360
this.isUndefined(bsConfig['connection_settings']['local']) &&
350-
( !this.isUndefined(args.localMode) || !this.isUndefined(bsConfig['connection_settings']['local_mode']) )
361+
(!this.isUndefined(args.localMode) ||
362+
!this.isUndefined(bsConfig['connection_settings']['local_mode']))
351363
) {
352364
bsConfig['connection_settings']['local'] = true;
353-
bsConfig.connection_settings.local_inferred = localInferred;
365+
bsConfig.connection_settings.local_inferred = true;
354366
}
355367
};
356368

test/unit/bin/helpers/utils.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,16 +676,14 @@ describe('utils', () => {
676676
delete process.env.BROWSERSTACK_LOCAL;
677677
});
678678

679-
it('bsconfig connection_settings local_inferred as true if serachforOption returns false with args local-mode true', () => {
679+
it('bsconfig connection_settings local_inferred as true if args local-mode true', () => {
680680
let bsConfig = {
681681
connection_settings: {
682682
}
683683
};
684684
let args = {
685685
localMode: "always-on"
686686
};
687-
let searchForOptionStub = sinon.stub(utils,"searchForOption");
688-
searchForOptionStub.returns(false);
689687
utils.setLocal(bsConfig,args);
690688
expect(bsConfig.connection_settings.local_inferred).to.be.eq(true);
691689
});
@@ -726,14 +724,13 @@ describe('utils', () => {
726724
expect(bsConfig.connection_settings.local).to.be.eq(false);
727725
});
728726

729-
it('should change local to true in bsConfig if process.env.BROWSERSTACK_LOCAL is set to true', () => {
727+
it('should change local to true in bsConfig if args.local is set to true', () => {
730728
let bsConfig = {
731729
connection_settings: {
732730
local: false,
733731
},
734732
};
735-
let args = {};
736-
process.env.BROWSERSTACK_LOCAL = true;
733+
let args = { local: true };
737734
utils.setLocal(bsConfig,args);
738735
expect(bsConfig.connection_settings.local).to.be.eq(true);
739736
});
@@ -748,6 +745,19 @@ describe('utils', () => {
748745
utils.setLocal(bsConfig,args);
749746
expect(bsConfig.connection_settings.local).to.be.eq(true);
750747
});
748+
749+
it('should set local to true in bsConfig if local is passed as string in bsConfig', () => {
750+
let bsConfig = {
751+
connection_settings: {
752+
local: "true"
753+
},
754+
};
755+
let args = {
756+
};
757+
utils.setLocal(bsConfig, args);
758+
expect(bsConfig.connection_settings.local).to.be.eq(true);
759+
});
760+
751761
});
752762

753763
describe('setLocalMode', () => {
@@ -1428,6 +1438,23 @@ describe('utils', () => {
14281438
expect(utils.isUndefined(bsConfig.auth)).to.be.true;
14291439
expect(utils.isUndefined(bsConfig.run_settings.npm_dependencies)).to.be.false;
14301440
});
1441+
1442+
it ('should set connection_settings if bsConfig.connection_settings is undefined' , () => {
1443+
let bsConfig = { run_settings: {} };
1444+
utils.setDefaults(bsConfig, {});
1445+
expect(utils.isUndefined(bsConfig.connection_settings)).to.be.false;
1446+
});
1447+
1448+
it('should not set connection_settings if bsConfig.connection_settings is defined ', () => {
1449+
let bsConfig = {
1450+
run_settings: {},
1451+
connection_settings: {
1452+
local: "false"
1453+
}
1454+
};
1455+
utils.setDefaults(bsConfig, {});
1456+
expect(bsConfig.connection_settings).to.deep.equal({local: "false"});
1457+
});
14311458
});
14321459

14331460
describe('getNumberOfSpecFiles', () => {

0 commit comments

Comments
 (0)