browserstack-cypress-cli 1.31.0 → 1.31.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.
@@ -18,7 +18,6 @@ const archiver = require("../helpers/archiver"),
18
18
  {initTimeComponents, instrumentEventTime, markBlockStart, markBlockEnd, getTimeComponents} = require('../helpers/timeComponents'),
19
19
  downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts,
20
20
  downloadBuildStacktrace = require('../helpers/downloadBuildStacktrace').downloadBuildStacktrace,
21
- updateNotifier = require('update-notifier'),
22
21
  pkg = require('../../package.json'),
23
22
  packageDiff = require('../helpers/package-diff');
24
23
  const { getStackTraceUrl } = require('../helpers/sync/syncSpecsLogs');
@@ -531,23 +530,27 @@ module.exports = function run(args, rawArgs) {
531
530
  utils.sendUsageReport(bsJsonData, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err), null, rawArgs);
532
531
  process.exitCode = Constants.ERROR_EXIT_CODE;
533
532
  }).finally(function(){
534
- const notifier = updateNotifier({
535
- pkg,
536
- updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
537
- });
533
+ import('update-notifier').then(({ default: updateNotifier } ) => {
534
+ const notifier = updateNotifier({
535
+ pkg,
536
+ updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
537
+ });
538
538
 
539
- // Checks for update on first run.
540
- // Set lastUpdateCheck to 0 to spawn the check update process as notifier sets this to Date.now() for preventing
541
- // the check untill one interval period. It runs once.
542
- if (!notifier.disabled && Date.now() - notifier.config.get('lastUpdateCheck') < 50) {
543
- notifier.config.set('lastUpdateCheck', 0);
544
- notifier.check();
545
- }
539
+ // Checks for update on first run.
540
+ // Set lastUpdateCheck to 0 to spawn the check update process as notifier sets this to Date.now() for preventing
541
+ // the check untill one interval period. It runs once.
542
+ if (!notifier.disabled && Date.now() - notifier.config.get('lastUpdateCheck') < 50) {
543
+ notifier.config.set('lastUpdateCheck', 0);
544
+ notifier.check();
545
+ }
546
546
 
547
- // Set the config update as notifier clears this after reading.
548
- if (notifier.update && notifier.update.current !== notifier.update.latest) {
549
- notifier.config.set('update', notifier.update);
550
- notifier.notify({isGlobal: true});
551
- }
547
+ // Set the config update as notifier clears this after reading.
548
+ if (notifier.update && notifier.update.current !== notifier.update.latest) {
549
+ notifier.config.set('update', notifier.update);
550
+ notifier.notify({isGlobal: true});
551
+ }
552
+ }).catch((error) => {
553
+ logger.debug('Got error loading update-notifier: ', error);
554
+ });
552
555
  });
553
556
  }
@@ -441,6 +441,14 @@ const CYPRESS_CONFIG_FILE_NAMES = Object.keys(CYPRESS_CONFIG_FILE_MAPPING);
441
441
 
442
442
  const CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs']
443
443
 
444
+ // Maximum size of VCS info which is allowed
445
+ const MAX_GIT_META_DATA_SIZE_IN_BYTES = 64 * 1024;
446
+
447
+ /* The value to be appended at the end if git metadata is larger than
448
+ MAX_GIT_META_DATA_SIZE_IN_BYTES
449
+ */
450
+ const GIT_META_DATA_TRUNCATED = '...[TRUNCATED]';
451
+
444
452
  const turboScaleObj = {};
445
453
 
