Skip to content

Commit d5b209a

Browse files
Adding unit test case and checking if local is passed as string (#128)
1 parent 170a49f commit d5b209a

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

bin/helpers/utils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ exports.getLocalFlag = (connectionSettings) => {
335335
};
336336

337337
exports.setLocal = (bsConfig, args) => {
338-
let localInferred = !(this.searchForOption('--local-mode'));
339338
if (!this.isUndefined(args.local)) {
340339
let local = false;
341340
if (String(args.local).toLowerCase() === 'true') {
@@ -351,12 +350,19 @@ exports.setLocal = (bsConfig, args) => {
351350
logger.info(
352351
'Reading local setting from the environment variable BROWSERSTACK_LOCAL'
353352
);
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;
354359
} else if (
355360
this.isUndefined(bsConfig['connection_settings']['local']) &&
356-
( !this.isUndefined(args.localMode) || !this.isUndefined(bsConfig['connection_settings']['local_mode']) )
361+
(!this.isUndefined(args.localMode) ||
362+
!this.isUndefined(bsConfig['connection_settings']['local_mode']))
357363
) {
358364
bsConfig['connection_settings']['local'] = true;
359-
bsConfig.connection_settings.local_inferred = localInferred;
365+
bsConfig.connection_settings.local_inferred = true;
360366
}
361367
};
362368

test/unit/bin/helpers/utils.js

Lines changed: 16 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', () => {

0 commit comments

Comments
 (0)