browserstack-cypress-cli 1.9.0 → 1.11.2

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.
@@ -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"),
@@ -10,19 +12,24 @@ const archiver = require("../helpers/archiver"),
10
12
  fileHelpers = require("../helpers/fileHelpers"),
11
13
  syncRunner = require("../helpers/syncRunner"),
12
14
  checkUploaded = require("../helpers/checkUploaded"),
15
+ packageInstaller = require("../helpers/packageInstaller"),
13
16
  reportGenerator = require('../helpers/reporterHTML').reportGenerator,
14
- {initTimeComponents, markBlockStart, markBlockEnd, getTimeComponents} = require('../helpers/timeComponents');
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');
15
21
 
16
- module.exports = function run(args) {
22
+ module.exports = function run(args, rawArgs) {
17
23
  let bsConfigPath = utils.getConfigPath(args.cf);
18
24
  //Delete build_results.txt from log folder if already present.
19
25
  initTimeComponents();
26
+ instrumentEventTime("cliStart")
20
27
  markBlockStart('deleteOldResults');
21
28
  utils.deleteResults();
22
29
  markBlockEnd('deleteOldResults');
23
30
 
24
31
  markBlockStart('validateBstackJson');
25
- return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
32
+ return utils.validateBstackJson(bsConfigPath).then(async function (bsConfig) {
26
33
  markBlockEnd('validateBstackJson');
27
34
  markBlockStart('setConfig');
28
35
  utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
@@ -67,6 +74,18 @@ module.exports = function run(args) {
67
74
 
68
75
  // set the no-wrap
69
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);
70
89
  markBlockEnd('setConfig');
71
90
 
72
91
  // Validate browserstack.json values and parallels specified via arguments
@@ -77,125 +96,206 @@ module.exports = function run(args) {
77
96
  //get the number of spec files
78
97
  let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
79
98
 
99
+ bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressJson);
100
+
101
+ // return the number of parallels user specified
102
+ let userSpecifiedParallels = utils.getParallels(bsConfig, args);
103
+
80
104
  // accept the number of parallels
81
105
  utils.setParallels(bsConfig, args, specFiles.length);
82
106
 
83
107
  // warn if specFiles cross our limit
84
- utils.warnSpecLimit(bsConfig, args, specFiles);
108
+ utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
85
109
  markBlockEnd('preArchiveSteps');
86
110
  markBlockStart('checkAlreadyUploaded');
87
- return checkUploaded.checkUploadedMd5(bsConfig, args).then(function (md5data) {
111
+ return checkUploaded.checkUploadedMd5(bsConfig, args, {markBlockStart, markBlockEnd}).then(function (md5data) {
88
112
  markBlockEnd('checkAlreadyUploaded');
89
113
 
90
- // Archive the spec files
91
- markBlockStart('zip');
92
- markBlockStart('zip.archive');
93
- return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
94
- markBlockEnd('zip.archive');
95
-
96
- // Uploaded zip file
97
- markBlockStart('zip.zipUpload');
98
- return zipUploader.zipUpload(bsConfig, config.fileName, md5data).then(async function (zip) {
99
- markBlockEnd('zip.zipUpload');
100
- markBlockEnd('zip');
101
- // Create build
102
-
103
- //setup Local Testing
104
- markBlockStart('localSetup');
105
- let bs_local = await utils.setupLocalTesting(bsConfig, args);
106
- markBlockEnd('localSetup');
107
- markBlockStart('createBuild');
108
- return build.createBuild(bsConfig, zip).then(function (data) {
109
- markBlockEnd('createBuild');
110
- markBlockEnd('total');
111
- let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
112
- let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
113
- utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
114
- 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)) {
115
- logger.warn(Constants.userMessages.NO_PARALLELS);
116
- }
114
+ markBlockStart('packageInstaller');
115
+ return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
116
+ markBlockEnd('packageInstaller');
117
117
 
118
- if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
119
- if (bsConfig.run_settings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
120
- let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
121
- logger.info(versionMessage);
122
- } else {
123
- let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
124
- logger.warn(versionMessage);
118
+ // Archive the spec files
119
+ markBlockStart('zip');
120
+ markBlockStart('zip.archive');
121
+ return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
122
+ markBlockEnd('zip.archive');
123
+
124
+ let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName));
125
+ let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName));
126
+
127
+ // Uploaded zip file
128
+ markBlockStart('zip.zipUpload');
129
+ return zipUploader.zipUpload(bsConfig, md5data, packageData).then(async function (zip) {
130
+ markBlockEnd('zip.zipUpload');
131
+ markBlockEnd('zip');
132
+
133
+ // Create build
134
+ //setup Local Testing
135
+ markBlockStart('localSetup');
136
+ let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
137
+ markBlockEnd('localSetup');
138
+ markBlockStart('createBuild');
139
+ return build.createBuild(bsConfig, zip).then(function (data) {
140
+ markBlockEnd('createBuild');
141
+ markBlockEnd('total');
142
+ utils.setProcessHooks(data.build_id, bsConfig, bs_local, args);
143
+ let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
144
+ let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
145
+ let buildReportData = {
146
+ 'build_id': data.build_id,
147
+ 'user_id': data.user_id,
148
+ 'parallels': userSpecifiedParallels
149
+ };
150
+ utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
151
+ 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)) {
152
+ logger.warn(Constants.userMessages.NO_PARALLELS);
125
153
  }
126
- }
127
154
 
128
- if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
129
- logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
130
- logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
131
- }
155
+ if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
156
+ if (bsConfig.run_settings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
157
+ let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version, data.framework_upgrade_message);
158
+ logger.info(versionMessage);
159
+ } else {
160
+ let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version, data.framework_upgrade_message);
161
+ logger.warn(versionMessage);
162
+ }
163
+ }
164
+
165
+ if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
166
+ logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
167
+ logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
168
+ }
132
169
 
133
- if (args.sync) {
134
- syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
135
170
 
136
- // stop the Local instance
137
- await utils.stopLocalBinary(bsConfig, bs_local, args);
171
+ if (args.sync) {
172
+ syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
138
173
 
139
- // Generate custom report!
140
- reportGenerator(bsConfig, data.build_id, args, function(){
141
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
142
- utils.handleSyncExit(exitCode, data.dashboard_url);
174
+ // stop the Local instance
175
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
176
+
177
+ // waiting for 5 secs for upload to complete (as a safety measure)
178
+ await new Promise(resolve => setTimeout(resolve, 5000));
179
+
180
+ // download build artifacts
181
+ if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
182
+ await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
183
+ }
184
+
185
+ // Generate custom report!
186
+ reportGenerator(bsConfig, data.build_id, args, rawArgs, function(){
187
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
188
+ utils.handleSyncExit(exitCode, data.dashboard_url);
189
+ });
143
190
  });
144
- });
145
- }
191
+ } else if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
192
+ logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
193
+ }
194
+
195
+ logger.info(message);
196
+ logger.info(dashboardLink);
197
+ if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
198
+ let dataToSend = {
199
+ time_components: getTimeComponents(),
200
+ unique_id: utils.generateUniqueHash(),
201
+ package_error: utils.checkError(packageData),
202
+ checkmd5_error: utils.checkError(md5data),
203
+ build_id: data.build_id,
204
+ test_zip_size: test_zip_size,
205
+ npm_zip_size: npm_zip_size,
206
+ test_suite_zip_upload: md5data.zipUrlPresent ? 0 : 1,
207
+ package_zip_upload: md5data.packageUrlPresent ? 0 : 1
208
+ };
209
+
210
+ if (!md5data.zipUrlPresent && zip.tests_upload_time) {
211
+ dataToSend.test_suite_zip_size = parseFloat((test_zip_size / 1024).toFixed(2));
212
+ dataToSend.test_suite_zip_upload_avg_speed = parseFloat(((test_zip_size * 1000) / (1024 * zip.tests_upload_time)).toFixed(2));
213
+ };
214
+
215
+ if (!md5data.packageUrlPresent && zip.npm_package_upload_time) {
216
+ dataToSend.npm_package_zip_size = parseFloat((npm_zip_size / 1024).toFixed(2));
217
+ dataToSend.npm_package_zip_upload_avg_speed = parseFloat(((npm_zip_size * 1000) / (1024 * zip.npm_package_upload_time)).toFixed(2));
218
+ };
146
219
 
