browserstack-cypress-cli 1.24.4 → 1.25.0

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.
@@ -184,6 +184,9 @@ module.exports = function run(args, rawArgs) {
184
184
  // set record feature caps
185
185
  utils.setRecordCaps(bsConfig, args, cypressConfigFile);
186
186
 
187
+ // set the interactive debugging capability
188
+ utils.setInteractiveCapability(bsConfig);
189
+
187
190
  // warn if specFiles cross our limit
188
191
  utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs, buildReportData);
189
192
  markBlockEnd('preArchiveSteps');
@@ -242,6 +242,23 @@ const validate = (bsConfig, args) => {
242
242
  addCypressZipStartLocation(bsConfig.run_settings);
243
243
  }
244
244
 
245
+ // check if Interactive Capabilities Caps passed is correct or not
246
+ if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging) && !Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) {
247
+ if(Utils.isConflictingBooleanValues(bsConfig.run_settings.interactive_debugging, bsConfig.run_settings.interactiveDebugging)) {
248
+ reject(Constants.userMessages.CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES);
249
+ } else if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging) && Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) {
250
+ logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
251
+ }
252
+ } else if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging)) {
253
+ if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging)) {
254
+ logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
255
+ }
256
+ } else if(!Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) {
257
+ if(Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) {
258
+ logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
259
+ }
260
+ }
261
+
245
262
  // check if two config files are present at the same location
