Skip to content

Commit 3f62dbb

Browse files
Setting local & local_identifier if not present in conf json but set as env variable.
1 parent de2e718 commit 3f62dbb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

bin/helpers/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ exports.getLocalFlag = (connectionSettings) => {
173173
}
174174

175175
exports.setLocal = (bsConfig) => {
176-
if(!this.isUndefined(process.env.BROWSERSTACK_LOCAL) && !this.isUndefined(bsConfig.connection_settings)){
176+
if(!this.isUndefined(process.env.BROWSERSTACK_LOCAL)){
177177
let local = false;
178178
if(String(process.env.BROWSERSTACK_LOCAL).toLowerCase() === "true") local = true;
179179
bsConfig['connection_settings']['local'] = local;
@@ -182,7 +182,7 @@ exports.setLocal = (bsConfig) => {
182182
}
183183

184184
exports.setLocalIdentifier = (bsConfig) => {
185-
if (!this.isUndefined(process.env.BROWSERSTACK_LOCAL_IDENTIFIER) && !this.isUndefined(bsConfig.connection_settings)){
185+
if (!this.isUndefined(process.env.BROWSERSTACK_LOCAL_IDENTIFIER)){
186186
bsConfig['connection_settings']['local_identifier'] = process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
187187
logger.info("Reading local identifier from the environment variable BROWSERSTACK_LOCAL_IDENTIFIER");
188188
}

test/unit/bin/helpers/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ describe("utils", () => {
344344
utils.setLocal(bsConfig);
345345
expect(bsConfig.connection_settings.local).to.be.eq(true);
346346
});
347+
348+
it("should set local to true in bsConfig if process.env.BROWSERSTACK_LOCAL is set to true & local is not set in bsConfig", () => {
349+
let bsConfig = {
350+
connection_settings: {
351+
}
352+
}
353+
process.env.BROWSERSTACK_LOCAL = true;
354+
utils.setLocal(bsConfig);
355+
expect(bsConfig.connection_settings.local).to.be.eq(true);
356+
});
357+
347358
});
348359

349360
describe("setLocalIdentifier", () => {
@@ -375,6 +386,16 @@ describe("utils", () => {
375386
expect(bsConfig.connection_settings.local_identifier).to.be.eq("local_identifier");
376387
});
377388

389+
it("should set local identifier in connection_settings in bsConfig if process.env.BROWSERSTACK_LOCAL_IDENTIFIER is present & not set in bsConfig", () => {
390+
let bsConfig = {
391+
connection_settings: {
392+
}
393+
}
394+
process.env.BROWSERSTACK_LOCAL_IDENTIFIER = "local_identifier";
395+
utils.setLocalIdentifier(bsConfig);
396+
expect(bsConfig.connection_settings.local_identifier).to.be.eq("local_identifier");
397+
});
398+
378399
});
379400

380401
describe("setUsername", () => {

0 commit comments

Comments
 (0)