browserstack-cypress-cli 1.11.0 → 1.11.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.
@@ -6,7 +6,7 @@ const logger = require("../helpers/logger").winstonLogger,
6
6
  downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts;
7
7
 
8
8
 
9
- module.exports = async function generateDownloads(args) {
9
+ module.exports = async function generateDownloads(args, rawArgs) {
10
10
  let bsConfigPath = utils.getConfigPath(args.cf);
11
11
 
12
12
  return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
@@ -28,12 +28,12 @@ module.exports = async function generateDownloads(args) {
28
28
  let errorCode = null;
29
29
  let buildId = args._[1];
30
30
 
31
- await downloadBuildArtifacts(bsConfig, buildId, args);
32
- utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode);
31
+ await downloadBuildArtifacts(bsConfig, buildId, args, rawArgs);
32
+ utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode, null, rawArgs);
33
33
  }).catch(function (err) {
34
34
  logger.error(err);
35
35
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
36
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
36
+ utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
37
37
  process.exitCode = Constants.ERROR_EXIT_CODE;
38
38
  });
39
39
  };
@@ -6,7 +6,7 @@ const logger = require("../helpers/logger").winstonLogger,
6
6
  reporterHTML = require('../helpers/reporterHTML');
7
7
 
8
8
 
9
- module.exports = function generateReport(args) {
9
+ module.exports = function generateReport(args, rawArgs) {
10
10
  let bsConfigPath = utils.getConfigPath(args.cf);
11
11
  let reportGenerator = reporterHTML.reportGenerator;
12
12
 
@@ -29,12 +29,12 @@ module.exports = function generateReport(args) {
29
29
  let errorCode = null;
30
30
  let buildId = args._[1];
31
31
 
32
- reportGenerator(bsConfig, buildId, args);
33
- utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode);
32
+ reportGenerator(bsConfig, buildId, args, rawArgs);
33
+ utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode, null, rawArgs);
34
34
  }).catch(function (err) {
35
35
  logger.error(err);
36
36
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
37
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
37
+ utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
38
38
  process.exitCode = Constants.ERROR_EXIT_CODE;
39
39
  });
40
40
  };
@@ -6,7 +6,7 @@ const config = require("../helpers/config"),
6
6
  Constants = require("../helpers/constants"),
7
7
  utils = require("../helpers/utils");
8
8
 
9
- module.exports = function info(args) {
9
+ module.exports = function info(args, rawArgs) {
10
10
  let bsConfigPath = utils.getConfigPath(args.cf);
11
11
 
12
12
  return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
@@ -90,12 +90,12 @@ module.exports = function info(args) {
90
90
  logger.info(message);
91
91
  }
92
92
  }
93
- utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
93
+ utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
94
94
  });
95
95
  }).catch(function (err) {
96
96
  logger.error(err);
97
97
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
98
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
98
+ utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
99
99
  process.exitCode = Constants.ERROR_EXIT_CODE;
100
100
  })
101
101
  }
@@ -7,7 +7,7 @@ const fileHelpers = require("../helpers/fileHelpers"),
7
7
  path = require('path');
8
8
 
9
9
 
10
- function get_path(args) {
10
+ function get_path(args, rawArgs) {
11
11
  if (args._.length > 1 && args.p) {
12
12
  let filename = args._[1];
13
13
  if (filename !== path.basename(filename)) {
@@ -15,7 +15,7 @@ function get_path(args) {
15
15
  logger.error(message);
16
16
  // set cypress config filename
17
17
  utils.setCypressConfigFilename(args.bstack_config, args);
18
- utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'conflicting_path_json_init');
18
+ utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'conflicting_path_json_init', null, rawArgs);
19
19
  return;
20
20
  }
21
21
 
@@ -35,9 +35,9 @@ function get_path(args) {
35
35
  }
36
36
 
37
37
 
38
- module.exports = function init(args) {
38
+ module.exports = function init(args, rawArgs) {
39
39
 
40
- let path_to_json = get_path(args);
40
+ let path_to_json = get_path(args, rawArgs);
41
41
  if (path_to_json === undefined) return;
42
42
 
43
43
  // append .json if filename passed is not of json type
@@ -57,7 +57,7 @@ module.exports = function init(args) {
57
57
  if (exists) {
58
58
  let message = Constants.userMessages.CONFIG_FILE_EXISTS;
59
59
  logger.error(message);
60
- utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
60
+ utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists', null, rawArgs);
61
61
  } else {
62
62
  fileHelpers.write(config, null, args, utils.configCreated);
63
63
  }
@@ -65,7 +65,7 @@ module.exports = function init(args) {
65
65
  } else {
66
66
  let message = util.format(Constants.userMessages.DIR_NOT_FOUND, path.dirname(config.path));
67
67
  logger.error(message);
68
- utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'path_to_init_not_found');
68
+ utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'path_to_init_not_found', null, rawArgs);
69
69
  }
70
70
  });
71
71
  }