246
263
  let cypressFileDirectory = path.dirname(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
247
264
  let listOfFiles = fs.readdirSync(cypressFileDirectory);
@@ -117,7 +117,9 @@ const userMessages = {
117
117
  NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR:
118
118
  "Unable to determine zip upload progress due to undefined/null connection request",
119
119
  CYPRESS_PORT_WARNING:
120
- "The requested port number <x> is ignored. The default BrowserStack port will be used for this execution"
120
+ "The requested port number <x> is ignored. The default BrowserStack port will be used for this execution",
121
+ CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES:
122
+ "Conflicting values (True & False) were found for the interactive_debugging capability. Please resolve this issue to proceed further."
121
123
  };
122
124
 
123
125
  const validationMessages = {
@@ -1000,6 +1000,24 @@ exports.setHeaded = (bsConfig, args) => {
1000
1000
  logger.debug(`headless mode set to ${bsConfig.run_settings.headless}`);
1001
1001
  };
1002
1002
 
1003
+ exports.isConflictingBooleanValues = (value1, value2) => {
1004
+ return (value1.toString() === "true" && value2.toString() === "false") || (value1.toString() === "false" && value2.toString() === "true")
1005
+ };
1006
+
1007
+ exports.isNonBooleanValue = (value) => {
1008
+ return value.toString() !== "true" && value.toString() !== "false";
1009
+ };
1010
+
1011
+ exports.setInteractiveCapability = (bsConfig) => {
1012
+ let interactiveDebuggingTemp = "true";
1013
+ let interactive_debugging = bsConfig.run_settings.interactive_debugging;
1014
+ let interactiveDebugging = bsConfig.run_settings.interactiveDebugging;
1015
+ if(this.isNotUndefined(interactive_debugging) && !this.isNonBooleanValue(interactive_debugging)) interactiveDebuggingTemp = interactive_debugging;
1016
+ else if(this.isNotUndefined(interactiveDebugging) && !this.isNonBooleanValue(interactiveDebugging)) interactiveDebuggingTemp = interactiveDebugging;
1017
+ logger.debug(`Setting interactiveDebugging flag to ${interactiveDebuggingTemp}`);
1018
+ bsConfig.run_settings.interactiveDebugging = interactiveDebuggingTemp;
1019
+ }
1020
+
1003
1021
  exports.setNoWrap = (_bsConfig, args) => {
1004
1022
  if (args.noWrap === true || this.searchForOption('--no-wrap')) {
1005
1023
  process.env.SYNC_NO_WRAP = true;
@@ -5,6 +5,7 @@ const http = require('http');
5
5
  const https = require('https');
6
6
 
7
7
  const logger = require("../../helpers/logger").winstonLogger;
8
+ const utils = require('../../helpers/utils');
8
9
 
9
10
  const { API_URL, consoleHolder } = require('../helper/constants');
10
11
 
@@ -47,9 +48,43 @@ exports.requireModule = (module, internal = false) => {
47
48
  return require(local_path);
48
49
  }
49
50
 
50
- getPackageVersion = (package_) => {
51
+ getPackageVersion = (package_, bsConfig = null) => {
51
52
  if(packages[package_]) return packages[package_];
52
- return packages[package_] = this.requireModule(`${package_}/package.json`).version;
53
+ let packageVersion;
54
+ /* Try to find version from module path */
55
+ try {
56
+ packages[package_] = this.requireModule(`${package_}/package.json`).version;
57
+ logger.info(`Getting ${package_} package version from module path = ${packages[package_]}`);
58
+ packageVersion = packages[package_];
59
+ } catch(e) {
60
+ debug(`Unable to find package ${package_} at module path with error ${e}`);
61
+ }
62
+
63
+ /* Read package version from npm_dependencies in browserstack.json file if present */
64
+ if(utils.isUndefined(packageVersion) && bsConfig && (process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1")) {
65
+ const runSettings = bsConfig.run_settings;
66
+ if (runSettings && runSettings.npm_dependencies !== undefined &&
67
+ Object.keys(runSettings.npm_dependencies).length !== 0 &&
68
+ typeof runSettings.npm_dependencies === 'object') {
69
+ if (package_ in runSettings.npm_dependencies) {
70
+ packages[package_] = runSettings.npm_dependencies[package_];
71
+ logger.info(`Getting ${package_} package version from browserstack.json = ${packages[package_]}`);
72
+ packageVersion = packages[package_];
73
+ }
74
+ }
75
+ }
76
+
77
+ /* Read package version from project's package.json if present */
78
+ const packageJSONPath = path.join(process.cwd(), 'package.json');
79
+ if(utils.isUndefined(packageVersion) && fs.existsSync(packageJSONPath)) {
80
+ const packageJSONContents = require(packageJSONPath);
81
+ if(packageJSONContents.devDependencies && !utils.isUndefined(packageJSONContents.devDependencies[package_])) packages[package_] = packageJSONContents.devDependencies[package_];
82
+ if(packageJSONContents.dependencies && !utils.isUndefined(packageJSONContents.dependencies[package_])) packages[package_] = packageJSONContents.dependencies[package_];
83
+ logger.info(`Getting ${package_} package version from package.json = ${packages[package_]}`);
84
+ packageVersion = packages[package_];
85
+ }
86
+
87
+ return packageVersion;
53
88
  }
54
89
 
55
90
  getAgentVersion = () => {
@@ -96,7 +131,7 @@ class CrashReporter {
96
131
  hashed_id: process.env.BS_TESTOPS_BUILD_HASHED_ID,
97
132
  observability_version: {
98
133
  frameworkName: 'Cypress',
99
- frameworkVersion: getPackageVersion('cypress'),
134
+ frameworkVersion: getPackageVersion('cypress', this.userConfigForReporting.browserstackConfigFile),
100
135
  sdkVersion: getAgentVersion()
101
136
  },
102
137
  exception: {
@@ -351,9 +351,43 @@ const getCiInfo = () => {
351
351
 
352
352
  let packages = {};
353
353
 
354
- exports.getPackageVersion = (package_) => {
354
+ exports.getPackageVersion = (package_, bsConfig = null) => {
355
355
  if(packages[package_]) return packages[package_];
356
- return packages[package_] = this.requireModule(`${package_}/package.json`).version;
356
+ let packageVersion;
357
+ /* Try to find version from module path */
358
+ try {
359
+ packages[package_] = this.requireModule(`${package_}/package.json`).version;
360
+ logger.info(`Getting ${package_} package version from module path = ${packages[package_]}`);
361
+ packageVersion = packages[package_];
362
+ } catch(e) {
363
+ exports.debug(`Unable to find package ${package_} at module path with error ${e}`);
364
+ }
365
+
366
+ /* Read package version from npm_dependencies in browserstack.json file if present */
367
+ if(utils.isUndefined(packageVersion) && bsConfig && (process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1")) {
368
+ const runSettings = bsConfig.run_settings;
369
+ if (runSettings && runSettings.npm_dependencies !== undefined &&
370
+ Object.keys(runSettings.npm_dependencies).length !== 0 &&
371
+ typeof runSettings.npm_dependencies === 'object') {
372
+ if (package_ in runSettings.npm_dependencies) {
373
+ packages[package_] = runSettings.npm_dependencies[package_];
374
+ logger.info(`Getting ${package_} package version from browserstack.json = ${packages[package_]}`);
375
+ packageVersion = packages[package_];
376
+ }
377
+ }
378
+ }
379
+
380
+ /* Read package version from project's package.json if present */
381
+ const packageJSONPath = path.join(process.cwd(), 'package.json');
382
+ if(utils.isUndefined(packageVersion) && fs.existsSync(packageJSONPath)) {
383
+ const packageJSONContents = require(packageJSONPath);
384
+ if(packageJSONContents.devDependencies && !utils.isUndefined(packageJSONContents.devDependencies[package_])) packages[package_] = packageJSONContents.devDependencies[package_];
385
+ if(packageJSONContents.dependencies && !utils.isUndefined(packageJSONContents.dependencies[package_])) packages[package_] = packageJSONContents.dependencies[package_];
386
+ logger.info(`Getting ${package_} package version from package.json = ${packages[package_]}`);
387
+ packageVersion = packages[package_];
388
+ }
389
+
390
+ return packageVersion;
357
391
  }
358
392
 
359
393
  exports.getAgentVersion = () => {
@@ -452,9 +486,14 @@ const setBrowserstackCypressCliDependency = (bsConfig) => {
452
486
  }
453
487
 
454
488
  const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => {
455
- const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath));
456
- if(bsConfig) process.env.OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH = bsConfig.run_settings.cypress_config_file;
457
- return cypressConfigFile;
489
+ try {
490
+ const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath));
491
+ if(bsConfig) process.env.OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH = bsConfig.run_settings.cypress_config_file;
492
+ return cypressConfigFile;
493
+ } catch(e) {
494
+ exports.debug(`Encountered an error when trying to import Cypress Config File ${e}`);
495
+ return {};
496
+ }
458
497
  }
459
498
 
460
499
  exports.setCrashReportingConfigFromReporter = (credentialsStr, bsConfigPath, cypressConfigPath) => {
@@ -530,7 +569,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
530
569
  'version_control': await getGitMetaData(),
531
570
  'observability_version': {
532
571
  frameworkName: "Cypress",
533
- frameworkVersion: exports.getPackageVersion('cypress'),
572
+ frameworkVersion: exports.getPackageVersion('cypress', user_config),
534
573
  sdkVersion: exports.getAgentVersion()
535
574
  }
536
575
  };
package/log/usage.log ADDED
@@ -0,0 +1 @@
1
+ {"level":"info","message":"Sending {\"event_type\":\"cypress_cli_stats\",\"data\":{\"bstack_json\":\"null\",\"run_settings\":\"\",\"os\":\"darwin\",\"os_version\":\"21.6.0\",\"bstack_json_found_in_pwd\":false,\"cypress_config_file_found_in_pwd\":null,\"cli_version\":\"1.24.4\",\"cli_path\":\"/Users/archish/.nvm/versions/node/v16.16.0/lib/node_modules\",\"npm_version\":\"8.11.0\",\"local_cypress_version\":null,\"ci_environment\":null,\"event_timestamp\":\"7/27/2023, 4:39:59 PM\",\"data\":null,\"raw_args\":\"[\\\"run\\\",\\\"--async\\\"]\",\"cli_args\":\"{\\\"_\\\":[\\\"run\\\"],\\\"async\\\":true,\\\"cf\\\":\\\"browserstack.json\\\",\\\"config-file\\\":\\\"browserstack.json\\\",\\\"configFile\\\":\\\"browserstack.json\\\",\\\"cli-debug\\\":false,\\\"cliDebug\\\":false,\\\"ccf\\\":\\\"./cypress.json\\\",\\\"cypress-config-file\\\":\\\"./cypress.json\\\",\\\"cypressConfigFile\\\":\\\"./cypress.json\\\",\\\"disable-npm-warning\\\":false,\\\"disableNpmWarning\\\":false,\\\"sync\\\":true,\\\"force-upload\\\":false,\\\"forceUpload\\\":false,\\\"headed\\\":false,\\\"no-wrap\\\":false,\\\"noWrap\\\":false,\\\"$0\\\":\\\"browserstack-cypress\\\"}\",\"message_type\":\"error\",\"error_code\":\"bstack_json_invalid_unknown\"}} to https://eds.browserstack.com:443/send_event_cy_internal","timestamp":"2023-07-27T11:09:59.626Z"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.24.4",
3
+ "version": "1.25.0",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {