browserstack-cypress-cli 1.8.1 → 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.
Files changed (43) hide show
  1. package/bin/commands/generateDownloads.js +39 -0
  2. package/bin/commands/generateReport.js +5 -4
  3. package/bin/commands/info.js +4 -3
  4. package/bin/commands/init.js +6 -6
  5. package/bin/commands/runs.js +227 -64
  6. package/bin/commands/stop.js +5 -65
  7. package/bin/helpers/archiver.js +5 -20
  8. package/bin/helpers/buildArtifacts.js +250 -0
  9. package/bin/helpers/capabilityHelper.js +15 -22
  10. package/bin/helpers/checkUploaded.js +153 -0
  11. package/bin/helpers/config.js +3 -0
  12. package/bin/helpers/constants.js +109 -13
  13. package/bin/helpers/fileHelpers.js +14 -0
  14. package/bin/helpers/hashUtil.js +70 -0
  15. package/bin/helpers/packageInstaller.js +134 -0
  16. package/bin/helpers/reporterHTML.js +169 -11
  17. package/bin/helpers/sync/syncSpecsLogs.js +37 -9
  18. package/bin/helpers/timeComponents.js +71 -0
  19. package/bin/helpers/usageReporting.js +35 -6
  20. package/bin/helpers/utils.js +420 -12
  21. package/bin/helpers/zipUpload.js +106 -27
  22. package/bin/runner.js +119 -118
  23. package/package.json +4 -1
  24. package/test/test_files/dummy_bstack.json +0 -0
  25. package/test/test_files/dummy_bstack_2.json +0 -1
  26. package/test/test_files/dummy_bstack_3.json +0 -3
  27. package/test/unit/bin/commands/generateReport.js +0 -112
  28. package/test/unit/bin/commands/info.js +0 -374
  29. package/test/unit/bin/commands/init.js +0 -187
  30. package/test/unit/bin/commands/runs.js +0 -700
  31. package/test/unit/bin/commands/stop.js +0 -388
  32. package/test/unit/bin/helpers/archiver.js +0 -57
  33. package/test/unit/bin/helpers/build.js +0 -210
  34. package/test/unit/bin/helpers/capabilityHelper.js +0 -1049
  35. package/test/unit/bin/helpers/fileHelpers.js +0 -102
  36. package/test/unit/bin/helpers/reporterHTML.js +0 -272
  37. package/test/unit/bin/helpers/sync/failedSpecDetails.js +0 -76
  38. package/test/unit/bin/helpers/sync/specSummary.js +0 -55
  39. package/test/unit/bin/helpers/sync/syncSpecsLogs.js +0 -403
  40. package/test/unit/bin/helpers/usageReporting.js +0 -411
  41. package/test/unit/bin/helpers/utils.js +0 -1770
  42. package/test/unit/bin/helpers/zipUpload.js +0 -205
  43. package/test/unit/support/fixtures/testObjects.js +0 -149
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ const logger = require("../helpers/logger").winstonLogger,
4
+ Constants = require("../helpers/constants"),
5
+ utils = require("../helpers/utils"),
6
+ downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts;
7
+
8
+
9
+ module.exports = async function generateDownloads(args, rawArgs) {
10
+ let bsConfigPath = utils.getConfigPath(args.cf);
11
+
12
+ return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
13
+ // setting setDefaults to {} if not present and set via env variables or via args.
14
+ utils.setDefaults(bsConfig, args);
15
+
16
+ // accept the username from command line if provided
17
+ utils.setUsername(bsConfig, args);
18
+
19
+ // accept the access key from command line if provided
20
+ utils.setAccessKey(bsConfig, args);
21
+
22
+ utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
23
+
24
+ // set cypress config filename
25
+ utils.setCypressConfigFilename(bsConfig, args);
26
+
27
+ let messageType = Constants.messageTypes.INFO;
28
+ let errorCode = null;
29
+ let buildId = args._[1];
30
+
31
+ await downloadBuildArtifacts(bsConfig, buildId, args, rawArgs);
32
+ utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode, null, rawArgs);
33
+ }).catch(function (err) {
34
+ logger.error(err);
35
+ utils.setUsageReportingFlag(null, args.disableUsageReporting);
36
+ utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
37
+ process.exitCode = Constants.ERROR_EXIT_CODE;
38
+ });
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,11 +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
+ process.exitCode = Constants.ERROR_EXIT_CODE;
38
39
  });
