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
@@ -3,6 +3,7 @@ const request = require("request"),
3
3
  config = require("../config"),
4
4
  utils = require("../utils"),
5
5
  logger = require("../logger").syncCliLogger,
6
+ winstonLogger = require("../logger").winstonLogger,
6
7
  async = require('async'),
7
8
  Constants = require("../constants"),
8
9
  tableStream = require('table').createStream,
@@ -13,7 +14,10 @@ let specSummary = {
13
14
  "specs": [],
14
15
  "duration": null
15
16
  }
16
-
17
+ let noWrap = false;
18
+ let terminalWidth = (process.stdout.columns) * 0.9;
19
+ let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
20
+ if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
17
21
 
18
22
  let getOptions = (auth, build_id) => {
19
23
  return {
@@ -30,15 +34,26 @@ let getOptions = (auth, build_id) => {
30
34
  };
31
35
  }
32
36
 
33
- let getTableConfig = () => {
37
+ let getTableConfig = (termWidth) => {
38
+ let centerWidth = Math.ceil(termWidth * 0.01),
39
+ leftWidth = Math.floor(termWidth * 0.75),
40
+ colWidth = Math.floor(termWidth * 0.2);
41
+
42
+ // Do not autosize on terminal's width if no-wrap provided
43
+ if (noWrap || isNaN(termWidth)) {
44
+ centerWidth = 1;
45
+ leftWidth = 100;
46
+ colWidth = 30;
47
+ }
48
+
34
49
  return {
35
50
  border: getBorderConfig(),
36
51
  columns: {
37
- 1: {alignment: 'center', width: 1},
38
- 2: {alignment: 'left', width: 100}
52
+ 1: {alignment: 'center', width: centerWidth},
53
+ 2: {alignment: 'left', width: leftWidth}
39
54
  },
40
55
  columnDefault: {
41
- width: 30,
56
+ width: colWidth,
42
57
  },
43
58
  columnCount: 3,
44
59
  };
@@ -67,10 +82,19 @@ let getBorderConfig = () => {
67
82
  }
68
83
  }
69
84
 
70
- let printSpecsStatus = (bsConfig, buildDetails) => {
85
+ let setNoWrapParams = () => {
86
+ noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
87
+ // Do not show the separator based on terminal width if no-wrap provided.
88
+ if (noWrap) {
89
+ lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
90
+ }
91
+ };
92
+
93
+ let printSpecsStatus = (bsConfig, buildDetails, rawArgs) => {
94
+ setNoWrapParams();
71
95
  return new Promise((resolve, reject) => {
72
96
  options = getOptions(bsConfig.auth, buildDetails.build_id)
73
- tableConfig = getTableConfig();
97
+ tableConfig = getTableConfig(terminalWidth);
74
98
  stream = tableStream(tableConfig);
75
99
 
76
100
  async.whilst(
@@ -81,7 +105,10 @@ let printSpecsStatus = (bsConfig, buildDetails) => {
81
105
  whileProcess(callback)
82
106
  },
83
107
  function(err, result) { // when loop ends
84
- logger.info("\n--------------------------------------------------------------------------------")
108
+ if (err) {
109
+ utils.sendUsageReport(bsConfig, {}, `buildId: ${buildDetails.build_id}`, 'error', 'sync_cli_error', err, rawArgs);
110
+ }
111
+ logger.info(lineSeparator);
85
112
  specSummary.duration = endTime - startTime
86
113
  resolve(specSummary)
87
114
  }
@@ -138,8 +165,9 @@ let showSpecsStatus = (data) => {
138
165
  }
139
166
 
140
167
  let printInitialLog = () => {
168
+ winstonLogger.info(Constants.syncCLI.STARTUP_MESSAGE);
141
169
  logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`)
142
- logger.info("--------------------------------------------------------------------------------")
170
+ logger.info(lineSeparator);
143
171
  n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
144
172
  }
145
173
 
@@ -0,0 +1,71 @@
1
+ 'use strict'
2
+
3
+ const { isUndefined } = require('./utils');
4
+
5
+
6
+ let sessionTimes = {
7
+ referenceTimes: {
8
+ absoluteStartTime: Date.now()
9
+ }, // Absolute times which needs to be used later to calculate logTimes
10
+ logTimes: {}, // Time Difference in ms which we need to push to EDS
11
+ eventTime: {}, // Time for particular events
12
+ };
13
+
14
+ const initTimeComponents = () => {
15
+ sessionTimes = {referenceTimes: {absoluteStartTime: Date.now()}, logTimes: {}, eventTime: {}};
16
+ };
17
+
18
+ const markBlockStart = (blockName) => {
19
+ sessionTimes.referenceTimes[blockName] = Date.now();
20
+ };
21
+
22
+ const markBlockEnd = (blockName) => {
23
+ const startTime = sessionTimes.referenceTimes[blockName] || sessionTimes.referenceTimes.absoluteStartTime;
24
+ markBlockDiff(blockName, startTime, Date.now());
25
+ };
26
+
27
+ const markBlockDiff = (blockName, startTime, stopTime) => {
28
+ sessionTimes.logTimes[blockName] = stopTime - startTime;
29
+ }
30
+
31
+ const instrumentEventTime = (eventName) => {
32
+ sessionTimes.eventTime[eventName] = new Date(new Date().toUTCString());
33
+ }
34
+
35
+ const getTimeComponents = () => {
36
+ const data = convertDotToNestedObject(sessionTimes.logTimes);
37
+ return Object.assign(data, sessionTimes.eventTime);
38
+ };
39
+
40
+ const convertDotToNestedObject = (dotNotationObject) => {
41
+ let nestedObject = {};
42
+
43
+ Object.keys(dotNotationObject).forEach((key) => {
44
+ let dotKeys = key.split('.');
45
+ let currentKey = nestedObject;
46
+ for(let i = 0; i < dotKeys.length - 1; i++) {
47
+ if (isUndefined(currentKey[dotKeys[i]])) {
48
+ currentKey[dotKeys[i]] = {};
49
+ } else if (Number.isInteger(currentKey[dotKeys[i]])) {
50
+ currentKey[dotKeys[i]] = {total: currentKey[dotKeys[i]]};
51
+ }
52
+ currentKey = currentKey[dotKeys[i]];
53
+ }
54
+ if (isUndefined(currentKey[dotKeys[dotKeys.length - 1]]) || Number.isInteger(currentKey[dotKeys[dotKeys.length - 1]])) {
55
+ currentKey[dotKeys[dotKeys.length - 1]] = dotNotationObject[key];
56
+ } else {
57
+ currentKey[dotKeys[dotKeys.length - 1]].total = dotNotationObject[key];
58
+ }
59
+ });
60
+
61
+ return nestedObject;
62
+ };
63
+
64
+ module.exports = {
65
+ initTimeComponents,
66
+ instrumentEventTime,
67
+ markBlockStart,
68
+ markBlockEnd,
69
+ markBlockDiff,
70
+ getTimeComponents,
71
+ };
@@ -6,7 +6,10 @@ const cp = require("child_process"),
6
6
  path = require('path');
7
7
 
8
8
  const config = require('./config'),
9
- fileLogger = require('./logger').fileLogger;
9
+ fileLogger = require('./logger').fileLogger,
10
+ utils = require('./utils');
11
+
12
+ const { AUTH_REGEX, REDACTED_AUTH } = require("./constants");
10
13
 
11
14
  function get_version(package_name) {
12
15
  try {
@@ -33,7 +36,7 @@ function local_cypress_version(bsConfig) {
33
36
  // 1. check version of Cypress installed in local project
34
37
  // 2. check version of Cypress installed globally if not present in project
35
38
 
36
- if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
39
+ if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypressProjectDir) {
37
40
  let version = get_version(path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', '.bin', 'cypress'));
38
41
  if (!version) {
39
42
  version = get_version('cypress');
@@ -80,7 +83,7 @@ function cli_version_and_path(bsConfig) {
80
83
  // 1. check version of Cypress installed in local project
81
84
  // 2. check version of Cypress installed globally if not present in project
82
85
 
83
- if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
86
+ if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypressProjectDir) {
84
87
  let _path = path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', 'browserstack-cypress');
85
88
  let version = get_version(_path);
86
89
  if (!version) {
@@ -172,19 +175,43 @@ function isUsageReportingEnabled() {
172
175
  function send(args) {
173
176
  if (isUsageReportingEnabled() === "true") return;
174
177
 
175
- let bsConfig = args.bstack_config;
178
+ let bsConfig = JSON.parse(JSON.stringify(args.bstack_config));
179
+ let runSettings = "";
180
+ let sanitizedbsConfig = "";
176
181
  let cli_details = cli_version_and_path(bsConfig);
177
- let data = {}
182
+ let data = utils.isUndefined(args.data) ? {} : args.data;
178
183
 
179
184
  if (bsConfig && bsConfig.run_settings) {
180
- data.cypress_version = bsConfig.run_settings.cypress_version
185
+ runSettings = bsConfig.run_settings;
186
+ data.cypress_version = bsConfig.run_settings.cypress_version;
181
187
  }
182
188
 
189
+ sanitizedbsConfig = `${(typeof bsConfig === 'string') ? bsConfig :
190
+ JSON.stringify(bsConfig)}`.replace(AUTH_REGEX, REDACTED_AUTH);
191
+
183
192
  delete args.bstack_config;
184
193
 
194
+ let zipUploadDetails = {
195
+ test_suite_zip_upload: data.test_suite_zip_upload,
196
+ package_zip_upload: data.package_zip_upload,
197
+ test_suite_zip_size: data.test_suite_zip_size,
198
+ test_suite_zip_upload_avg_speed: data.test_suite_zip_upload_avg_speed,
199
+ npm_package_zip_size: data.npm_package_zip_size,
200
+ npm_package_zip_upload_avg_speed: data.npm_package_zip_upload_avg_speed,
201
+ }
202
+
203
+ Object.keys(zipUploadDetails).forEach((key) => {
204
+ delete data[key];
205
+ })
206
+
185
207
  const payload = {
186
208
  event_type: "cypress_cli_stats",
187
209
  data: {
210
+ build_hashed_id: data.build_id,
211
+ user_id: data.user_id,
212
+ parallels: data.parallels,
213
+ bstack_json: sanitizedbsConfig,
214
+ run_settings: runSettings,
188
215
  os: _os(),
189
216
  os_version: os_version(),
190
217
  bstack_json_found_in_pwd: bstack_json_found_in_pwd(),
@@ -196,6 +223,8 @@ function send(args) {
196
223
  ci_environment: ci_environment(),
197
224
  event_timestamp: new Date().toLocaleString(),
198
225
  data: JSON.stringify(data),
226
+ raw_args: JSON.stringify(args.raw_args),
227
+ ...zipUploadDetails,
199
228
  ...args,
200
229
  },
201
230
  };