browserstack-cypress-cli 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,16 +112,16 @@ module.exports = function run(args, rawArgs) {
112
112
  // warn if specFiles cross our limit
113
113
  utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
114
114
  markBlockEnd('preArchiveSteps');
115
- markBlockStart('checkAlreadyUploaded');
115
+ markBlockStart('zip');
116
+ markBlockStart('zip.checkAlreadyUploaded');
116
117
  return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
117
- markBlockEnd('checkAlreadyUploaded');
118
+ markBlockEnd('zip.checkAlreadyUploaded');
118
119
 
119
- markBlockStart('packageInstaller');
120
+ markBlockStart('zip.packageInstaller');
120
121
  return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
121
- markBlockEnd('packageInstaller');
122
+ markBlockEnd('zip.packageInstaller');
122
123
 
123
124
  // Archive the spec files
124
- markBlockStart('zip');
125
125
  markBlockStart('zip.archive');
126
126
  return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
127
127
  markBlockEnd('zip.archive');
@@ -204,7 +204,6 @@ module.exports = function run(args, rawArgs) {
204
204
  }).finally(() =>{
205
205
  let terminalWidth = (process.stdout.columns) * 0.9;
206
206
  let lineSeparator = "\n" + "-".repeat(terminalWidth);
207
- console.log(lineSeparator)
208
207
  logger.info(Constants.userMessages.BUILD_FAILED_ERROR)
209
208
  process.exitCode = Constants.BUILD_FAILED_EXIT_CODE;
210
209
  });