@@ -1,4 +1,6 @@
1
1
  'use strict';
2
+ const path = require('path');
3
+
2
4
  const archiver = require("../helpers/archiver"),
3
5
  zipUploader = require("../helpers/zipUpload"),
4
6
  build = require("../helpers/build"),
@@ -17,7 +19,7 @@ const archiver = require("../helpers/archiver"),
17
19
  updateNotifier = require('update-notifier'),
18
20
  pkg = require('../../package.json');
19
21
 
20
- module.exports = function run(args) {
22
+ module.exports = function run(args, rawArgs) {
21
23
  let bsConfigPath = utils.getConfigPath(args.cf);
22
24
  //Delete build_results.txt from log folder if already present.
23
25
  initTimeComponents();
@@ -94,11 +96,14 @@ module.exports = function run(args) {
94
96
  //get the number of spec files
95
97
  let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
96
98
 
99
+ // return the number of parallels user specified
100
+ let userSpecifiedParallels = utils.getParallels(bsConfig, args);
101
+
97
102
  // accept the number of parallels
98
103
  utils.setParallels(bsConfig, args, specFiles.length);
99
104
 
100
105
  // warn if specFiles cross our limit
101
- utils.warnSpecLimit(bsConfig, args, specFiles);
106
+ utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
102
107
  markBlockEnd('preArchiveSteps');
103
108
  markBlockStart('checkAlreadyUploaded');
104
109
  return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
@@ -114,6 +119,9 @@ module.exports = function run(args) {
114
119
  return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
115
120
  markBlockEnd('zip.archive');
116
121
 
122
+ let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName));
123
+ let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName));
124
+
117
125
  // Uploaded zip file
118
126
  markBlockStart('zip.zipUpload');
119
127
  return zipUploader.zipUpload(bsConfig, md5data, packageData).then(async function (zip) {
@@ -123,7 +131,7 @@ module.exports = function run(args) {
123
131
  // Create build
124
132
  //setup Local Testing
125
133
  markBlockStart('localSetup');
126
- let bs_local = await utils.setupLocalTesting(bsConfig, args);
134
+ let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
127
135
  markBlockEnd('localSetup');
128
136
  markBlockStart('createBuild');
129
137
  return build.createBuild(bsConfig, zip).then(function (data) {
@@ -132,6 +140,11 @@ module.exports = function run(args) {
132
140
  utils.setProcessHooks(data.build_id, bsConfig, bs_local, args);
133
141
  let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
134
142
  let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
143
+ let buildReportData = {
144
+ 'build_id': data.build_id,
145
+ 'user_id': data.user_id,
146
+ 'parallels': userSpecifiedParallels
147
+ };
135
148
  utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
136
149
  if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
137
150
  logger.warn(Constants.userMessages.NO_PARALLELS);
@@ -154,22 +167,22 @@ module.exports = function run(args) {
154
167
 
155
168
 
156
169
  if (args.sync) {
157
- syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
170
+ syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
158
171
 
159
172
  // stop the Local instance
160
- await utils.stopLocalBinary(bsConfig, bs_local, args);
173
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
161
174
 
162
175
  // waiting for 5 secs for upload to complete (as a safety measure)
163
176
  await new Promise(resolve => setTimeout(resolve, 5000));
164
177
 
165
178
  // download build artifacts
166
179
  if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
167
- await downloadBuildArtifacts(bsConfig, data.build_id, args);
180
+ await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
168
181
  }
169
182
 
170
183
  // Generate custom report!
171
- reportGenerator(bsConfig, data.build_id, args, function(){
172
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
184
+ reportGenerator(bsConfig, data.build_id, args, rawArgs, function(){
185
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
173
186
  utils.handleSyncExit(exitCode, data.dashboard_url);
174
187
  });
175
188
  });
@@ -186,7 +199,29 @@ module.exports = function run(args) {
186
199
  package_error: utils.checkError(packageData),
187
200
  checkmd5_error: utils.checkError(md5data),
188
201
  build_id: data.build_id,
202
+ test_zip_size: test_zip_size,
203
+ npm_zip_size: npm_zip_size,
204
+ test_suite_zip_upload: md5data.zipUrlPresent ? 0 : 1,
205
+ package_zip_upload: md5data.packageUrlPresent ? 0 : 1
206
+ };
207
+
208
+ if (!md5data.zipUrlPresent && zip.tests_upload_time) {
209
+ dataToSend.test_suite_zip_size = parseFloat((test_zip_size / 1024).toFixed(2));
210
+ dataToSend.test_suite_zip_upload_avg_speed = parseFloat(((test_zip_size * 1000) / (1024 * zip.tests_upload_time)).toFixed(2));
189
211
  };
212
+
213
+ if (!md5data.packageUrlPresent && zip.npm_package_upload_time) {
214
+ dataToSend.npm_package_zip_size = parseFloat((npm_zip_size / 1024).toFixed(2));
215
+ dataToSend.npm_package_zip_upload_avg_speed = parseFloat(((npm_zip_size * 1000) / (1024 * zip.npm_package_upload_time)).toFixed(2));
216
+ };
217
+
218
+ if (zip.tests_upload_time || zip.npm_package_upload_time) {
219
+ dataToSend.time_components.zip.zipUploadSplit = {
220
+ tests_upload_time: zip.tests_upload_time,
221
+ npm_package_upload_time: zip.npm_package_upload_time,
222
+ }
223
+ }
224
+
190
225
  if (bsConfig && bsConfig.connection_settings) {
191
226
  if (bsConfig.connection_settings.local_mode) {
192
227
  dataToSend.local_mode = bsConfig.connection_settings.local_mode;
@@ -195,30 +230,31 @@ module.exports = function run(args) {
195
230
  dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal;
196
231
  }
197
232
  }
198
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, dataToSend);
233
+ buildReportData = { ...buildReportData, ...dataToSend };
234
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
199
235
  return;
200
236
  }).catch(async function (err) {
201
237
  // Build creation failed
202
238
  logger.error(err);
203
239
  // stop the Local instance
204
- await utils.stopLocalBinary(bsConfig, bs_local, args);
240
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
205
241
 
206
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
242
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', null, rawArgs);
207
243
  process.exitCode = Constants.ERROR_EXIT_CODE;
208
244
  });
209
245
  }).catch(function (err) {
210
246
  // Zip Upload failed | Local Start failed
211
247
  logger.error(err);
212
248
  if(err === Constants.userMessages.LOCAL_START_FAILED){
213
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
249
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', null, rawArgs);
214
250
  } else {
215
251
  logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
216
252
  fileHelpers.deleteZip();
217
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
253
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed', null, rawArgs);
218
254
  try {
219
255
  fileHelpers.deletePackageArchieve();
220
256
  } catch (err) {
221
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
257
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
222
258
  }
223
259
  }
224
260
  process.exitCode = Constants.ERROR_EXIT_CODE;
@@ -227,16 +263,16 @@ module.exports = function run(args) {
227
263
  // Zipping failed
228
264
  logger.error(err);
229
265
  logger.error(Constants.userMessages.FAILED_TO_ZIP);
230
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
266
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed', null, rawArgs);
231
267
  try {
232
268
  fileHelpers.deleteZip();
233
269
  } catch (err) {
234
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
270
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed', null, rawArgs);
235
271
  }
236
272
  try {
237
273
  fileHelpers.deletePackageArchieve();
238
274
  } catch (err) {
239
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
275
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
240
276
  }
241
277
  process.exitCode = Constants.ERROR_EXIT_CODE;
242
278
  });
@@ -244,11 +280,11 @@ module.exports = function run(args) {
244
280
  // package installer failed
245
281
  logger.error(err);
246
282
  logger.error(Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE);
247
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed');
283
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed', null, rawArgs);
248
284
  try {
249
285
  fileHelpers.deletePackageArchieve();
250
286
  } catch (err) {
251
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed');
287
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
252
288
  }
253
289
  process.exitCode = Constants.ERROR_EXIT_CODE;
254
290
  });
@@ -256,7 +292,7 @@ module.exports = function run(args) {
256
292
  // md5 check failed
257
293
  logger.error(err);
258
294
  logger.error(Constants.userMessages.FAILED_MD5_CHECK);
259
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
295
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed', null, rawArgs);
260
296
  process.exitCode = Constants.ERROR_EXIT_CODE;
261
297
  });
262
298
  }).catch(function (err) {
@@ -270,13 +306,14 @@ module.exports = function run(args) {
270
306
  }
271
307
 
272
308
  let error_code = utils.getErrorCodeFromMsg(err);
273
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
309
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code, null, rawArgs);
274
310
  process.exitCode = Constants.ERROR_EXIT_CODE;
275
311
  });
276
312
  }).catch(function (err) {
277
313
  logger.error(err);
278
314
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
279
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
315
+ let bsJsonData = utils.readBsConfigJSON(bsConfigPath);
316
+ utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
280
317
  process.exitCode = Constants.ERROR_EXIT_CODE;
281
318
  }).finally(function(){
282
319
  updateNotifier({
@@ -6,7 +6,7 @@ const config = require("../helpers/config"),
6
6
  Constants = require("../helpers/constants"),
7
7
  utils = require("../helpers/utils");
8
8
 
9
- module.exports = function stop(args) {
9
+ module.exports = function stop(args, rawArgs) {
10
10
  let bsConfigPath = utils.getConfigPath(args.cf);
11
11
 
12
12
  return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
@@ -25,12 +25,12 @@ module.exports = function stop(args) {
25
25
 
26
26
  let buildId = args._[1];
27
27
 
28
- await utils.stopBrowserStackBuild(bsConfig, args, buildId);
28
+ await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
29
29
 
30
30
  }).catch(function (err) {
31
31
  logger.error(err);
32
32
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
33
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
33
+ utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
34
34
  process.exitCode = Constants.ERROR_EXIT_CODE;
35
35
  })
36
36
  }
@@ -3,14 +3,15 @@
3
3
  const fs = require('fs'),
4
4
  path = require('path');
5
5
 
6
- const axios = require('axios'),
7
- unzipper = require('unzipper');
6
+ const unzipper = require('unzipper');
8
7
 
9
8
  const logger = require('./logger').winstonLogger,
10
9
  utils = require("./utils"),
11
10
  Constants = require("./constants"),
12
11
  config = require("./config");
13
12
 
13
+ const request = require('request');
14
+
14
15
 
15
16
  let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
16
17
  let BUILD_ARTIFACTS_FAIL_COUNT = 0;
@@ -95,32 +96,31 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
95
96
  let tmpFilePath = path.join(filePath, fileName);
96
97
  const writer = fs.createWriteStream(tmpFilePath);
97
98
 
98
- return axios({
99
- method: 'get',
100
- url: url,
101
- responseType: 'stream',
102
- }).then(response => {
103
-
104
- //ensure that the user can call `then()` only when the file has
105
- //been downloaded entirely.
106
-
107
- return new Promise(async (resolve, reject) => {
108
- response.data.pipe(writer);
109
- let error = null;
110
- writer.on('error', err => {
111
- error = err;
112
- writer.close();
113
- reject(err);
114
- });
115
- writer.on('close', async () => {
116
- if (!error) {
117
- await unzipFile(filePath, fileName);
118
- fs.unlinkSync(tmpFilePath);
119
- resolve(true);
120
- }
121
- //no need to call the reject here, as it will have been called in the
122
- //'error' stream;
123
- });
99
+ return new Promise(async (resolve, reject) => {
100
+ request.get(url).on('response', function(response) {
101
+
102
+ if(response.statusCode != 200) {
103
+ reject();
104
+ } else {
105
+ //ensure that the user can call `then()` only when the file has
106
+ //been downloaded entirely.
107
+ response.pipe(writer);
108
+ let error = null;
109
+ writer.on('error', err => {
110
+ error = err;
111
+ writer.close();
112
+ reject(err);
113
+ });
114
+ writer.on('close', async () => {
115
+ if (!error) {
116
+ await unzipFile(filePath, fileName);
117
+ fs.unlinkSync(tmpFilePath);
118
+ resolve(true);
119
+ }
120
+ //no need to call the reject here, as it will have been called in the
121
+ //'error' stream;
122
+ });
123
+ }
124
124
  });
125
125
  });
126
126
  }
@@ -134,8 +134,8 @@ const unzipFile = async (filePath, fileName) => {
134
134
  });
135
135
  }
136
136
 
137
- const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
138
- let url = `${config.buildUrl}${buildId}/build_artifacts/status`;
137
+ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => {
138
+ options.url = `${config.buildUrl}${buildId}/build_artifacts/status`;
139
139
 
140
140
  let cypressJSON = utils.getCypressJSON(bsConfig);
141
141
 
@@ -156,65 +156,95 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
156
156
  }
157
157
  }
158
158
 
159
- try {
160
- await axios.post(url, data, options);
161
- } catch (err) {
162
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update');
163
- }
159
+ options.formData = data.toString();
160
+ let responseData = null;
161
+ return new Promise (async (resolve, reject) => {
162
+ request.post(options, function (err, resp, data) {
163
+ if(err) {
164
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
165
+ reject(err);
166
+ } else {
167
+ try {
168
+ responseData = JSON.parse(data);
169
+ } catch(e) {
170
+ responseData = {};
171
+ }
172
+ if (resp.statusCode != 200) {
173
+ if (responseData && responseData["error"]) {
174
+ utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
175
+ reject(responseData["error"])
176
+ }
177
+ }
178
+ }
179
+ resolve()
180
+ });
181
+ });
164
182
  }
165
183
 
166
- exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
167
- BUILD_ARTIFACTS_FAIL_COUNT = 0;
168
- BUILD_ARTIFACTS_TOTAL_COUNT = 0;
169
-
170
- let url = `${config.buildUrl}${buildId}/build_artifacts`;
171
- let options = {
172
- auth: {
173
- username: bsConfig.auth.username,
174
- password: bsConfig.auth.access_key,
175
- },
176
- headers: {
177
- 'User-Agent': utils.getUserAgent(),
178
- },
179
- };
180
-
181
- let message = null;
182
- let messageType = null;
183
- let errorCode = null;
184
-
185
- try {
186
- const res = await axios.get(url, options);
187
- let buildDetails = res.data;
188
-
189
- await createDirectories(buildId, buildDetails);
190
- await parseAndDownloadArtifacts(buildId, buildDetails);
191
-
192
- if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
193
- messageType = Constants.messageTypes.ERROR;
194
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
195
- logger.error(message);
184
+ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
185
+ return new Promise ( async (resolve, reject) => {
186
+ BUILD_ARTIFACTS_FAIL_COUNT = 0;
187
+ BUILD_ARTIFACTS_TOTAL_COUNT = 0;
188
+
189
+ let options = {
190
+ url: `${config.buildUrl}${buildId}/build_artifacts`,
191
+ auth: {
192
+ username: bsConfig.auth.username,
193
+ password: bsConfig.auth.access_key,
194
+ },
195
+ headers: {
196
+ 'User-Agent': utils.getUserAgent(),
197
+ },
198
+ };
199
+
200
+ let message = null;
201
+ let messageType = null;
202
+ let errorCode = null;
203
+ let buildDetails = null;
204
+ request.get(options, async function (err, resp, body) {
205
+ if(err) {
206
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
196
207
  process.exitCode = Constants.ERROR_EXIT_CODE;
197
208
  } else {
198
- messageType = Constants.messageTypes.SUCCESS;
199
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
200
- logger.info(message);
209
+ try {
210
+ buildDetails = JSON.parse(body);
211
+ if(resp.statusCode != 200) {
212
+ logger.error('Downloading the build artifacts failed.');
213
+ logger.error(`Error: Request failed with status code ${resp.statusCode}`)
214
+ utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
215
+ process.exitCode = Constants.ERROR_EXIT_CODE;
216
+ } else {
217
+ await createDirectories(buildId, buildDetails);
218
+ await parseAndDownloadArtifacts(buildId, buildDetails);
219
+ if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
220
+ messageType = Constants.messageTypes.ERROR;
221
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
222
+ logger.error(message);
223
+ process.exitCode = Constants.ERROR_EXIT_CODE;
224
+ } else {
225
+ messageType = Constants.messageTypes.SUCCESS;
226
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
227
+ logger.info(message);
228
+ }
229
+ await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs)
230
+ utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs);
231
+ }
232
+ } catch (err) {
233
+ messageType = Constants.messageTypes.ERROR;
234
+ errorCode = 'api_failed_build_artifacts';
235
+ if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
236
+ messageType = Constants.messageTypes.ERROR;
237
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
238
+ logger.error(message);
239
+ } else {
240
+ logger.error('Downloading the build artifacts failed.');
241
+ }
242
+ utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs);
243
+ logger.error(`Error: Request failed with status code ${resp.statusCode}`)
244
+ process.exitCode = Constants.ERROR_EXIT_CODE;
245
+ }
201
246
  }
202
-
203
- await sendUpdatesToBstack(bsConfig, buildId, args, options);
204
- utils.sendUsageReport(bsConfig, args, message, messageType, null);
205
- } catch (err) {
206
- messageType = Constants.messageTypes.ERROR;
207
- errorCode = 'api_failed_build_artifacts';
208
-
209
- if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
210
- messageType = Constants.messageTypes.ERROR;
211
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
212
- logger.error(message);
213
- } else {
214
- logger.error('Downloading the build artifacts failed.');
215
- }
216
-
217
- utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);
218
- process.exitCode = Constants.ERROR_EXIT_CODE;
219
- }
247
+ resolve();
248
+ });
249
+ });
220
250
  };