147
- logger.info(message);
148
- logger.info(dashboardLink);
149
- if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
150
- let dataToSend = {
151
- time_components: getTimeComponents(),
152
- build_id: data.build_id,
153
- };
154
- if (bsConfig && bsConfig.connection_settings) {
155
- if (bsConfig.connection_settings.local_mode) {
156
- dataToSend.local_mode = bsConfig.connection_settings.local_mode;
220
+ if (zip.tests_upload_time || zip.npm_package_upload_time) {
221
+ dataToSend.time_components.zip.zipUploadSplit = {
222
+ tests_upload_time: zip.tests_upload_time,
223
+ npm_package_upload_time: zip.npm_package_upload_time,
224
+ }
157
225
  }
158
- if (bsConfig.connection_settings.usedAutoLocal) {
159
- dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal;
226
+
227
+ if (bsConfig && bsConfig.connection_settings) {
228
+ if (bsConfig.connection_settings.local_mode) {
229
+ dataToSend.local_mode = bsConfig.connection_settings.local_mode;
230
+ }
231
+ if (bsConfig.connection_settings.usedAutoLocal) {
232
+ dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal;
233
+ }
160
234
  }
161
- }
162
- utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, dataToSend);
163
- return;
164
- }).catch(async function (err) {
165
- // Build creation failed
166
- logger.error(err);
167
- // stop the Local instance
168
- await utils.stopLocalBinary(bsConfig, bs_local, args);
235
+ buildReportData = { ...buildReportData, ...dataToSend };
236
+ utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
237
+ return;
238
+ }).catch(async function (err) {
239
+ // Build creation failed
240
+ logger.error(err);
241
+ // stop the Local instance
242
+ await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
169
243
 
170
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
244
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', null, rawArgs);
245
+ process.exitCode = Constants.ERROR_EXIT_CODE;
246
+ });
247
+ }).catch(function (err) {
248
+ // Zip Upload failed | Local Start failed
249
+ logger.error(err);
250
+ if(err === Constants.userMessages.LOCAL_START_FAILED){
251
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', null, rawArgs);
252
+ } else {
253
+ logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
254
+ fileHelpers.deleteZip();
255
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed', null, rawArgs);
256
+ try {
257
+ fileHelpers.deletePackageArchieve();
258
+ } catch (err) {
259
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
260
+ }
261
+ }
262
+ process.exitCode = Constants.ERROR_EXIT_CODE;
171
263
  });