@@ -258,7 +257,7 @@ module.exports = function run(args, rawArgs) {
258
257
  utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
259
258
  return;
260
259
  }).catch(async function (err) {
261
- if (err && err.includes('browserstack.geoLocation')) {
260
+ if (err && err.toString().includes('browserstack.geoLocation')) {
262
261
  err = err.replace(/browserstack.geoLocation/g, 'geolocation');
263
262
  }
264
263
  // Build creation failed
@@ -71,21 +71,31 @@ const caps = (bsConfig, zip) => {
71
71
  obj.local = true;
72
72
  }
73
73
 
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_LOCAL_BINARY_RUNNING) && process.env.BSTACK_CYPRESS_LOCAL_BINARY_RUNNING == "true") {
77
+ obj.localMode = null;
78
+
79
+ // Local Mode
80
+ if (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 (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
+ }
80
94
  }
81
- logger.info(`Local testing set up in ${obj.localMode} mode.`);
82
95
  }
83
96
 
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}`);
97
+ if (!Utils.isUndefined(process.env.BSTACK_CYPRESS_LOCAL_BINARY_ALREADY_RUNNING) && process.env.BSTACK_CYPRESS_LOCAL_BINARY_ALREADY_RUNNING == "true") {
98
+ logger.info(Constants.userMessages.LOCAL_BINARY_ALREADY_RUNNING);
89
99
  }
90
100
 
91
101
  logger.info(`Local is set to: ${obj.local} (${obj.local ? Constants.userMessages.LOCAL_TRUE : Constants.userMessages.LOCAL_FALSE})`);
@@ -164,8 +174,6 @@ const validate = (bsConfig, args) => {
164
174
  // validate local args i.e --local-mode and --local-identifier
165
175
 
166
176
  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);
169
177
 
170
178
  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);
171
179
 
@@ -56,6 +56,7 @@ const userMessages = {
56
56
  LOCAL_START_FAILED: "Local Testing setup failed.",
57
57
  LOCAL_STOP_FAILED: "Local Binary stop failed.",
58
58
  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.",
59
60
  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.",
60
61
  DOWNLOAD_BUILD_ARTIFACTS_FAILED: "Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
61
62
  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>'",
@@ -593,11 +593,6 @@ exports.setLocalIdentifier = (bsConfig, args) => {
593
593
  !this.isUndefined(bsConfig["connection_settings"]["local_identifier"])
594
594
  ){
595
595
  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']);
601
596
  }
602
597
  };
603
598
 
@@ -637,9 +632,18 @@ exports.setLocalMode = (bsConfig, args) => {
637
632
  exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
638
633
  return new Promise(async (resolve, reject) => {
639
634
  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_LOCAL_BINARY_ALREADY_RUNNING = "true"; // shows message when binary is not spawned by the CLI process
645
+ process.env.BSTACK_CYPRESS_LOCAL_BINARY_RUNNING = "true";
646
+ }
643
647
  if (!localIdentifierRunning){
644
648
  bsConfig.connection_settings.usedAutoLocal = true;
645
649
  var bs_local = this.getLocalBinary();
@@ -648,6 +652,7 @@ exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
648
652
  logger.info('Setting up Local testing...');
649
653
  bs_local.start(bs_local_args, function (localStartError) {
650
654
  if (that.isUndefined(localStartError)) {
655
+ process.env.BSTACK_CYPRESS_LOCAL_BINARY_RUNNING = "true";
651
656
  resolve(bs_local);
652
657
  } else {
653
658
  let message = `name: ${localStartError.name}, message: ${localStartError.message}, extra: ${localStartError.extra}`,
@@ -675,22 +680,6 @@ exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
675
680
 
676
681
  exports.stopLocalBinary = (bsConfig, bs_local, args, rawArgs) => {
677
682
  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
- }
694
683
  if (!this.isUndefined(bs_local) && bs_local.isRunning() && bsConfig['connection_settings'] && bsConfig['connection_settings']['local_mode'].toLowerCase() != "always-on") {
695
684
  let that = this;
696
685
  bs_local.stop(function (localStopError) {
@@ -744,35 +733,26 @@ exports.generateLocalIdentifier = (mode) => {
744
733
  return Buffer.from(local_identifier).toString("base64");
745
734
  };
746
735
 
747
- exports.checkLocalIdentifierRunning = (bsConfig, localIdentifier) => {
736
+ exports.checkLocalBinaryRunning = (bsConfig, localIdentifier) => {
748
737
  let options = {
749
- url: `${config.localTestingListUrl}?auth_token=${bsConfig.auth.access_key}&state=running`,
738
+ url: `${config.cypress_v1}/local_binary_running_check`,
750
739
  auth: {
751
740
  user: bsConfig.auth.username,
752
741
  password: bsConfig.auth.access_key,
753
742
  },
754
743
  headers: {
744
+ 'Content-Type': 'application/json',
755
745
  'User-Agent': this.getUserAgent(),
756
746
  },
747
+ body: JSON.stringify({ localIdentifier: localIdentifier}),
757
748
  };
758
- let that = this;
759
749
  return new Promise ( function(resolve, reject) {
760
- request.get(options, function (err, resp, body) {
750
+ request.post(options, function (err, resp, body) {
761
751
  if(err){
762
752
  reject(err);
763
753
  }
764
754
  let response = JSON.parse(body);
765
- let localInstances = [];
766
- if(!that.isUndefined(response['instances'])){
767
- localInstances = response['instances'];
768
- }
769
- let localIdentifiers = [];
770
-
771
- localInstances.forEach(function(instance){
772
- localIdentifiers.push(instance['localIdentifier']);
773
- });
774
-
775
- resolve(localIdentifiers.includes(localIdentifier));
755
+ resolve(response);
776
756
  });
777
757
  });
778
758
  };
@@ -1047,7 +1027,6 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
1047
1027
  logger.info(message);
1048
1028
  }
1049
1029
  } catch(err) {
1050
- console.log(err);
1051
1030
  message = Constants.userMessages.BUILD_STOP_FAILED;
1052
1031
  messageType = Constants.messageTypes.ERROR;
1053
1032
  errorCode = 'api_failed_build_stop';
package/bin/runner.js CHANGED
@@ -67,7 +67,7 @@ var argv = yargs
67
67
  .showHelpOnFail(false, Constants.cliMessages.VERSION.HELP)
68
68
  .demand(1, Constants.cliMessages.VERSION.DEMAND)
69
69
  .command('init', Constants.cliMessages.INIT.INFO, function(yargs) {
70
- let rawArgv = yargs.argv;
70
+ let rawArgv = process.argv.slice(2);
71
71
  argv = yargs
72
72
  .usage("usage: $0 init [filename] [options]")
73
73
  .options({
@@ -87,7 +87,7 @@ var argv = yargs
87
87
  }
88
88
  })
89
89
  .command('build-info', Constants.cliMessages.BUILD.INFO, function(yargs) {
90
- let rawArgv = yargs.argv;
90
+ let rawArgv = process.argv.slice(2);
91
91
  argv = yargs
92
92
  .usage('usage: $0 <buildId>')
93
93
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
@@ -103,7 +103,7 @@ var argv = yargs
103
103
  }
104
104
  })
105
105
  .command('build-stop', Constants.cliMessages.BUILD.STOP, function (yargs) {
106
- let rawArgv = yargs.argv;
106
+ let rawArgv = process.argv.slice(2);
107
107
  argv = yargs
108
108
  .usage('usage: $0 <buildId>')
109
109
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
@@ -119,7 +119,7 @@ var argv = yargs
119
119
  }
120
120
  })
121
121
  .command('run', Constants.cliMessages.RUN.INFO, function(yargs) {
122
- let rawArgv = yargs.argv;
122
+ let rawArgv = process.argv.slice(2);
123
123
  argv = yargs
124
124
  .usage('usage: $0 run <options>')
125
125
  .options({
@@ -246,7 +246,7 @@ var argv = yargs
246
246
  }
247
247
  })
248
248
  .command('generate-report', Constants.cliMessages.GENERATE_REPORT.INFO, function(yargs) {
249
- let rawArgv = yargs.argv;
249
+ let rawArgv = process.argv.slice(2);
250
250
  argv = yargs
251
251
  .usage('usage: $0 generate-report <buildId>')
252
252
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
@@ -262,7 +262,7 @@ var argv = yargs
262
262
  }
263
263
  })
264
264
  .command('generate-downloads', Constants.cliMessages.GENERATE_DOWNLOADS.INFO, function(yargs) {
265
- let rawArgv = yargs.argv;
265
+ let rawArgv = process.argv.slice(2);
266
266
  argv = yargs
267
267
  .usage('usage: $0 generate-downloads <buildId>')
268
268
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {