Skip to content

Commit b9dbae6

Browse files
author
Karan Nagpal
committed
Handle binary spawned by CLT
1 parent 18d86f7 commit b9dbae6

File tree

4 files changed

+36
-49
lines changed

4 files changed

+36
-49
lines changed

bin/commands/runs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ module.exports = function run(args, rawArgs) {
204204
}).finally(() =>{
205205
let terminalWidth = (process.stdout.columns) * 0.9;
206206
let lineSeparator = "\n" + "-".repeat(terminalWidth);
207-
console.log(lineSeparator)
208207
logger.info(Constants.userMessages.BUILD_FAILED_ERROR)
209208
process.exitCode = Constants.BUILD_FAILED_EXIT_CODE;
210209
});

bin/helpers/capabilityHelper.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,29 @@ const caps = (bsConfig, zip) => {
7171
obj.local = true;
7272
}
7373

74-
obj.localMode = null;
75-
// Local Mode
76-
if (obj.local === true && bsConfig.connection_settings.local_mode) {
77-
obj.localMode = bsConfig.connection_settings.local_mode;
78-
if (bsConfig.connection_settings.user_defined_local_mode_warning) {
79-
logger.warn(Constants.userMessages.INVALID_LOCAL_MODE_WARNING);
74+
// binary was spawned locally
75+
if(obj.local === true) {
76+
if (!Utils.isUndefined(process.env.BSTACK_CYPRESS_RUN_LOCAL_BINARY) && process.env.BSTACK_CYPRESS_RUN_LOCAL_BINARY == "true") {
77+
obj.localMode = null;
78+
79+
// Local Mode
80+
if (obj.local === true && bsConfig.connection_settings.local_mode) {
81+
obj.localMode = bsConfig.connection_settings.local_mode;
82+
if (bsConfig.connection_settings.user_defined_local_mode_warning) {
83+
logger.warn(Constants.userMessages.INVALID_LOCAL_MODE_WARNING);
84+
}
85+
logger.info(`Local testing set up in ${obj.localMode} mode.`);
86+
}
87+
88+
// Local Identifier
89+
obj.localIdentifier = null;
90+
if (obj.local === true && (bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier)) {
91+
obj.localIdentifier = bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier;
92+
logger.info(`Local testing identifier: ${obj.localIdentifier}`);
93+
}
94+
} else {
95+
logger.info(Constants.userMessages.LOCAL_BINARY_ALREADY_RUNNING);
8096
}
81-
logger.info(`Local testing set up in ${obj.localMode} mode.`);
82-
}
83-
84-
// Local Identifier
85-
obj.localIdentifier = null;
86-
if (obj.local === true && (bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier)) {
87-
obj.localIdentifier = bsConfig.connection_settings.localIdentifier || bsConfig.connection_settings.local_identifier;
88-
logger.info(`Local testing identifier: ${obj.localIdentifier}`);
8997
}
9098

9199
logger.info(`Local is set to: ${obj.local} (${obj.local ? Constants.userMessages.LOCAL_TRUE : Constants.userMessages.LOCAL_FALSE})`);
@@ -164,8 +172,6 @@ const validate = (bsConfig, args) => {
164172
// validate local args i.e --local-mode and --local-identifier
165173

166174
if( Utils.searchForOption('--local-identifier') && (Utils.isUndefined(args.localIdentifier) || (!Utils.isUndefined(args.localIdentifier) && !args.localIdentifier.trim()))) reject(Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER);
167-
168-
if( Utils.getLocalFlag(bsConfig.connection_settings) && (Utils.isUndefined(bsConfig["connection_settings"]["local_identifier"]) || ( !Utils.isUndefined(bsConfig["connection_settings"]["local_identifier"]) && !bsConfig["connection_settings"]["local_identifier"].trim()))) reject(Constants.validationMessages.INVALID_LOCAL_IDENTIFIER);
169175

170176
if( Utils.searchForOption('--local-mode') && ( Utils.isUndefined(args.localMode) || (!Utils.isUndefined(args.localMode) && !["always-on","on-demand"].includes(args.localMode)))) reject(Constants.validationMessages.INVALID_LOCAL_MODE);
171177

bin/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const userMessages = {
5656
LOCAL_START_FAILED: "Local Testing setup failed.",
5757
LOCAL_STOP_FAILED: "Local Binary stop failed.",
5858
INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
59+
LOCAL_BINARY_ALREADY_RUNNING: "We found an existing BrowserStack Local connection running from your account. Using the existing connection for this build. If you wish to use a new Local connection for your build, please specify a value for 'local_identifier' within 'connection_settings' in your browserstack.json config.",
5960
SPEC_LIMIT_WARNING: "You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder.",
6061
DOWNLOAD_BUILD_ARTIFACTS_FAILED: "Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
6162
ASYNC_DOWNLOADS: "Test artifacts as specified under 'downloads' can be downloaded after the build has completed its run, using 'browserstack-cypress generate-downloads <build-id>'",

bin/helpers/utils.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,6 @@ exports.setLocalIdentifier = (bsConfig, args) => {
593593
!this.isUndefined(bsConfig["connection_settings"]["local_identifier"])
594594
){
595595
bsConfig['connection_settings']['local_mode'] = 'always-on';
596-
} else if (
597-
bsConfig['connection_settings']['local'] &&
598-
this.isUndefined(bsConfig["connection_settings"]["local_identifier"])
599-
){
600-
bsConfig["connection_settings"]["local_identifier"] = this.generateLocalIdentifier(bsConfig['connection_settings']['local_mode']);
601596
}
602597
};
603598

@@ -637,9 +632,17 @@ exports.setLocalMode = (bsConfig, args) => {
637632
exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
638633
return new Promise(async (resolve, reject) => {
639634
if( bsConfig['connection_settings'] && bsConfig['connection_settings']['local'] && String(bsConfig['connection_settings']['local']) === "true" ){
640-
let localIdentifierRunning = await this.checkLocalIdentifierRunning(
641-
bsConfig, bsConfig['connection_settings']['local_identifier']
642-
);
635+
let localBinaryRunning = await this.checklocalBinaryRunning(bsConfig, bsConfig['connection_settings']['local_identifier']);
636+
let localIdentifierRunning;
637+
if (localBinaryRunning['should_spawn_binary'] == true) {
638+
localIdentifierRunning = false;
639+
if(this.isUndefined(bsConfig["connection_settings"]["local_identifier"])) {
640+
bsConfig["connection_settings"]["local_identifier"] = this.generateLocalIdentifier(bsConfig['connection_settings']['local_mode']);
641+
}
642+
} else {
643+
localIdentifierRunning = true;
644+
process.env.BSTACK_CYPRESS_RUN_LOCAL_BINARY = "true";
645+
}
643646
if (!localIdentifierRunning){
644647
bsConfig.connection_settings.usedAutoLocal = true;
645648
var bs_local = this.getLocalBinary();
@@ -675,22 +678,6 @@ exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
675678

676679
exports.stopLocalBinary = (bsConfig, bs_local, args, rawArgs) => {
677680
return new Promise(async (resolve, reject) => {
678-
if(bsConfig['connection_settings'] && bsConfig['connection_settings']['local']){
679-
let localIdentifierRunning = await this.checkLocalIdentifierRunning(bsConfig,bsConfig["connection_settings"]["local_identifier"]);
680-
if(!localIdentifierRunning){
681-
let message = `Local Binary not running.`,
682-
errorCode = 'local_identifier_error';
683-
this.sendUsageReport(
684-
bsConfig,
685-
args,
686-
message,
687-
Constants.messageTypes.ERROR,
688-
errorCode,
689-
null,
690-
rawArgs
691-
);
692-
}
693-
}
694681
if (!this.isUndefined(bs_local) && bs_local.isRunning() && bsConfig['connection_settings'] && bsConfig['connection_settings']['local_mode'].toLowerCase() != "always-on") {
695682
let that = this;
696683
bs_local.stop(function (localStopError) {
@@ -744,7 +731,7 @@ exports.generateLocalIdentifier = (mode) => {
744731
return Buffer.from(local_identifier).toString("base64");
745732
};
746733

747-
exports.checkLocalIdentifierRunning = (bsConfig, localIdentifier) => {
734+
exports.checklocalBinaryRunning = (bsConfig, localIdentifier) => {
748735
let options = {
749736
url: `${config.cypress_v1}/local_binary_running_check`,
750737
auth: {
@@ -762,13 +749,8 @@ exports.checkLocalIdentifierRunning = (bsConfig, localIdentifier) => {
762749
if(err){
763750
reject(err);
764751
}
765-
console.log(body);
766752
let response = JSON.parse(body);
767-
if(response['should_spawn_binary'] == true){
768-
resolve(false);
769-
} else {
770-
resolve(true);
771-
}
753+
resolve(response);
772754
});
773755
});
774756
};
@@ -1043,7 +1025,6 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
10431025
logger.info(message);
10441026
}
10451027
} catch(err) {
1046-
console.log(err);
10471028
message = Constants.userMessages.BUILD_STOP_FAILED;
10481029
messageType = Constants.messageTypes.ERROR;
10491030
errorCode = 'api_failed_build_stop';

0 commit comments

Comments
 (0)