39
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,11 +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
+ process.exitCode = Constants.ERROR_EXIT_CODE;
99
100
  })
100
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"),
@@ -9,14 +11,27 @@ const archiver = require("../helpers/archiver"),
9
11
  utils = require("../helpers/utils"),
10
12
  fileHelpers = require("../helpers/fileHelpers"),
11
13
  syncRunner = require("../helpers/syncRunner"),
12
- reportGenerator = require('../helpers/reporterHTML').reportGenerator;
14
+ checkUploaded = require("../helpers/checkUploaded"),
15
+ packageInstaller = require("../helpers/packageInstaller"),
16
+ reportGenerator = require('../helpers/reporterHTML').reportGenerator,
17
+ {initTimeComponents, instrumentEventTime, markBlockStart, markBlockEnd, getTimeComponents} = require('../helpers/timeComponents'),
18
+ downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts,
19
+ updateNotifier = require('update-notifier'),
20
+ pkg = require('../../package.json');
13
21
 
14
- module.exports = function run(args) {
22
+ module.exports = function run(args, rawArgs) {
15
23
  let bsConfigPath = utils.getConfigPath(args.cf);
16
24
  //Delete build_results.txt from log folder if already present.
25
+ initTimeComponents();
26
+ instrumentEventTime("cliStart")
27
+ markBlockStart('deleteOldResults');
17
28
  utils.deleteResults();
29
+ markBlockEnd('deleteOldResults');
18
30
 
19
- return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
31
+ markBlockStart('validateBstackJson');
32
+ return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
33
+ markBlockEnd('validateBstackJson');
34
+ markBlockStart('setConfig');
20
35
  utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
21
36
 
22
37
  utils.setDefaults(bsConfig, args);
@@ -39,6 +54,9 @@ module.exports = function run(args) {
39
54
  // accept the env list from command line and set it
40
55
  utils.setTestEnvs(bsConfig, args);
41
56
 
57
+ // accept the system env list from bsconf and set it
58
+ utils.setSystemEnvs(bsConfig);
59
+
42
60
  //accept the local from env variable if provided
43
61
  utils.setLocal(bsConfig, args);
44
62
 
@@ -54,91 +72,228 @@ module.exports = function run(args) {
54
72
  // run test in headed mode
55
73
  utils.setHeaded(bsConfig, args);
56
74
 
75
+ // set the no-wrap
76
+ utils.setNoWrap(bsConfig, args);
77
+
78
+ //set browsers
79
+ await utils.setBrowsers(bsConfig, args);
80
+
81
+ //set config (--config)
82
+ utils.setConfig(bsConfig, args);
83
+
84
+ // set sync/async mode (--async/--sync)
85
+ utils.setCLIMode(bsConfig, args);
86
+
87
+ // set other cypress configs e.g. reporter and reporter-options
88
+ utils.setOtherConfigs(bsConfig, args);
89
+ markBlockEnd('setConfig');
90
+
57
91
  // Validate browserstack.json values and parallels specified via arguments
92
+ markBlockStart('validateConfig');
58
93
  return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
59
-
94
+ markBlockEnd('validateConfig');
95
+ markBlockStart('preArchiveSteps');
60
96
  //get the number of spec files
61
97
  let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
62
98
 
99
+ // return the number of parallels user specified
100
+ let userSpecifiedParallels = utils.getParallels(bsConfig, args);
101
+
63
102
  // accept the number of parallels
64
103
  utils.setParallels(bsConfig, args, specFiles.length);
65
104
 
66
- // Archive the spec files
67
- return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {
105
+ // warn if specFiles cross our limit
106
+ utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
107
+ markBlockEnd('preArchiveSteps');
108
+ markBlockStart('checkAlreadyUploaded');
109
+ return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
110
+ markBlockEnd('checkAlreadyUploaded');
68
111
 
69
- // Uploaded zip file
70
- return zipUploader.zipUpload(bsConfig, config.fileName).then(async function (zip) {
71
- // Create build
112
+ markBlockStart('packageInstaller');
113
+ return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
114
+ markBlockEnd('packageInstaller');
72
115
 
73
- //setup Local Testing
74
- let bs_local = await utils.setupLocalTesting(bsConfig, args);
116
+ // Archive the spec files
117
+ markBlockStart('zip');
118
+ markBlockStart('zip.archive');
119
+ return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
120
+ markBlockEnd('zip.archive');
75
121
 
76
- return build.createBuild(bsConfig, zip).then(function (data) {
77
- let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
78
- let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
79
- utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
80
- 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)) {
81
- logger.warn(Constants.userMessages.NO_PARALLELS);
82
- }
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));
83
124
 
84
- if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
85
- let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version)
86
- logger.warn(versionMessage);
87
- }
125
+ // Uploaded zip file
126
+ markBlockStart('zip.zipUpload');
127
+ return zipUploader.zipUpload(bsConfig, md5data, packageData).then(async function (zip) {
128
+ markBlockEnd('zip.zipUpload');
129
+ markBlockEnd('zip');
88
130
 
89
- if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
90
- logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
91
- logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
92
- }
131
+ // Create build
132
+ //setup Local Testing
133
+ markBlockStart('localSetup');
134
+ let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
135
+ markBlockEnd('localSetup');
136
+ markBlockStart('createBuild');
137
+ return build.createBuild(bsConfig, zip).then(function (data) {
138
+ markBlockEnd('createBuild');
139
+ markBlockEnd('total');
140
+ utils.setProcessHooks(data.build_id, bsConfig, bs_local, args);
141
+ let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
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
+ };
148
+ utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
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)) {
150
+ logger.warn(Constants.userMessages.NO_PARALLELS);
151
+ }
152
+
153
+ if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
154
+ if (bsConfig.run_settings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
155
+ let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version, data.framework_upgrade_message);
156
+ logger.info(versionMessage);
157
+ } else {
158
+ let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version, data.framework_upgrade_message);
159
+ logger.warn(versionMessage);
160
+ }
161
+ }
162
+
163
+ if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
164
+ logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
165
+ logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
166
+ }
93
167
 
94
- if (args.sync) {
95
- syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
96
168
 
169
+ if (args.sync) {
170
+ syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
171
+
172
+ // stop the Local instance
173
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
174
+
175
+ // waiting for 5 secs for upload to complete (as a safety measure)
176
+ await new Promise(resolve => setTimeout(resolve, 5000));
177
+
178
+ // download build artifacts
179
+ if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
180
+ await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
181
+ }
182
+
183
+ // Generate custom report!
184
+ reportGenerator(bsConfig, data.build_id, args, rawArgs, function(){
185
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
186
+ utils.handleSyncExit(exitCode, data.dashboard_url);
187
+ });
188
+ });
189
+ } else if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
190
+ logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
191
+ }
192
+
193
+ logger.info(message);
194
+ logger.info(dashboardLink);
195
+ if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
196
+ let dataToSend = {
197
+ time_components: getTimeComponents(),
198
+ unique_id: utils.generateUniqueHash(),
199
+ package_error: utils.checkError(packageData),
200
+ checkmd5_error: utils.checkError(md5data),
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));
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
+
225
+ if (bsConfig && bsConfig.connection_settings) {
226
+ if (bsConfig.connection_settings.local_mode) {
227
+ dataToSend.local_mode = bsConfig.connection_settings.local_mode;
228
+ }
229
+ if (bsConfig.connection_settings.usedAutoLocal) {
230
+ dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal;
231
+ }
232
+ }
233
+ buildReportData = { ...buildReportData, ...dataToSend };
234
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
235
+ return;
236
+ }).catch(async function (err) {
237
+ // Build creation failed
238
+ logger.error(err);
97
239
  // stop the Local instance
98
- await utils.stopLocalBinary(bsConfig, bs_local, args);
240
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
99
241
 
100
- // Generate custom report!
101
- reportGenerator(bsConfig, data.build_id, args, function(){
102
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
103
- utils.handleSyncExit(exitCode, data.dashboard_url);
104
- });
242
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', null, rawArgs);
243
+ process.exitCode = Constants.ERROR_EXIT_CODE;
105
244
  });
