browserstack-cypress-cli 1.12.0 → 1.13.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.
@@ -47,6 +47,7 @@ module.exports = function info(args, rawArgs) {
47
47
  errorCode = 'api_failed_build_info';
48
48
 
49
49
  logger.info(message);
50
+ logger.error(utils.formatRequest(err, resp, body));
50
51
  } else {
51
52
  let build = null;
52
53
  try {
@@ -66,6 +67,7 @@ module.exports = function info(args, rawArgs) {
66
67
  message = Constants.userMessages.API_DEPRECATED;
67
68
  logger.info(message);
68
69
  }
70
+ logger.info(utils.formatRequest(err, resp, body));
69
71
  } else if (resp.statusCode != 200) {
70
72
  messageType = Constants.messageTypes.ERROR;
71
73
  errorCode = 'api_failed_build_info';
@@ -80,6 +82,7 @@ module.exports = function info(args, rawArgs) {
80
82
  message = Constants.userMessages.BUILD_INFO_FAILED;
81
83
  logger.error(message);
82
84
  }
85
+ logger.error(utils.formatRequest(err, resp, body));
83
86
  } else {
84
87
  messageType = Constants.messageTypes.SUCCESS;
85
88
  message = `Build info for build id: \n ${JSON.stringify(
@@ -53,6 +53,9 @@ module.exports = function run(args, rawArgs) {
53
53
  // set cypress geo location
54
54
  utils.setGeolocation(bsConfig, args);
55
55
 
56
+ // set spec timeout
57
+ utils.setSpecTimeout(bsConfig, args);
58
+
56
59
  // accept the specs list from command line if provided
57
60
  utils.setUserSpecs(bsConfig, args);
58
61
 
@@ -112,16 +115,16 @@ module.exports = function run(args, rawArgs) {
112
115
  // warn if specFiles cross our limit
113
116
  utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
114
117
  markBlockEnd('preArchiveSteps');
115
- markBlockStart('checkAlreadyUploaded');
118
+ markBlockStart('zip');
119
+ markBlockStart('zip.checkAlreadyUploaded');
116
120
  return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
117
- markBlockEnd('checkAlreadyUploaded');
121
+ markBlockEnd('zip.checkAlreadyUploaded');
118
122
 
119
- markBlockStart('packageInstaller');
123
+ markBlockStart('zip.packageInstaller');
120
124
  return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
121
- markBlockEnd('packageInstaller');
125
+ markBlockEnd('zip.packageInstaller');
122
126
 
123
127
  // Archive the spec files
124
- markBlockStart('zip');
125
128
  markBlockStart('zip.archive');
126
129
  return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
127
130
  markBlockEnd('zip.archive');
@@ -204,7 +207,6 @@ module.exports = function run(args, rawArgs) {
204
207
  }).finally(() =>{
205
208
  let terminalWidth = (process.stdout.columns) * 0.9;
206
209
  let lineSeparator = "\n" + "-".repeat(terminalWidth);
207
- console.log(lineSeparator)
208
210
  logger.info(Constants.userMessages.BUILD_FAILED_ERROR)
209
211
  process.exitCode = Constants.BUILD_FAILED_EXIT_CODE;
210
212
  });
@@ -258,7 +260,7 @@ module.exports = function run(args, rawArgs) {
258
260
  utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
259
261
  return;
260
262
  }).catch(async function (err) {
261
- if (err && err.includes('browserstack.geoLocation')) {
263
+ if (err && err.toString().includes('browserstack.geoLocation')) {
262
264
  err = err.replace(/browserstack.geoLocation/g, 'geolocation');
263
265
  }
264
266
  // Build creation failed
@@ -4,7 +4,8 @@ const request = require('request');
4
4
  const config = require('./config'),
5
5
  capabilityHelper = require("../helpers/capabilityHelper"),
6
6
  Constants = require('../helpers/constants'),
7
- utils = require('../helpers/utils');
7
+ utils = require('../helpers/utils'),
8
+ logger = require('../helpers/logger').winstonLogger;
8
9
 
9
10
  const createBuild = (bsConfig, zip) => {
10
11
  return new Promise(function (resolve, reject) {
@@ -24,6 +25,7 @@ const createBuild = (bsConfig, zip) => {
24
25
 
25
26
  request.post(options, function (err, resp, body) {
26
27
  if (err) {
28
+ logger.error(utils.formatRequest(err, resp, body));
27
29
  reject(err);
28
30
  } else {
29
31
  let build = null;
@@ -37,9 +39,11 @@ const createBuild = (bsConfig, zip) => {
37
39
  if (build) {
38
40
  resolve(build.message);
39
41
  } else {
42
+ logger.error(utils.formatRequest(err, resp, body));
40
43
  reject(Constants.userMessages.API_DEPRECATED);
41
44
  }
42
45
  } else if (resp.statusCode != 201) {
46
+ logger.error(utils.formatRequest(err, resp, body));
43
47
  if (build) {
44
48
  reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
45
49
  } else {
@@ -162,6 +162,7 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) =>
162
162
  request.post(options, function (err, resp, data) {
163
163
  if(err) {
164
164
  utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
165
+ logger.error(utils.formatRequest(err, resp, body));
165
166
  reject(err);
166
167
  } else {
167
168
  try {
@@ -203,6 +204,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
203
204
  let buildDetails = null;
204
205
  request.get(options, async function (err, resp, body) {
205
206
  if(err) {
207
+ logger.error(utils.formatRequest(err, resp, body));
206
208
  utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
207
209
  process.exitCode = Constants.ERROR_EXIT_CODE;
208
210
  } else {
@@ -211,6 +213,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
211
213
  if(resp.statusCode != 200) {
212
214
  logger.error('Downloading the build artifacts failed.');
213
215
  logger.error(`Error: Request failed with status code ${resp.statusCode}`)
216
+ logger.error(utils.formatRequest(err, resp, body));
214
217
  utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
215
218
  process.exitCode = Constants.ERROR_EXIT_CODE;
216
219
  } else {
@@ -241,6 +244,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
241
244
  }
242
245
  utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs);
243
246
  logger.error(`Error: Request failed with status code ${resp.statusCode}`)
247
+ logger.error(utils.formatRequest(err, resp, body));
244
248
  process.exitCode = Constants.ERROR_EXIT_CODE;
245
249
  }
246
250
  }
@@ -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
 
@@ -219,6 +227,20 @@ const validate = (bsConfig, args) => {
219
227
  addCypressZipStartLocation(bsConfig.run_settings);
220
228
  }
221
229
 
230
+ if(!Utils.isUndefined(bsConfig.run_settings.spec_timeout)) {
231
+ if(Utils.isPositiveInteger(bsConfig.run_settings.spec_timeout.toString().trim())) {
232
+ if(Number(bsConfig.run_settings.spec_timeout) > Constants.SPEC_TIMEOUT_LIMIT) {
233
+ reject(Constants.validationMessages.SPEC_TIMEOUT_LIMIT_ERROR)
234
+ } else {
235
+ logger.info(Constants.userMessages.SPEC_LIMIT_SUCCESS_MESSAGE.replace("<x>", bsConfig.run_settings.spec_timeout));
236
+ }
237
+ } else {
238
+ logger.warn(Constants.userMessages.SPEC_TIMEOUT_LIMIT_WARNING)
239
+ }
240
+ } else {
241
+ logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
242
+ }
243
+
222
244
  resolve(cypressJson);
223
245
  });
224
246
  }
@@ -82,7 +82,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
82
82
  zipUrlPresent: false,
83
83
  packageUrlPresent: false,
84
84
  };
85
- if (args["force-upload"] && !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
85
+ if (args["force-upload"]) {
86
86
  return resolve(obj);
87
87
  }
88
88
 
@@ -56,13 +56,16 @@ 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>'",
62
63
  DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
63
64
  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",
64
65
  PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
65
- BUILD_FAILED_ERROR: "The above stacktrace has been thrown by Cypress when we tried to run your build. If your test suite requires npm dependencies then please specify them on browserstack.json. Read more at " + chalk.blueBright("https://www.browserstack.com/docs/automate/cypress/npm-packages") + ". Also, we recommend you to try running the build locally using ‘cypress run’ and if it works fine then please reach out to support at " + chalk.blueBright("https://www.browserstack.com/contact#technical-support")
66
+ BUILD_FAILED_ERROR: "The above stacktrace has been thrown by Cypress when we tried to run your build. If your test suite requires npm dependencies then please specify them on browserstack.json. Read more at " + chalk.blueBright("https://www.browserstack.com/docs/automate/cypress/npm-packages") + ". Also, we recommend you to try running the build locally using ‘cypress run’ and if it works fine then please reach out to support at " + chalk.blueBright("https://www.browserstack.com/contact#technical-support"),
67
+ SPEC_TIMEOUT_LIMIT_WARNING: "Value for the 'spec_timeout' key not in the 1-120 range. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout",
68
+ SPEC_LIMIT_SUCCESS_MESSAGE: "Spec timeout specified as <x> minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack"
66
69
  };
67
70
 
68
71
  const validationMessages = {
@@ -96,7 +99,9 @@ const validationMessages = {
96
99
  NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE: "IP Geolocation feature is not available in conjunction with BrowserStack Local.",
97
100
  HOME_DIRECTORY_NOT_FOUND: "Specified home directory could not be found. Please make sure the path of the home directory is correct.",
98
101
  HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
99
- CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory."
102
+ CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory.",
103
+ SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
104
+ SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout "
100
105
  };
101
106
 
102
107
  const cliMessages = {
@@ -139,7 +144,8 @@ const cliMessages = {
139
144
  CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.",
140
145
  REPORTER: "Specify the custom reporter to use",
141
146
  REPORTER_OPTIONS: "Specify reporter options for custom reporter",
142
- CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations."
147
+ CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations.",
148
+ SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details."
143
149
  },
144
150
  COMMON: {
145
151
  DISABLE_USAGE_REPORTING: "Disable usage reporting",
@@ -167,7 +173,7 @@ const messageTypes = {
167
173
  NULL: null
168
174
  }
169
175
 
170
- 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'];
176
+ 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', 'gz', 'tgz', 'tiff', 'bmp', 'msg', 'gif', 'sql'];
171
177
 
172
178
  const filesToIgnoreWhileUploading = [
173
179
  '**/node_modules/**',
@@ -225,6 +231,10 @@ const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
225
231
 
226
232
  const AUTH_REGEX = /"auth" *: *{[\s\S]*?}/g
227
233
 
234
+ const CLI_ARGS_REGEX = /(?<=("u"|"username"|"k"|"key") *: *)"[^,}]*/g
235
+
236
+ const RAW_ARGS_REGEX = /(?<=("-u"|"-username"|"-k"|"-key") *, *)"[^,\]]*/g
237
+
228
238
  const ERROR_EXIT_CODE = 1;
229
239
 
230
240
  const BUILD_FAILED_EXIT_CODE = 3;
@@ -233,6 +243,8 @@ const REDACTED = "[REDACTED]";
233
243
 
234
244
  const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED} }`;
235
245
 
246
+ const SPEC_TIMEOUT_LIMIT = 120 // IN MINS
247
+
236
248
  module.exports = Object.freeze({
237
249
  syncCLI,
238
250
  userMessages,
@@ -252,6 +264,10 @@ module.exports = Object.freeze({
252
264
  LATEST_VERSION_SYNTAX_REGEX,
253
265
  ERROR_EXIT_CODE,
254
266
  AUTH_REGEX,
267
+ CLI_ARGS_REGEX,
268
+ RAW_ARGS_REGEX,
255
269
  REDACTED_AUTH,
256
- BUILD_FAILED_EXIT_CODE
270
+ REDACTED,
271
+ BUILD_FAILED_EXIT_CODE,
272
+ SPEC_TIMEOUT_LIMIT
257
273
  });
@@ -7,7 +7,8 @@
7
7
  Constants = require('./constants'),
8
8
  process = require('process'),
9
9
  utils = require('./utils'),
10
- { spawn } = require('child_process');
10
+ { spawn } = require('child_process'),
11
+ util = require('util');
11
12
 
12
13
  let nodeProcess;
13
14
 
@@ -54,16 +55,18 @@ const packageInstall = (packageDir) => {
54
55
  return new Promise(function (resolve, reject) {
55
56
  const nodeProcessCloseCallback = (code) => {
56
57
  if(code == 0) {
58
+ logger.info(`Packages were installed locally successfully.`);
57
59
  resolve('Packages were installed successfully.');
58
60
  } else {
59
- reject('Packages were not installed successfully.');
61
+ logger.error(`Some error occurred while installing packages. Error code ${code}`);
62
+ reject('Packages were not installed successfully. Error code ${code}');
60
63
  }
61
64
  };
62
65
  const nodeProcessErrorCallback = (error) => {
63
- logger.error(`Some error occurred while installing packages: ${error}`);
64
- reject(`Packages were not installed successfully.`);
66
+ logger.error(`Some error occurred while installing packages: ${util.inspect(error)}`);
67
+ reject(`Packages were not installed successfully. Error Description ${util.inspect(error)}`);
65
68
  };
66
- nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install'], {cwd: packageDir});
69
+ nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
67
70
  nodeProcess.on('close', nodeProcessCloseCallback);
68
71
  nodeProcess.on('error', nodeProcessErrorCallback);
69
72
  });
@@ -105,14 +105,14 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
105
105
  let messageType = null;
106
106
  let errorCode = null;
107
107
  let build;
108
-
108
+
109
109
  if (err) {
110
110
  message = err;
111
111
  messageType = Constants.messageTypes.ERROR;
112
112
  errorCode = 'api_failed_build_report';
113
113
 
114
114
  logger.error('Generating the build report failed.');
115
- logger.error(message);
115
+ logger.error(utils.formatRequest(err, resp, body));
116
116
 
117
117
  utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
118
118
  return;
@@ -145,7 +145,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
145
145
  logger.error(`Error generating the report: ${error}`);
146
146
  response = {message: message};
147
147
  }
148
- logger.error(response.message);
148
+ logger.error(utils.formatRequest(err, resp, body));
149
149
  } else if (resp.statusCode != 200) {
150
150
  messageType = Constants.messageTypes.ERROR;
151
151
  errorCode = 'api_failed_build_generate_report';
@@ -158,7 +158,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, cb) => {
158
158
  if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
159
159
  } else {
160
160
  message = Constants.userMessages.BUILD_GENERATE_REPORT_FAILED.replace('<build-id>', buildId);
161
- logger.error(message);
161
+ logger.error(utils.formatRequest(err, resp, body));
162
162
  }
163
163
  } else {
164
164
  messageType = Constants.messageTypes.SUCCESS;
@@ -9,7 +9,7 @@ const config = require('./config'),
9
9
  fileLogger = require('./logger').fileLogger,
10
10
  utils = require('./utils');
11
11
 
12
- const { AUTH_REGEX, REDACTED_AUTH } = require("./constants");
12
+ const { AUTH_REGEX, REDACTED_AUTH, REDACTED, CLI_ARGS_REGEX, RAW_ARGS_REGEX } = require("./constants");
13
13
 
14
14
  function get_version(package_name) {
15
15
  try {
@@ -172,6 +172,10 @@ function isUsageReportingEnabled() {
172
172
  return process.env.DISABLE_USAGE_REPORTING;
173
173
  }
174
174
 
175
+ function redactKeys(str, regex, redact) {
176
+ return str.replace(regex, redact);
177
+ }
178
+
175
179
  function send(args) {
176
180
  if (isUsageReportingEnabled() === "true") return;
177
181
 
@@ -185,10 +189,12 @@ function send(args) {
185
189
  runSettings = bsConfig.run_settings;
186
190
  data.cypress_version = bsConfig.run_settings.cypress_version;
187
191
  }
188
-
189
- sanitizedbsConfig = `${(typeof bsConfig === 'string') ? bsConfig :
190
- JSON.stringify(bsConfig)}`.replace(AUTH_REGEX, REDACTED_AUTH);
191
-
192
+
193
+ sanitizedbsConfig = redactKeys(`${(typeof bsConfig === 'string') ? bsConfig :
194
+ JSON.stringify(bsConfig)}`, AUTH_REGEX, REDACTED_AUTH);
195
+ args.cli_args = args.cli_args && redactKeys(JSON.stringify(args.cli_args), CLI_ARGS_REGEX, REDACTED);
196
+ args.raw_args = args.raw_args && redactKeys(JSON.stringify(args.raw_args), RAW_ARGS_REGEX, REDACTED);
197
+
192
198
  delete args.bstack_config;
193
199
 
194
200
  let zipUploadDetails = {
@@ -7,6 +7,7 @@ const getmac = require('getmac').default;
7
7
  const { v4: uuidv4 } = require('uuid');
8
8
  const browserstack = require('browserstack-local');
9
9
  const crypto = require('crypto');
10
+ const util = require('util');
10
11
 
11
12
  const usageReporting = require("./usageReporting"),
12
13
  logger = require("./logger").winstonLogger,
@@ -309,6 +310,23 @@ exports.setGeolocation = (bsConfig, args) => {
309
310
  }
310
311
  }
311
312
 
313
+ exports.isSpecTimeoutArgPassed = () => {
314
+ return this.searchForOption('--spec-timeout') || this.searchForOption('-t');
315
+ }
316
+ exports.setSpecTimeout = (bsConfig, args) => {
317
+ let specTimeout = null;
318
+ if(this.isSpecTimeoutArgPassed()) {
319
+ if(!this.isUndefined(args.specTimeout)) {
320
+ specTimeout = args.specTimeout;
321
+ } else {
322
+ specTimeout = 'undefined'
323
+ }
324
+ } else if (!this.isUndefined(bsConfig.run_settings.spec_timeout)) {
325
+ specTimeout = bsConfig.run_settings.spec_timeout;
326
+ }
327
+ bsConfig.run_settings.spec_timeout = specTimeout;
328
+ }
329
+
312
330
  // specs can be passed from bstack configuration file
313
331
  // specs can be passed via command line args as a string
314
332
  // command line args takes precedence over config
@@ -389,10 +407,26 @@ exports.fixCommaSeparatedString = (string) => {
389
407
 
390
408
  exports.isUndefined = value => (value === undefined || value === null);
391
409
 
410
+ exports.isPositiveInteger = (str) => {
411
+ if (typeof str !== 'string') {
412
+ return false;
413
+ }
414
+
415
+ const num = Number(str);
416
+
417
+ if (this.isInteger(num) && num > 0) {
418
+ return true;
419
+ }
420
+
421
+ return false;
422
+ }
423
+
392
424
  exports.isTrueString = value => (!this.isUndefined(value) && value.toString().toLowerCase() === 'true');
393
425
 
394
426
  exports.isFloat = (value) => Number(value) && Number(value) % 1 !== 0;
395
427
 
428
+ exports.isInteger = (value) => Number.isInteger(value);
429
+
396
430
  exports.nonEmptyArray = (value) => {
397
431
  if(!this.isUndefined(value) && value && value.length) {
398
432
  return true;
@@ -593,11 +627,6 @@ exports.setLocalIdentifier = (bsConfig, args) => {
593
627
  !this.isUndefined(bsConfig["connection_settings"]["local_identifier"])
594
628
  ){
595
629
  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
630
  }
602
631
  };
603
632
 
@@ -637,9 +666,18 @@ exports.setLocalMode = (bsConfig, args) => {
637
666
  exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
638
667
  return new Promise(async (resolve, reject) => {
639
668
  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
- );
669
+ let localBinaryRunning = await this.checkLocalBinaryRunning(bsConfig, bsConfig['connection_settings']['local_identifier']);
670
+ let localIdentifierRunning;
671
+ if (localBinaryRunning['should_spawn_binary'] == true) {
672
+ localIdentifierRunning = false;
673
+ if(this.isUndefined(bsConfig["connection_settings"]["local_identifier"])) {
674
+ bsConfig["connection_settings"]["local_identifier"] = this.generateLocalIdentifier(bsConfig['connection_settings']['local_mode']);
675
+ }
676
+ } else {
677
+ localIdentifierRunning = true;
678
+ process.env.BSTACK_CYPRESS_LOCAL_BINARY_ALREADY_RUNNING = "true"; // shows message when binary is not spawned by the CLI process
679
+ process.env.BSTACK_CYPRESS_LOCAL_BINARY_RUNNING = "true";
680
+ }
643
681
  if (!localIdentifierRunning){
644
682
  bsConfig.connection_settings.usedAutoLocal = true;
645
683
  var bs_local = this.getLocalBinary();
@@ -648,6 +686,7 @@ exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
648
686
  logger.info('Setting up Local testing...');
649
687
  bs_local.start(bs_local_args, function (localStartError) {
650
688
  if (that.isUndefined(localStartError)) {
689
+ process.env.BSTACK_CYPRESS_LOCAL_BINARY_RUNNING = "true";
651
690
  resolve(bs_local);
652
691
  } else {
653
692
  let message = `name: ${localStartError.name}, message: ${localStartError.message}, extra: ${localStartError.extra}`,
@@ -675,22 +714,6 @@ exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
675
714
 
676
715
  exports.stopLocalBinary = (bsConfig, bs_local, args, rawArgs) => {
677
716
  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
717
  if (!this.isUndefined(bs_local) && bs_local.isRunning() && bsConfig['connection_settings'] && bsConfig['connection_settings']['local_mode'].toLowerCase() != "always-on") {
695
718
  let that = this;
696
719
  bs_local.stop(function (localStopError) {
@@ -744,35 +767,26 @@ exports.generateLocalIdentifier = (mode) => {
744
767
  return Buffer.from(local_identifier).toString("base64");
745
768
  };
746
769
 
747
- exports.checkLocalIdentifierRunning = (bsConfig, localIdentifier) => {
770
+ exports.checkLocalBinaryRunning = (bsConfig, localIdentifier) => {
748
771
  let options = {
749
- url: `${config.localTestingListUrl}?auth_token=${bsConfig.auth.access_key}&state=running`,
772
+ url: `${config.cypress_v1}/local_binary_running_check`,
750
773
  auth: {
751
774
  user: bsConfig.auth.username,
752
775
  password: bsConfig.auth.access_key,
753
776
  },
754
777
  headers: {
778
+ 'Content-Type': 'application/json',
755
779
  'User-Agent': this.getUserAgent(),
756
780
  },
781
+ body: JSON.stringify({ localIdentifier: localIdentifier}),
757
782
  };
758
- let that = this;
759
783
  return new Promise ( function(resolve, reject) {
760
- request.get(options, function (err, resp, body) {
784
+ request.post(options, function (err, resp, body) {
761
785
  if(err){
762
786
  reject(err);
763
787
  }
764
788
  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));
789
+ resolve(response);
776
790
  });
777
791
  });
778
792
  };
@@ -989,6 +1003,14 @@ exports.setCLIMode = (bsConfig, args) => {
989
1003
  }
990
1004
  }
991
1005
 
1006
+ exports.formatRequest = (err, resp, body) => {
1007
+ return {
1008
+ err,
1009
+ status: resp ? resp.statusCode : null,
1010
+ body: body ? util.format('%j', body) : null
1011
+ }
1012
+ }
1013
+
992
1014
  exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
993
1015
  let that = this;
994
1016
  return new Promise(function (resolve, reject) {
@@ -1047,7 +1069,6 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
1047
1069
  logger.info(message);
1048
1070
  }
1049
1071
  } catch(err) {
1050
- console.log(err);
1051
1072
  message = Constants.userMessages.BUILD_STOP_FAILED;
1052
1073
  messageType = Constants.messageTypes.ERROR;
1053
1074
  errorCode = 'api_failed_build_stop';
@@ -52,7 +52,7 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
52
52
  var r = request.post(options, function (err, resp, body) {
53
53
 
54
54
  if (err) {
55
- reject(err);
55
+ reject({message: err, stacktrace: utils.formatRequest(err, resp, body)});
56
56
  } else {
57
57
  try {
58
58
  responseData = JSON.parse(body);
@@ -63,9 +63,9 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
63
63
  if (resp.statusCode == 401) {
64
64
  if (responseData && responseData["error"]) {
65
65
  responseData["time"] = Date.now() - obj.startTime;
66
- return reject(responseData["error"]);
66
+ return reject({message: responseData["error"], stacktrace: utils.formatRequest(err, resp, body)});
67
67
  } else {
68
- return reject(Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS);
68
+ return reject({message: Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS, stacktrace: utils.formatRequest(err, resp, body)});
69
69
  }
70
70
  }
71
71
  if (!opts.propogateError){
@@ -73,12 +73,12 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
73
73
  }
74
74
  if(responseData && responseData["error"]){
75
75
  responseData["time"] = Date.now() - obj.startTime;
76
- reject(responseData["error"]);
76
+ reject({message: responseData["error"], stacktrace: utils.formatRequest(err, resp, body)});
77
77
  } else {
78
78
  if (resp.statusCode == 413) {
79
- reject(Constants.userMessages.ZIP_UPLOAD_LIMIT_EXCEEDED);
79
+ reject({message: Constants.userMessages.ZIP_UPLOAD_LIMIT_EXCEEDED, stacktrace: utils.formatRequest(err, resp, body)});
80
80
  } else {
81
- reject(Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE);
81
+ reject({message: Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE, stacktrace: utils.formatRequest(err, resp, body)});
82
82
  }
83
83
  }
84
84
  } else {
@@ -147,9 +147,10 @@ const uploadCypressZip = (bsConfig, md5data, packageData) => {
147
147
  });
148
148
  return resolve(obj);
149
149
  }).catch((error) => {
150
- purgeUploadBar(testZipUploadObj);
151
- purgeUploadBar(npmPackageZipUploadObj);
152
- return reject(error);
150
+ testZipUploadObj.bar1 && purgeUploadBar(testZipUploadObj);
151
+ npmPackageZipUploadObj.bar1 && purgeUploadBar(npmPackageZipUploadObj);
152
+ logger.error(error.stacktrace)
153
+ return reject(error.message);
153
154
  })
154
155
  })
155
156
  }
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({
@@ -168,6 +168,12 @@ var argv = yargs
168
168
  type: "string",
169
169
  default: undefined
170
170
  },
171
+ 't': {
172
+ alias: ['specTimeout'],
173
+ default: undefined,
174
+ describe: Constants.cliMessages.RUN.SPEC_TIMEOUT,
175
+ type: "string"
176
+ },
171
177
  'disable-npm-warning': {
172
178
  default: false,
173
179
  description: Constants.cliMessages.COMMON.NO_NPM_WARNING,
@@ -246,7 +252,7 @@ var argv = yargs
246
252
  }
247
253
  })
248
254
  .command('generate-report', Constants.cliMessages.GENERATE_REPORT.INFO, function(yargs) {
249
- let rawArgv = yargs.argv;
255
+ let rawArgv = process.argv.slice(2);
250
256
  argv = yargs
251
257
  .usage('usage: $0 generate-report <buildId>')
252
258
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
@@ -262,7 +268,7 @@ var argv = yargs
262
268
  }
263
269
  })
264
270
  .command('generate-downloads', Constants.cliMessages.GENERATE_DOWNLOADS.INFO, function(yargs) {
265
- let rawArgv = yargs.argv;
271
+ let rawArgv = process.argv.slice(2);
266
272
  argv = yargs
267
273
  .usage('usage: $0 generate-downloads <buildId>')
268
274
  .demand(1, Constants.cliMessages.BUILD.DEMAND)
@@ -56,7 +56,7 @@ module.exports = function () {
56
56
  "project_name": "project-name",
57
57
  "build_name": "build-name",
58
58
  "exclude": [],
59
- "parallels": "Here goes the number of parallels you want to run",
59
+ "parallels": "Number of parallels you want to run",
60
60
  "npm_dependencies": {
61
61
  },
62
62
  "package_config_options": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.12.0",
3
+ "version": "1.13.1",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,23 +12,23 @@
12
12
  "browserstack-cypress": "bin/runner.js"
13
13
  },
14
14
  "dependencies": {
15
- "archiver": "^5.2.0",
16
- "async": "^3.2.0",
17
- "browserstack-local": "^1.4.8",
18
- "chalk": "^4.1.0",
19
- "cli-progress": "^3.9.1",
20
- "fs-extra": "^8.1.0",
21
- "getmac": "^5.17.0",
22
- "glob": "^7.1.6",
23
- "mkdirp": "^1.0.3",
24
- "request": "^2.88.0",
25
- "requestretry": "^4.1.0",
26
- "table": "^5.4.6",
27
- "unzipper": "^0.10.11",
28
- "update-notifier": "^5.1.0",
29
- "uuid": "^8.3.2",
15
+ "archiver": "5.3.0",
16
+ "async": "3.2.3",
17
+ "browserstack-local": "1.4.8",
18
+ "chalk": "4.1.2",
19
+ "cli-progress": "3.10.0",
20
+ "fs-extra": "8.1.0",
21
+ "getmac": "5.20.0",
22
+ "glob": "7.2.0",
23
+ "mkdirp": "1.0.4",
24
+ "request": "2.88.2",
25
+ "requestretry": "4.1.2",
26
+ "table": "5.4.6",
27
+ "unzipper": "0.10.11",
28
+ "update-notifier": "5.1.0",
29
+ "uuid": "8.3.2",
30
30
  "winston": "2.4.4",
31
- "yargs": "^14.2.3"
31
+ "yargs": "14.2.3"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",
@@ -39,13 +39,13 @@
39
39
  "url": "https://github.com/browserstack/browserstack-cypress-cli/issues"
40
40
  },
41
41
  "devDependencies": {
42
- "chai": "^4.2.0",
43
- "chai-as-promised": "^7.1.1",
44
- "custom-env": "^2.0.1",
45
- "mocha": "^7.1.2",
46
- "nyc": "^15.0.1",
47
- "proxyquire": "^2.1.3",
48
- "rewire": "^5.0.0",
49
- "sinon": "^9.0.2"
42
+ "chai": "4.3.6",
43
+ "chai-as-promised": "7.1.1",
44
+ "custom-env": "2.0.1",
45
+ "mocha": "7.2.0",
46
+ "nyc": "15.1.0",
47
+ "proxyquire": "2.1.3",
48
+ "rewire": "5.0.0",
49
+ "sinon": "9.2.4"
50
50
  }
51
51
  }