@@ -26,6 +26,7 @@ const userMessages = {
26
26
  MD5_CHECK_FAILED: "There was some issue while checking if zip is already uploaded.",
27
27
  ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
28
28
  ZIP_DELETED: "Deleted tests.zip successfully.",
29
+ NPM_INSTALL_AND_UPLOAD: "Installing required dependencies and building the package to upload to BrowserStack",
29
30
  NPM_DELETE_FAILED: "Could not delete the dependency packages.",
30
31
  NPM_DELETED: "Deleted dependency packages successfully.",
31
32
  API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
@@ -42,6 +43,8 @@ const userMessages = {
42
43
  UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully",
43
44
  UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack",
44
45
  UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
46
+ SKIP_UPLOADING_TESTS: "Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.",
47
+ SKIP_UPLOADING_NPM_PACKAGES: "Skipping the upload of node_modules since BrowserStack has already cached your npm dependencies that have not changed since the last run.",
45
48
  LOCAL_TRUE: "you will now be able to test localhost / private URLs",
46
49
  LOCAL_FALSE: "you won't be able to test localhost / private URLs",
47
50
  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.",
@@ -209,8 +212,14 @@ const usageReportingConstants = {
209
212
 
210
213
  const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
211
214
 
215
+ const AUTH_REGEX = /"auth" *: *{[\s\S]*?}/g
216
+
212
217
  const ERROR_EXIT_CODE = 1;
213
218
 
219
+ const REDACTED = "[REDACTED]";
220
+
221
+ const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED} }`;
222
+
214
223
  module.exports = Object.freeze({
215
224
  syncCLI,
216
225
  userMessages,
@@ -228,5 +237,7 @@ module.exports = Object.freeze({
228
237
  METADATA_CHAR_BUFFER_PER_SPEC,
229
238
  usageReportingConstants,
230
239
  LATEST_VERSION_SYNTAX_REGEX,
231
- ERROR_EXIT_CODE
240
+ ERROR_EXIT_CODE,
241
+ AUTH_REGEX,
242
+ REDACTED_AUTH
232
243
  });