106
- }
107
-
108
- logger.info(message);
109
- logger.info(dashboardLink);
110
- if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
111
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
112
- return;
113
- }).catch(async function (err) {
114
- // Build creation failed
245
+ }).catch(function (err) {
246
+ // Zip Upload failed | Local Start failed
247
+ logger.error(err);
248
+ if(err === Constants.userMessages.LOCAL_START_FAILED){
249
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', null, rawArgs);
250
+ } else {
251
+ logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
252
+ fileHelpers.deleteZip();
253
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed', null, rawArgs);
254
+ try {
255
+ fileHelpers.deletePackageArchieve();
256
+ } catch (err) {
257
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
258
+ }
259
+ }
260
+ process.exitCode = Constants.ERROR_EXIT_CODE;
261
+ });
262
+ }).catch(function (err) {
263
+ // Zipping failed
115
264
  logger.error(err);
116
- // stop the Local instance
117
- await utils.stopLocalBinary(bsConfig, bs_local, args);
118
-
119
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
265
+ logger.error(Constants.userMessages.FAILED_TO_ZIP);
266
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed', null, rawArgs);
267
+ try {
268
+ fileHelpers.deleteZip();
269
+ } catch (err) {
270
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed', null, rawArgs);
271
+ }
272
+ try {
273
+ fileHelpers.deletePackageArchieve();
274
+ } catch (err) {
275
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
276
+ }
277
+ process.exitCode = Constants.ERROR_EXIT_CODE;
120
278
  });
121
279
  }).catch(function (err) {
122
- // Zip Upload failed | Local Start failed
280
+ // package installer failed
123
281
  logger.error(err);
124
- if(err === Constants.userMessages.LOCAL_START_FAILED){
125
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
126
- } else {
127
- logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
128
- fileHelpers.deleteZip();
129
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
282
+ logger.error(Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE);
283
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed', null, rawArgs);
284
+ try {
285
+ fileHelpers.deletePackageArchieve();
286
+ } catch (err) {
287
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
130
288
  }
289
+ process.exitCode = Constants.ERROR_EXIT_CODE;
131
290
  });
132
291
  }).catch(function (err) {
133
- // Zipping failed
292
+ // md5 check failed
134
293
  logger.error(err);
135
- logger.error(Constants.userMessages.FAILED_TO_ZIP);
136
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
137
- try {
138
- fileHelpers.deleteZip();
139
- } catch (err) {
140
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
141
- }
294
+ logger.error(Constants.userMessages.FAILED_MD5_CHECK);
295
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed', null, rawArgs);
296
+ process.exitCode = Constants.ERROR_EXIT_CODE;
142
297
  });
143
298
  }).catch(function (err) {
144
299
  // browerstack.json is not valid
@@ -151,11 +306,19 @@ module.exports = function run(args) {
151
306
  }
152
307
 
153
308
  let error_code = utils.getErrorCodeFromMsg(err);
154
- 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);
310
+ process.exitCode = Constants.ERROR_EXIT_CODE;
155
311
  });
156
312
  }).catch(function (err) {
157
313
  logger.error(err);
158
314
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
159
- 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);
317
+ process.exitCode = Constants.ERROR_EXIT_CODE;
318
+ }).finally(function(){
319
+ updateNotifier({
320
+ pkg,
321
+ updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
322
+ }).notify({isGlobal: true});
160
323
  });
161
324
  }
@@ -6,10 +6,10 @@ 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
- return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
12
+ return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
13
13
  utils.setDefaults(bsConfig, args);
14
14
 
15
15
  // accept the username from command line if provided
