browserstack-cypress-cli 1.10.1 → 1.11.0

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.
@@ -7,6 +7,7 @@ const syncCLI = {
7
7
  },
8
8
  INITIAL_DELAY_MULTIPLIER: 10,
9
9
  DEFAULT_LINE_SEP: "\n--------------------------------------------------------------------------------",
10
+ STARTUP_MESSAGE: "BrowserStack machines are now setting up Cypress with the specified npm dependencies for running your tests. It might take some time before your tests start runnning and showing up below..."
10
11
  };
11
12
 
12
13
  const userMessages = {
@@ -25,8 +26,11 @@ const userMessages = {
25
26
  MD5_CHECK_FAILED: "There was some issue while checking if zip is already uploaded.",
26
27
  ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
27
28
  ZIP_DELETED: "Deleted tests.zip successfully.",
29
+ NPM_DELETE_FAILED: "Could not delete the dependency packages.",
30
+ NPM_DELETED: "Deleted dependency packages successfully.",
28
31
  API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
29
32
  FAILED_TO_ZIP: "Failed to zip files.",
33
+ FAILED_CREATE_NPM_ARCHIVE: "CLI execution failed due to some issue in npm setup. Please retry.",
30
34
  FAILED_MD5_CHECK: "Something went wrong - you can retry running browserstack-cypress with ‘--force-upload’ parameter, or contact BrowserStack Support.",
31
35
  VISIT_DASHBOARD: "Visit the Automate dashboard for real-time test reporting:",
32
36
  CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
@@ -35,13 +39,16 @@ const userMessages = {
35
39
  NO_NPM_DEPENDENCIES_READ_MORE: "Read more about npm dependencies here: https://www.browserstack.com/docs/automate/cypress/npm-packages. You can suppress this warning by using --disable-npm-warning flag.",
36
40
  VALIDATING_CONFIG: "Validating the config",
37
41
  UPLOADING_TESTS: "Uploading the tests to BrowserStack",
42
+ UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully",
43
+ UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack",
44
+ UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
38
45
  LOCAL_TRUE: "you will now be able to test localhost / private URLs",
39
46
  LOCAL_FALSE: "you won't be able to test localhost / private URLs",
40
47
  EXIT_SYNC_CLI_MESSAGE: "Exiting the CLI, but your build is still running. You can use the --sync option to keep getting test updates. You can also use the build-info <build-id> command now.",
41
48
  FATAL_NETWORK_ERROR: `fatal: unable to access '${config.buildUrl}': Could not resolve host: ${config.rails_host}`,
42
49
  RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`,
43
50
  CHECK_DASHBOARD_AT: "Please check the build status at: ",
44
- CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
51
+ CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
45
52
  LOCAL_START_FAILED: "Local Testing setup failed.",
46
53
  LOCAL_STOP_FAILED: "Local Binary stop failed.",
47
54
  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",
@@ -49,7 +56,8 @@ const userMessages = {
49
56
  DOWNLOAD_BUILD_ARTIFACTS_FAILED: "Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
50
57
  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>'",
51
58
  DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
52
- LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions"
59
+ LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
60
+ PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
53
61
  };
54
62
 
55
63
  const validationMessages = {
@@ -74,7 +82,8 @@ const validationMessages = {
74
82
  INVALID_LOCAL_MODE: "When using --local-mode, a value needs to be supplied. \n--local-mode (\"always-on\" | \"on-demand\").\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
75
83
  INVALID_LOCAL_CONFIG_FILE: "Using --local-config-file requires an input of the form /path/to/config-file.yml.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
76
84
  INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
77
- INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference"
85
+ INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference",
86
+ INVALID_LOCAL_ASYNC_ARGS: "Cannot run in --async mode when local is set to true. Please run the build after removing --async",
78
87
  };
79
88
 
80
89
  const cliMessages = {
@@ -96,7 +105,7 @@ const cliMessages = {
96
105
  },
97
106
  RUN: {
98
107
  PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
99
- INFO: "Run your tests on BrowserStack.",
108
+ INFO: "Run your tests on BrowserStack. For more help: `browserstack-cypress run --help`.",
100
109
  CYPRESS_DESC: "Path to Cypress config file",
101
110
  CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
102
111
  BUILD_NAME: "The build name you want to use to name your test runs",
@@ -105,6 +114,7 @@ const cliMessages = {
105
114
  SPECS_DESCRIPTION: "Specify the spec files to run",
106
115
  ENV_DESCRIPTION: "Specify the environment variables for your spec files",
107
116
  SYNC_DESCRIPTION: "Makes the run command in sync",
117
+ ASYNC_DESCRIPTION: "Makes the run command in async",
108
118
  BUILD_REPORT_MESSAGE: "See the entire build report here",
109
119
  HEADED: "Run your tests in a headed browser instead of a headless browser",
110
120
  LOCAL: "Accepted values: (true | false) - create a local testing connection to let you test staging and localhost websites, or sites behind proxies; learn more at browserstack.com/local-testing",
@@ -143,7 +153,7 @@ const messageTypes = {
143
153
  NULL: null
144
154
  }
145
155
 
146
- const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env'];
156
+ const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env', 'mov', 'mp4', 'mp3', 'wav'];
147
157
 
148
158
  const filesToIgnoreWhileUploading = [
149
159
  '**/node_modules/**',
@@ -156,6 +166,8 @@ const filesToIgnoreWhileUploading = [
156
166
  '.idea/**',
157
167
  '.vscode/**',
158
168
  '.npm/**',
169
+ 'bstackPackages.tar.gz',
170
+ 'tmpBstackPackages/**',
159
171
  '.yarn/**',
160
172
  'build_artifacts/**'
161
173
  ];
@@ -175,6 +187,15 @@ const hashingOptions = {
175
187
  encoding: 'hex',
176
188
  };
177
189
 
190
+ const packageInstallerOptions = {
191
+ npmLoad: {
192
+ loglevel: 'silent',
193
+ only: 'dev',
194
+ 'save-dev': true,
195
+ 'only-dev': true,
196
+ }
197
+ }
198
+
178
199
  const specFileTypes = ['js', 'ts', 'feature', 'jsx', 'coffee', 'cjsx'];
179
200
 
180
201
  const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
@@ -188,6 +209,8 @@ const usageReportingConstants = {
188
209
 
189
210
  const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
190
211
 
212
+ const ERROR_EXIT_CODE = 1;
213
+
191
214
  module.exports = Object.freeze({
192
215
  syncCLI,
193
216
  userMessages,
@@ -198,10 +221,12 @@ module.exports = Object.freeze({
198
221
  filesToIgnoreWhileUploading,
199
222
  readDirOptions,
200
223
  hashingOptions,
224
+ packageInstallerOptions,
201
225
  specFileTypes,
202
226
  DEFAULT_CYPRESS_SPEC_PATH,
203
227
  SPEC_TOTAL_CHAR_LIMIT,
204
228
  METADATA_CHAR_BUFFER_PER_SPEC,
205
229
  usageReportingConstants,
206
- LATEST_VERSION_SYNTAX_REGEX
230
+ LATEST_VERSION_SYNTAX_REGEX,
231
+ ERROR_EXIT_CODE
207
232
  });
@@ -4,6 +4,7 @@ const fs = require('fs-extra'),
4
4
 
5
5
  const logger = require('./logger').winstonLogger,
6
6
  Constants = require('../helpers/constants'),
7
+ process = require('process'),
7
8
  config = require('../helpers/config');
8
9
 
9
10
  exports.write = function (f, message, args, cb) {
@@ -35,6 +36,19 @@ exports.deleteZip = () => {
35
36
  }
36
37
  };
37
38
 
39
+ exports.deletePackageArchieve = (logging = true) => {
40
+ try {
41
+ delete process.env.CYPRESS_INSTALL_BINARY;
42
+ fs.removeSync(config.packageFileName);
43
+ fs.removeSync(config.packageDirName);
44
+ if (logging) logger.info(Constants.userMessages.NPM_DELETED);
45
+ return 0;
46
+ } catch (err) {
47
+ if (logging) logger.info(Constants.userMessages.NPM_DELETE_FAILED);
48
+ return 1;
49
+ }
50
+ };
51
+
38
52
  exports.dirExists = function (filePath, cb) {
39
53
  let exists = false;
40
54
  if (fs.existsSync(path.dirname(filePath), cb)) {
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+ const npm = require('npm'),
3
+ archiver = require("archiver"),
4
+ path = require('path'),
5
+ os = require('os'),
6
+ fs = require('fs-extra'),
7
+ fileHelpers = require('./fileHelpers'),
8
+ logger = require("./logger").winstonLogger,
9
+ Constants = require('./constants'),
10
+ process = require('process'),
11
+ utils = require('./utils');
12
+
13
+ const setupPackageFolder = (runSettings, directoryPath) => {
14
+ return new Promise(function (resolve, reject) {
15
+ fileHelpers.deletePackageArchieve(false);
16
+ fs.mkdir(directoryPath, function (err) {
17
+ try {
18
+ if (err) {
19
+ return reject(err);
20
+ }
21
+ let packageJSON = {};
22
+ if (typeof runSettings.package_config_options === 'object') {
23
+ Object.assign(packageJSON, runSettings.package_config_options);
24
+ }
25
+
26
+ if (typeof runSettings.npm_dependencies === 'object') {
27
+ Object.assign(packageJSON, {
28
+ devDependencies: runSettings.npm_dependencies,
29
+ });
30
+ }
31
+
32
+ if (Object.keys(packageJSON).length > 0) {
33
+ let packageJSONString = JSON.stringify(packageJSON);
34
+ let packagePath = path.join(directoryPath, "package.json");
35
+ fs.writeFileSync(packagePath, packageJSONString);
36
+ let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
37
+ let sourceNpmrc = path.join(cypressFolderPath, ".npmrc");
38
+ let destNpmrc = path.join(directoryPath, ".npmrc");
39
+ if (fs.existsSync(sourceNpmrc)) {
40
+ fs.copyFileSync(sourceNpmrc, destNpmrc);
41
+ }
42
+ return resolve("package file created");
43
+ }
44
+ return reject("Nothing in package file");
45
+ } catch(error) {
46
+ return reject(error);
47
+ }
48
+ })
49
+ })
50
+ };
51
+
52
+ const packageInstall = (packageDir) => {
53
+ return new Promise(function (resolve, reject) {
54
+ let savedPrefix = null;
55
+ let npmLoad = Constants.packageInstallerOptions.npmLoad
56
+ npmLoad["cache"] = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
57
+ const installCallback = (err, result) => {
58
+ npm.prefix = savedPrefix;
59
+ if (err) {
60
+ return reject(err);
61
+ }
62
+ resolve(result);
63
+ };
64
+ const loadCallback = (err) => {
65
+ if (err) {
66
+ return reject(err);
67
+ }
68
+ savedPrefix = npm.prefix;
69
+ npm.prefix = packageDir;
70
+ npm.commands.install(packageDir, [], installCallback);
71
+ };
72
+ npm.load(npmLoad, loadCallback);
73
+ });
74
+ };
75
+
76
+ const packageArchiver = (packageDir, packageFile) => {
77
+ return new Promise(function (resolve, reject) {
78
+ let output = fs.createWriteStream(packageFile);
79
+ let archive = archiver('tar', {
80
+ gzip: true
81
+ });
82
+ archive.on('warning', function (err) {
83
+ if (err.code === 'ENOENT') {
84
+ logger.info(err);
85
+ } else {
86
+ reject(err);
87
+ }
88
+ });
89
+
90
+ output.on('close', function () {
91
+ resolve('Zipping completed');
92
+ });
93
+
94
+ output.on('end', function () {
95
+ logger.info('Data has been drained');
96
+ });
97
+
98
+ archive.on('error', function (err) {
99
+ reject(err);
100
+ });
101
+
102
+ archive.pipe(output);
103
+ archive.directory(packageDir, false);
104
+ archive.finalize();
105
+ })
106
+ }
107
+
108
+ const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBlocks) => {
109
+ return new Promise(function (resolve) {
110
+ let obj = {
111
+ packageArchieveCreated: false
112
+ };
113
+ if (md5data.packageUrlPresent || !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
114
+ return resolve(obj);
115
+ }
116
+ logger.info(`Installing required dependencies and building the package to upload to BrowserStack`);
117
+ instrumentBlocks.markBlockStart("packageInstaller.folderSetup");
118
+ return setupPackageFolder(bsConfig.run_settings, packageDir).then((_result) => {
119
+ process.env.CYPRESS_INSTALL_BINARY = 0
120
+ instrumentBlocks.markBlockEnd("packageInstaller.folderSetup");
121
+ instrumentBlocks.markBlockStart("packageInstaller.packageInstall");
122
+ return packageInstall(packageDir);
123
+ }).then((_result) => {
124
+ instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");
125
+ instrumentBlocks.markBlockStart("packageInstaller.packageArchive");
126
+ return packageArchiver(packageDir, packageFile);
127
+ }).then((_result) => {
128
+ instrumentBlocks.markBlockEnd("packageInstaller.packageArchive");
129
+ Object.assign(obj, { packageArchieveCreated: true });
130
+ return resolve(obj);
131
+ }).catch((err) => {
132
+ obj.error = err.stack.substring(0,100);
133
+ return resolve(obj);
134
+ })
135
+ })
136
+ }
137
+
138
+ exports.packageWrapper = packageWrapper;
@@ -277,7 +277,10 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){
277
277
  });
278
278
  combination.tests = sessionTests;
279
279
  resolve(combination.tests);
280
- } catch (error) { reject(error) }
280
+ } catch (error) {
281
+ process.exitCode = Constants.ERROR_EXIT_CODE;
282
+ reject(error);
283
+ }
281
284
  })
282
285
  }
283
286
 
@@ -308,7 +311,10 @@ function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
308
311
  });
309
312
  combination.tests = sessionTests;
310
313
  resolve(combination.tests);
311
- } catch (error) { reject(error) }
314
+ } catch (error) {
315
+ process.exitCode = Constants.ERROR_EXIT_CODE;
316
+ reject(error);
317
+ }
312
318
  })
313
319
  }
314
320
 
@@ -3,6 +3,7 @@ const request = require("request"),
3
3
  config = require("../config"),
4
4
  utils = require("../utils"),
5
5
  logger = require("../logger").syncCliLogger,
6
+ winstonLogger = require("../logger").winstonLogger,
6
7
  async = require('async'),
7
8
  Constants = require("../constants"),
8
9
  tableStream = require('table').createStream,
@@ -164,6 +165,7 @@ let showSpecsStatus = (data) => {
164
165
  }
165
166
 
166
167
  let printInitialLog = () => {
168
+ winstonLogger.info(Constants.syncCLI.STARTUP_MESSAGE);
167
169
  logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`)
168
170
  logger.info(lineSeparator);
169
171
  n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
@@ -13,9 +13,11 @@ const usageReporting = require("./usageReporting"),
13
13
  Constants = require("./constants"),
14
14
  chalk = require('chalk'),
15
15
  syncCliLogger = require("../helpers/logger").syncCliLogger,
16
+ fileHelpers = require("./fileHelpers"),
16
17
  config = require("../helpers/config");
17
18
 
18
19
  const request = require('request');
20
+ const axios = require("axios");
19
21
 
20
22
  exports.validateBstackJson = (bsConfigPath) => {
21
23
  return new Promise(function (resolve, reject) {
@@ -80,6 +82,9 @@ exports.getErrorCodeFromMsg = (errMsg) => {
80
82
  case Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE:
81
83
  errorCode = 'invalid_cypress_config_file';
82
84
  break;
85
+ case Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS:
86
+ errorCode = 'invalid_local_async_args';
87
+ break;
83
88
  }
84
89
  if (
85
90
  errMsg.includes("Please use --config-file <path to browserstack.json>.")
@@ -187,6 +192,11 @@ exports.setDefaults = (bsConfig, args) => {
187
192
  bsConfig.connection_settings = {};
188
193
  }
189
194
 
195
+ // setting cache_dependencies to true if not present
196
+ if (this.isUndefined(bsConfig.run_settings.cache_dependencies)) {
197
+ bsConfig.run_settings.cache_dependencies = true;
198
+ }
199
+
190
200
  }
191
201
 
192
202
  exports.setUsername = (bsConfig, args) => {
@@ -334,6 +344,8 @@ exports.fixCommaSeparatedString = (string) => {
334
344
 
335
345
  exports.isUndefined = value => (value === undefined || value === null);
336
346
 
347
+ exports.isTrueString = value => (!this.isUndefined(value) && value.toString().toLowerCase() === 'true');
348
+
337
349
  exports.isFloat = (value) => Number(value) && Number(value) % 1 !== 0;
338
350
 
339
351
  exports.nonEmptyArray = (value) => {
@@ -404,6 +416,82 @@ exports.isCypressProjDirValid = (cypressProjDir, integrationFoldDir) => {
404
416
  return parentTokens.every((t, i) => childTokens[i] === t);
405
417
  };
406
418
 
419
+ exports.generateUploadParams = (bsConfig, filePath, md5data, fileDetails) => {
420
+ let options = {
421
+ url: config.uploadUrl,
422
+ auth: {
423
+ user: bsConfig.auth.username,
424
+ password: bsConfig.auth.access_key
425
+ },
426
+ formData: {
427
+ file: fs.createReadStream(filePath),
428
+ filetype: fileDetails.filetype,
429
+ filename: fileDetails.filename,
430
+ zipMd5sum: md5data ? md5data : '',
431
+ },
432
+ headers: {
433
+ "User-Agent": exports.getUserAgent(),
434
+ }
435
+ }
436
+ return options
437
+ }
438
+
439
+ exports.sortJsonKeys = (unordered) => {
440
+ const ordered = Object.keys(unordered).sort().reduce(
441
+ (obj, key) => {
442
+ obj[key] = unordered[key];
443
+ return obj;
444
+ },
445
+ {}
446
+ );
447
+ return ordered
448
+ }
449
+
450
+ exports.generateUploadOptions = (type, md5data, packageData) => {
451
+ let options = {};
452
+ switch (type) {
453
+ case 'zip':
454
+ options = {
455
+ archivePresent: true,
456
+ md5ReturnKey: "zip_url",
457
+ urlPresent: md5data.zipUrlPresent,
458
+ md5Data: md5data.zip_md5sum,
459
+ url: md5data.zipUrl,
460
+ propogateError: true,
461
+ fileDetails: {
462
+ filetype: "zip",
463
+ filename: "tests"
464
+ },
465
+ messages: {
466
+ uploading: Constants.userMessages.UPLOADING_TESTS,
467
+ uploadingSuccess: Constants.userMessages.UPLOADING_TESTS_SUCCESS
468
+ },
469
+ cleanupMethod: fileHelpers.deleteZip,
470
+ }
471
+ break;
472
+ case 'npm':
473
+ options = {
474
+ archivePresent: packageData.packageArchieveCreated,
475
+ md5ReturnKey: "npm_package_url",
476
+ urlPresent: md5data.packageUrlPresent,
477
+ md5Data: md5data.npm_package_md5sum,
478
+ url: md5data.npmPackageUrl,
479
+ propogateError: false,
480
+ fileDetails: {
481
+ filetype: "tar.gz",
482
+ filename: "bstackPackages"
483
+ },
484
+ messages: {
485
+ uploading: Constants.userMessages.UPLOADING_NPM_PACKAGES,
486
+ uploadingSuccess: Constants.userMessages.UPLOADING_NPM_PACKAGES_SUCCESS
487
+ },
488
+ cleanupMethod: fileHelpers.deletePackageArchieve,
489
+ }
490
+ break;
491
+ }
492
+ return options;
493
+ };
494
+
407
495
  exports.getLocalFlag = (connectionSettings) => {
408
496
  return (
409
497
  !this.isUndefined(connectionSettings) &&
@@ -733,18 +821,27 @@ exports.getNetworkErrorMessage = (dashboard_url) => {
733
821
  return chalk.red(message)
734
822
  }
735
823
 
736
- exports.versionChangedMessage = (preferredVersion, actualVersion) => {
824
+ exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => {
737
825
  let message = Constants.userMessages.CYPRESS_VERSION_CHANGED.replace("<preferredVersion>", preferredVersion);
738
826
  message = message.replace("<actualVersion>", actualVersion);
827
+ frameworkUpgradeMessage = frameworkUpgradeMessage.replace('.latest', "");
828
+ message = message.replace('<frameworkUpgradeMessage>', frameworkUpgradeMessage);
739
829
  return message
740
830
  }
741
831
 
742
- exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion) => {
832
+ exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion, frameworkUpgradeMessage = '') => {
743
833
  let message = Constants.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("<latestSyntaxVersion>", latestSyntaxVersion);
744
834
  message = message.replace("<actualVersion>", actualVersion);
835
+ message = message.replace('<frameworkUpgradeMessage>', frameworkUpgradeMessage)
745
836
  return message
746
837
  }
747
838
 
839
+ exports.checkError = (data) => {
840
+ if (!this.isUndefined(data.error)) {
841
+ return data.error
842
+ }
843
+ }
844
+
748
845
  exports.isJSONInvalid = (err, args) => {
749
846
  let invalid = true
750
847
 
@@ -760,6 +857,10 @@ exports.isJSONInvalid = (err, args) => {
760
857
  return false
761
858
  }
762
859
 
860
+ if( err === Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS && !this.isUndefined(args.async)) {
861
+ return false
862
+ }
863
+
763
864
  return invalid
764
865
  }
765
866
 
@@ -820,3 +921,94 @@ exports.getCypressJSON = (bsConfig) => {
820
921
  }
821
922
  return cypressJSON;
822
923
  }
924
+
925
+ exports.setCLIMode = (bsConfig, args) => {
926
+ args.sync = true;
927
+ if(!this.isUndefined(args.async) && args.async){
928
+ args.sync = false;
929
+ }
930
+ }
931
+
932
+ exports.stopBrowserStackBuild = async (bsConfig, args, buildId ) => {
933
+ let url = config.buildStopUrl + buildId;
934
+ let options = {
935
+ url: url,
936
+ auth: {
937
+ username: bsConfig["auth"]["username"],
938
+ password: bsConfig["auth"]["access_key"],
939
+ },
940
+ headers: {
941
+ 'User-Agent': this.getUserAgent(),
942
+ },
943
+ };
944
+
945
+ let message = null;
946
+ let messageType = null;
947
+ let errorCode = null;
948
+ try{
949
+ let resp = await axios.post(url, {} , options);
950
+ let build = null;
951
+ if(resp.data){
952
+ build = resp.data;
953
+ }
954
+
955
+ if (resp.status == 299) {
956
+ messageType = Constants.messageTypes.INFO;
957
+ errorCode = 'api_deprecated';
958
+
959
+ if (build) {
960
+ message = build.message;
961
+ logger.info(message);
962
+ } else {
963
+ message = Constants.userMessages.API_DEPRECATED;
964
+ logger.info(message);
965
+ }
966
+ } else if (resp.status != 200) {
967
+ messageType = Constants.messageTypes.ERROR;
968
+ errorCode = 'api_failed_build_stop';
969
+
970
+ if (build) {
971
+ message = `${
972
+ Constants.userMessages.BUILD_STOP_FAILED
973
+ } with error: \n${JSON.stringify(build, null, 2)}`;
974
+ logger.error(message);
975
+ if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
976
+ } else {
977
+ message = Constants.userMessages.BUILD_STOP_FAILED;
978
+ logger.error(message);
979
+ }
980
+ } else {
981
+ messageType = Constants.messageTypes.SUCCESS;
982
+ message = `${JSON.stringify(build, null, 2)}`;
983
+ logger.info(message);
984
+ }
985
+ } catch(err){
986
+ console.log(err);
987
+ message = Constants.userMessages.BUILD_STOP_FAILED;
988
+ messageType = Constants.messageTypes.ERROR;
989
+ errorCode = 'api_failed_build_stop';
990
+ logger.info(message);
991
+ } finally {
992
+ this.sendUsageReport(bsConfig, args, message, messageType, errorCode);
993
+ }
994
+ }
995
+
996
+ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args) => {
997
+ let bindData = {
998
+ buildId: buildId,
999
+ bsConfig: bsConfig,
1000
+ bsLocalInstance: bsLocal,
1001
+ args: args
1002
+ }
1003
+ process.on('SIGINT', processExitHandler.bind(this, bindData));
1004
+ process.on('SIGTERM', processExitHandler.bind(this, bindData));
1005
+ process.on('SIGBREAK', processExitHandler.bind(this, bindData));
1006
+ process.on('uncaughtException', processExitHandler.bind(this, bindData));
1007
+ }
1008
+
1009
+ async function processExitHandler(exitData){
1010
+ logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
1011
+ await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId);
1012
+ await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args);
1013
+ process.exit(0);
1014
+ }