Skip to content
Open
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
6 changes: 6 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ exports.setLocalArgs = (bsConfig, args) => {
if (bsConfig["connection_settings"]["useCaCertificate"])
local_args['useCaCertificate'] = bsConfig["connection_settings"]["useCaCertificate"];

// browserstack-local only recognises the all-lowercase binarypath key; any other casing is
// forwarded to the binary as an unknown CLI flag and the binary gets downloaded anyway
const localBinaryPath = bsConfig["connection_settings"]["binaryPath"] || bsConfig["connection_settings"]["binarypath"];
if (localBinaryPath)
local_args['binarypath'] = localBinaryPath;

local_args['daemon'] = true;
local_args['enable-logging-for-api'] = true
local_args['source'] = `cypress:${usageReporting.cli_version_and_path(bsConfig).version}`;
Expand Down
56 changes: 55 additions & 1 deletion test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const chai = require('chai'),
crypto = require('crypto'),
fs = require('fs');
const getmac = require('getmac').default;
const usageReporting = require('../../../../bin/helpers/usageReporting');
const utils = require('../../../../bin/helpers/utils'),
constant = require('../../../../bin/helpers/constants'),
logger = require('../../../../bin/helpers/logger').winstonLogger,
Expand All @@ -23,6 +22,10 @@ const utils = require('../../../../bin/helpers/utils'),
syncLogger = require('../../../../bin/helpers/logger').syncCliLogger,
Contants = require('../../../../bin/helpers/constants'),
o11yHelpers = require('../../../../bin/testObservability/helper/helper');
// utils must be required first: usageReporting reassigns module.exports after its own circular
// require('./utils'), so loading it first leaves utils holding a stale, empty exports object and
// nothing stubbed here is visible to the code under test.
const usageReporting = require('../../../../bin/helpers/usageReporting');
const browserstack = require('browserstack-local');
const { CYPRESS_V10_AND_ABOVE_TYPE, CYPRESS_V9_AND_OLDER_TYPE } = require('../../../../bin/helpers/constants');
const { winstonLogger, syncCliLogger } = require('../../../../bin/helpers/logger');
Expand Down Expand Up @@ -1440,6 +1443,57 @@ describe('utils', () => {
expect(local_args['config-file']).to.be.eq(path.resolve('./local.yml'));
sinon.restore();
});

it('forwards a configured binaryPath as the lowercase binarypath key', () => {
let bsConfig = {
auth: { access_key: 'xyz' },
connection_settings: {
local: true,
local_identifier: 'on-demand',
binaryPath: '/tmp/BrowserStackLocal',
},
};
let cliVersionPathStub = sinon
.stub(usageReporting, 'cli_version_and_path')
.withArgs(bsConfig);
cliVersionPathStub.returns('abc');
let local_args = utils.setLocalArgs(bsConfig, {});
expect(local_args['binarypath']).to.be.eq('/tmp/BrowserStackLocal');
expect(local_args['binaryPath']).to.be.eq(undefined);
sinon.restore();
});

it('also accepts the lowercase binarypath config key', () => {
let bsConfig = {
auth: { access_key: 'xyz' },
connection_settings: {
local: true,
local_identifier: 'on-demand',
binarypath: '/tmp/BrowserStackLocal',
},
};
let cliVersionPathStub = sinon
.stub(usageReporting, 'cli_version_and_path')
.withArgs(bsConfig);
cliVersionPathStub.returns('abc');
let local_args = utils.setLocalArgs(bsConfig, {});
expect(local_args['binarypath']).to.be.eq('/tmp/BrowserStackLocal');
sinon.restore();
});

it('omits binarypath when none is configured', () => {
let bsConfig = {
auth: { access_key: 'xyz' },
connection_settings: { local: true, local_identifier: 'on-demand' },
};
let cliVersionPathStub = sinon
.stub(usageReporting, 'cli_version_and_path')
.withArgs(bsConfig);
cliVersionPathStub.returns('abc');
let local_args = utils.setLocalArgs(bsConfig, {});
expect(Object.keys(local_args)).to.not.include('binarypath');
sinon.restore();
});
});

describe('stopLocalBinary', () => {
Expand Down
Loading