@@ -25,72 +25,12 @@ module.exports = function stop(args) {
25
25
 
26
26
  let buildId = args._[1];
27
27
 
28
- let options = {
29
- url: config.buildStopUrl + buildId,
30
- auth: {
31
- user: bsConfig.auth.username,
32
- password: bsConfig.auth.access_key,
33
- },
34
- headers: {
35
- 'User-Agent': utils.getUserAgent(),
36
- },
37
- };
28
+ await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
38
29
 
39
- request.post(options, function (err, resp, body) {
40
- let message = null;
41
- let messageType = null;
42
- let errorCode = null;
43
-
44
- if (err) {
45
- message = Constants.userMessages.BUILD_STOP_FAILED;
46
- messageType = Constants.messageTypes.ERROR;
47
- errorCode = 'api_failed_build_stop';
48
-
49
- logger.info(message);
50
- } else {
51
- let build = null;
52
- try {
53
- build = JSON.parse(body);
54
- } catch (error) {
55
- build = null;
56
- }
57
-
58
- if (resp.statusCode == 299) {
59
- messageType = Constants.messageTypes.INFO;
60
- errorCode = 'api_deprecated';
61
-
62
- if (build) {
63
- message = build.message;
64
- logger.info(message);
65
- } else {
66
- message = Constants.userMessages.API_DEPRECATED;
67
- logger.info(message);
68
- }
69
- } else if (resp.statusCode != 200) {
70
- messageType = Constants.messageTypes.ERROR;
71
- errorCode = 'api_failed_build_stop';
72
-
73
- if (build) {
74
- message = `${
75
- Constants.userMessages.BUILD_STOP_FAILED
76
- } with error: \n${JSON.stringify(build, null, 2)}`;
77
- logger.error(message);
78
- if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
79
- } else {
80
- message = Constants.userMessages.BUILD_STOP_FAILED;
81
- logger.error(message);
82
- }
83
- } else {
84
- messageType = Constants.messageTypes.SUCCESS;
85
- message = `${JSON.stringify(build, null, 2)}`;
86
- logger.info(message);
87
- }
88
- }
89
- utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
90
- });
91
30
  }).catch(function (err) {
92
31
  logger.error(err);
93
32
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
94
- 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
+ process.exitCode = Constants.ERROR_EXIT_CODE;
95
35
  })
96
36
  }
@@ -7,8 +7,11 @@ const archiver = require("archiver"),
7
7
  utils = require('../helpers/utils'),
8
8
  path = require('path');
9
9
 
10
- const archiveSpecs = (runSettings, filePath, excludeFiles) => {
10
+ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
11
11
  return new Promise(function (resolve, reject) {
12
+ if (md5data.zipUrlPresent) {
13
+ return resolve('Zipping not required');
14
+ }
12
15
  var output = fs.createWriteStream(filePath);
13
16
 
14
17
  var cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
@@ -41,8 +44,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
41
44
 
42
45
  archive.pipe(output);
43
46
 
44
- let ignoreFiles = getFilesToIgnore(runSettings, excludeFiles);
45
-
47
+ let ignoreFiles = utils.getFilesToIgnore(runSettings, excludeFiles);
46
48
  archive.glob(`**/*.+(${Constants.allowedFileTypes.join("|")})`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles, dot:true });
47
49
 
48
50
  let packageJSON = {};
@@ -78,21 +80,4 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
78
80
  });
79
81
  }
80
82
 
81
- const getFilesToIgnore = (runSettings, excludeFiles) => {
82
- let ignoreFiles = Constants.filesToIgnoreWhileUploading;
83
-
84
- // exclude files asked by the user
85
- // args will take precedence over config file
86
- if (!utils.isUndefined(excludeFiles)) {
87
- let excludePatterns = utils.fixCommaSeparatedString(excludeFiles).split(',');
88
- ignoreFiles = ignoreFiles.concat(excludePatterns);
89
- logger.info(`Excluding files matching: ${JSON.stringify(excludePatterns)}`);
90
- } else if (!utils.isUndefined(runSettings.exclude) && runSettings.exclude.length) {
91
- ignoreFiles = ignoreFiles.concat(runSettings.exclude);
92
- logger.info(`Excluding files matching: ${JSON.stringify(runSettings.exclude)}`);
93
- }
94
-
95
- return ignoreFiles;
96
- }
97
-
98
83
  exports.archive = archiveSpecs