Skip to content

local passed as string check fix #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
}
};

Expand Down
22 changes: 16 additions & 6 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,14 @@ 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: {
}
};
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);
});
Expand Down Expand Up @@ -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);
});
Expand All @@ -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', () => {
Expand Down