172
264
  }).catch(function (err) {
173
- // Zip Upload failed | Local Start failed
265
+ // Zipping failed
174
266
  logger.error(err);
175
- if(err === Constants.userMessages.LOCAL_START_FAILED){
176
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
177
- } else {
178
- logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
267
+ logger.error(Constants.userMessages.FAILED_TO_ZIP);
268
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed', null, rawArgs);
269
+ try {
179
270
  fileHelpers.deleteZip();
180
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
271
+ } catch (err) {
272
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed', null, rawArgs);
273
+ }
274
+ try {
275
+ fileHelpers.deletePackageArchieve();
276
+ } catch (err) {
277
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
181
278
  }
279
+ process.exitCode = Constants.ERROR_EXIT_CODE;
182
280
  });
183
281
  }).catch(function (err) {
184
- // Zipping failed
282
+ // package installer failed
185
283
  logger.error(err);
186
- logger.error(Constants.userMessages.FAILED_TO_ZIP);
187
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
284
+ logger.error(Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE);
285
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed', null, rawArgs);
188
286
  try {
189
- fileHelpers.deleteZip();
287
+ fileHelpers.deletePackageArchieve();
190
288
  } catch (err) {
191
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
289
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', null, rawArgs);
192
290
  }
291
+ process.exitCode = Constants.ERROR_EXIT_CODE;
193
292
  });
194
293
  }).catch(function (err) {
195
294
  // md5 check failed
196
295
  logger.error(err);
197
296
  logger.error(Constants.userMessages.FAILED_MD5_CHECK);
198
- utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
297
+ utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed', null, rawArgs);
298
+ process.exitCode = Constants.ERROR_EXIT_CODE;
199
299
  });
200
300
  }).catch(function (err) {
201
301
  // browerstack.json is not valid
@@ -208,11 +308,19 @@ module.exports = function run(args) {
208
308
  }
209
309
 
210
310
  let error_code = utils.getErrorCodeFromMsg(err);
211
- utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
311
+ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code, null, rawArgs);
312
+ process.exitCode = Constants.ERROR_EXIT_CODE;
212
313
  });
213
314
  }).catch(function (err) {
214
315
  logger.error(err);
215
316
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
216
- utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
317
+ let bsJsonData = utils.readBsConfigJSON(bsConfigPath);
318
+ utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
319
+ process.exitCode = Constants.ERROR_EXIT_CODE;
320
+ }).finally(function(){
321
+ updateNotifier({
322
+ pkg,
323
+ updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
324
+ }).notify({isGlobal: true});
217
325
  });
218
326
  }
@@ -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
  }