446
454
  module.exports = Object.freeze({
@@ -475,5 +483,7 @@ module.exports = Object.freeze({
475
483
  CYPRESS_V10_AND_ABOVE_TYPE,
476
484
  CYPRESS_CONFIG_FILE_MAPPING,
477
485
  CYPRESS_CONFIG_FILE_NAMES,
478
- CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS
486
+ CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS,
487
+ MAX_GIT_META_DATA_SIZE_IN_BYTES,
488
+ GIT_META_DATA_TRUNCATED
479
489
  });
@@ -18,6 +18,7 @@ const glob = require('glob');
18
18
  const pGitconfig = promisify(gitconfig);
19
19
  const { readCypressConfigFile } = require('./readCypressConfigUtil');
20
20
  const CrashReporter = require('../testObservability/crashReporter');
21
+ const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants')
21
22
 
22
23
  exports.debug = (text, shouldReport = false, throwable = null) => {
23
24
  if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
@@ -119,7 +120,7 @@ exports.getGitMetaData = () => {
119
120
 
120
121
  const { remote } = await pGitconfig(info.commonGitDir);
121
122
  const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
122
- resolve({
123
+ let gitMetaData = {
123
124
  "name": "git",
124
125
  "sha": info["sha"],
125
126
  "short_sha": info["abbreviatedSha"],
@@ -136,7 +137,11 @@ exports.getGitMetaData = () => {
136
137
  "last_tag": info["lastTag"],
137
138
  "commits_since_last_tag": info["commitsSinceLastTag"],
138
139
  "remotes": remotes
139
- });
140
+ };
141
+
142
+ gitMetaData = exports.checkAndTruncateVCSInfo(gitMetaData);
143
+
144
+ resolve(gitMetaData);
140
145
  } catch(e) {
141
146
  exports.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
142
147
  logger.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
@@ -146,7 +151,7 @@ exports.getGitMetaData = () => {
146
151
  } else {
147
152
  const { remote } = await pGitconfig(info.commonGitDir);
148
153
  const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
149
- resolve({
154
+ let gitMetaData = {
150
155
  "name": "git",
151
156
  "sha": info["sha"],
152
157
  "short_sha": info["abbreviatedSha"],
@@ -163,7 +168,11 @@ exports.getGitMetaData = () => {
163
168
  "last_tag": info["lastTag"],
164
169
  "commits_since_last_tag": info["commitsSinceLastTag"],
165
170
  "remotes": remotes
166
- });
171
+ };
172
+
173
+ gitMetaData = exports.checkAndTruncateVCSInfo(gitMetaData);
174
+
175
+ resolve(gitMetaData);
167
176
  }
168
177
  } catch(err) {
169
178
  exports.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
@@ -387,3 +396,48 @@ exports.getSupportFiles = (bsConfig, isA11y) => {
387
396
  cleanupParams: Object.keys(cleanupParams).length ? cleanupParams : null
388
397
  };
389
398
  }
399
+
400
+ exports.checkAndTruncateVCSInfo = (gitMetaData) => {
401
+ const gitMetaDataSizeInBytes = exports.getSizeOfJsonObjectInBytes(gitMetaData);
402
+
403
+ if (gitMetaDataSizeInBytes && gitMetaDataSizeInBytes > MAX_GIT_META_DATA_SIZE_IN_BYTES) {
404
+ const truncateSize = gitMetaDataSizeInBytes - MAX_GIT_META_DATA_SIZE_IN_BYTES;
405
+ gitMetaData.commit_message = exports.truncateString(gitMetaData.commit_message, truncateSize);
406
+ logger.info(`The commit has been truncated. Size of commit after truncation is ${ exports.getSizeOfJsonObjectInBytes(gitMetaData) / 1024} KB`);
407
+ }
408
+
409
+ return gitMetaData;
410
+ };
411
+
412
+ exports.getSizeOfJsonObjectInBytes = (jsonData) => {
413
+ try {
414
+ if (jsonData && jsonData instanceof Object) {
415
+ const buffer = Buffer.from(JSON.stringify(jsonData));
416
+
417
+ return buffer.length;
418
+ }
419
+ } catch (error) {
420
+ logger.debug(`Something went wrong while calculating size of JSON object: ${error}`);
421
+ }
422
+
423
+ return -1;
424
+ };
425
+
426
+ exports.truncateString = (field, truncateSizeInBytes) => {
427
+ try {
428
+ const bufferSizeInBytes = Buffer.from(GIT_META_DATA_TRUNCATED).length;
429
+
430
+ const fieldBufferObj = Buffer.from(field);
431
+ const lenOfFieldBufferObj = fieldBufferObj.length;
432
+ const finalLen = Math.ceil(lenOfFieldBufferObj - truncateSizeInBytes - bufferSizeInBytes);
433
+ if (finalLen > 0) {
434
+ const truncatedString = fieldBufferObj.subarray(0, finalLen).toString() + GIT_META_DATA_TRUNCATED;
435
+
436
+ return truncatedString;
437
+ }
438
+ } catch (error) {
439
+ logger.debug(`Error while truncating field, nothing was truncated here: ${error}`);
440
+ }
441
+
442
+ return field;
443
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.31.0",
3
+ "version": "1.31.2",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  "request": "2.88.2",
30
30
  "requestretry": "7.1.0",
31
31
  "table": "5.4.6",
32
- "update-notifier": "5.1.0",
32
+ "update-notifier": "7.0.0",
33
33
  "uuid": "8.3.2",
34
34
  "windows-release": "^5.1.0",
35
35
  "winston": "2.4.4",