diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index c59c9785..fe2e9f50 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -329,7 +329,6 @@ exports.getLocalFlag = (connectionSettings) => { }; exports.setLocal = (bsConfig, args) => { - let localInferred = !(this.searchForOption('--local-mode')); if (!this.isUndefined(args.local)) { let local = false; if (String(args.local).toLowerCase() === 'true') { @@ -345,12 +344,19 @@ exports.setLocal = (bsConfig, args) => { logger.info( 'Reading local setting from the environment variable BROWSERSTACK_LOCAL' ); + } else if (!this.isUndefined(bsConfig['connection_settings']['local'])) { + let local = false; + if (String(bsConfig['connection_settings']['local']).toLowerCase() === 'true') { + local = true; + } + bsConfig['connection_settings']['local'] = local; } else if ( this.isUndefined(bsConfig['connection_settings']['local']) && - ( !this.isUndefined(args.localMode) || !this.isUndefined(bsConfig['connection_settings']['local_mode']) ) + (!this.isUndefined(args.localMode) || + !this.isUndefined(bsConfig['connection_settings']['local_mode'])) ) { bsConfig['connection_settings']['local'] = true; - bsConfig.connection_settings.local_inferred = localInferred; + bsConfig.connection_settings.local_inferred = true; } }; diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 84bb8997..5ce5ef9a 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -676,7 +676,7 @@ describe('utils', () => { delete process.env.BROWSERSTACK_LOCAL; }); - it('bsconfig connection_settings local_inferred as true if serachforOption returns false with args local-mode true', () => { + it('bsconfig connection_settings local_inferred as true if args local-mode true', () => { let bsConfig = { connection_settings: { } @@ -684,8 +684,6 @@ describe('utils', () => { let args = { localMode: "always-on" }; - let searchForOptionStub = sinon.stub(utils,"searchForOption"); - searchForOptionStub.returns(false); utils.setLocal(bsConfig,args); expect(bsConfig.connection_settings.local_inferred).to.be.eq(true); }); @@ -726,14 +724,13 @@ describe('utils', () => { expect(bsConfig.connection_settings.local).to.be.eq(false); }); - it('should change local to true in bsConfig if process.env.BROWSERSTACK_LOCAL is set to true', () => { + it('should change local to true in bsConfig if args.local is set to true', () => { let bsConfig = { connection_settings: { local: false, }, }; - let args = {}; - process.env.BROWSERSTACK_LOCAL = true; + let args = { local: true }; utils.setLocal(bsConfig,args); expect(bsConfig.connection_settings.local).to.be.eq(true); }); @@ -748,6 +745,19 @@ describe('utils', () => { utils.setLocal(bsConfig,args); expect(bsConfig.connection_settings.local).to.be.eq(true); }); + + it('should set local to true in bsConfig if local is passed as string in bsConfig', () => { + let bsConfig = { + connection_settings: { + local: "true" + }, + }; + let args = { + }; + utils.setLocal(bsConfig, args); + expect(bsConfig.connection_settings.local).to.be.eq(true); + }); + }); describe('setLocalMode', () => {