browserstack-cypress-cli 1.32.8 → 1.34.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.
Files changed (82) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/.nyc_output/1c1b6051-514d-4847-bd2a-d03b2d537cfb.json +1 -0
  3. package/.nyc_output/20afa9bb-5b9f-42e2-adfe-9dbf55591bb8.json +1 -0
  4. package/.nyc_output/22e511c5-8971-4265-b783-553560573bdc.json +1 -0
  5. package/.nyc_output/2d21e700-0ac9-4ac9-8f8c-322a5cbefe8d.json +1 -0
  6. package/.nyc_output/3c54171a-9bf6-478d-a4c0-28ec402806cf.json +1 -0
  7. package/.nyc_output/52675bfd-ff62-4f5b-944c-e3f48af2972c.json +1 -0
  8. package/.nyc_output/5766c03a-3d68-4298-89f7-c298c025e176.json +1 -0
  9. package/.nyc_output/625adc06-9859-4c11-8892-0498922cc2aa.json +1 -0
  10. package/.nyc_output/730f797e-97d0-44a8-b5d0-7fd3f8c06d75.json +1 -0
  11. package/.nyc_output/73501809-7c04-439e-8c09-9a1bff7962c6.json +1 -0
  12. package/.nyc_output/77484870-1b25-4c2d-a361-2ac51c0951bc.json +1 -0
  13. package/.nyc_output/8098fa2d-312d-4762-ad96-3e9827eaef09.json +1 -0
  14. package/.nyc_output/87357e21-685f-4861-9a6f-4c6b62f85ac0.json +1 -0
  15. package/.nyc_output/8fcd9f27-af41-43f7-bdf8-7bea2efd7abb.json +1 -0
  16. package/.nyc_output/9f8ad8fd-775b-4a99-ba77-c6142e7df5e9.json +1 -0
  17. package/.nyc_output/a1de1cdd-5eed-409d-a528-1c7cf16d56b5.json +1 -0
  18. package/.nyc_output/a25237ac-032d-4a27-af09-fb32326b539a.json +1 -0
  19. package/.nyc_output/a5d38a55-372c-4676-b4bc-c6def0669c0d.json +1 -0
  20. package/.nyc_output/a67d3cbf-0548-4fcb-8aad-2af60b532670.json +1 -0
  21. package/.nyc_output/aa2117b0-10c0-4f5b-9d8d-1f96375f0240.json +1 -0
  22. package/.nyc_output/ac17471f-3f16-45ab-b53e-ba8956afd5d4.json +1 -0
  23. package/.nyc_output/bbbe672a-8524-4850-b6b3-b725aa2b6c16.json +1 -0
  24. package/.nyc_output/c7289c09-7047-47cb-9737-f11fe7fc9628.json +1 -0
  25. package/.nyc_output/ceeeac29-3ca3-40af-b779-12c0408cf05d.json +1 -0
  26. package/.nyc_output/d08d37a4-6abc-41a7-98bd-de074a1fca7f.json +1 -0
  27. package/.nyc_output/d1dbecb0-8458-41bc-86c8-9d2470b60415.json +1 -0
  28. package/.nyc_output/d7245fa2-3732-4790-831b-44dbcba15a16.json +1 -0
  29. package/.nyc_output/e184572f-281b-4bd6-81e3-58842eac98ee.json +1 -0
  30. package/.nyc_output/efd98bd9-1699-472b-ab98-0808e5d39899.json +1 -0
  31. package/.nyc_output/processinfo/1c1b6051-514d-4847-bd2a-d03b2d537cfb.json +1 -0
  32. package/.nyc_output/processinfo/20afa9bb-5b9f-42e2-adfe-9dbf55591bb8.json +1 -0
  33. package/.nyc_output/processinfo/22e511c5-8971-4265-b783-553560573bdc.json +1 -0
  34. package/.nyc_output/processinfo/2d21e700-0ac9-4ac9-8f8c-322a5cbefe8d.json +1 -0
  35. package/.nyc_output/processinfo/3c54171a-9bf6-478d-a4c0-28ec402806cf.json +1 -0
  36. package/.nyc_output/processinfo/52675bfd-ff62-4f5b-944c-e3f48af2972c.json +1 -0
  37. package/.nyc_output/processinfo/5766c03a-3d68-4298-89f7-c298c025e176.json +1 -0
  38. package/.nyc_output/processinfo/625adc06-9859-4c11-8892-0498922cc2aa.json +1 -0
  39. package/.nyc_output/processinfo/730f797e-97d0-44a8-b5d0-7fd3f8c06d75.json +1 -0
  40. package/.nyc_output/processinfo/73501809-7c04-439e-8c09-9a1bff7962c6.json +1 -0
  41. package/.nyc_output/processinfo/77484870-1b25-4c2d-a361-2ac51c0951bc.json +1 -0
  42. package/.nyc_output/processinfo/8098fa2d-312d-4762-ad96-3e9827eaef09.json +1 -0
  43. package/.nyc_output/processinfo/87357e21-685f-4861-9a6f-4c6b62f85ac0.json +1 -0
  44. package/.nyc_output/processinfo/8fcd9f27-af41-43f7-bdf8-7bea2efd7abb.json +1 -0
  45. package/.nyc_output/processinfo/9f8ad8fd-775b-4a99-ba77-c6142e7df5e9.json +1 -0
  46. package/.nyc_output/processinfo/a1de1cdd-5eed-409d-a528-1c7cf16d56b5.json +1 -0
  47. package/.nyc_output/processinfo/a25237ac-032d-4a27-af09-fb32326b539a.json +1 -0
  48. package/.nyc_output/processinfo/a5d38a55-372c-4676-b4bc-c6def0669c0d.json +1 -0
  49. package/.nyc_output/processinfo/a67d3cbf-0548-4fcb-8aad-2af60b532670.json +1 -0
  50. package/.nyc_output/processinfo/aa2117b0-10c0-4f5b-9d8d-1f96375f0240.json +1 -0
  51. package/.nyc_output/processinfo/ac17471f-3f16-45ab-b53e-ba8956afd5d4.json +1 -0
  52. package/.nyc_output/processinfo/bbbe672a-8524-4850-b6b3-b725aa2b6c16.json +1 -0
  53. package/.nyc_output/processinfo/c7289c09-7047-47cb-9737-f11fe7fc9628.json +1 -0
  54. package/.nyc_output/processinfo/ceeeac29-3ca3-40af-b779-12c0408cf05d.json +1 -0
  55. package/.nyc_output/processinfo/d08d37a4-6abc-41a7-98bd-de074a1fca7f.json +1 -0
  56. package/.nyc_output/processinfo/d1dbecb0-8458-41bc-86c8-9d2470b60415.json +1 -0
  57. package/.nyc_output/processinfo/d7245fa2-3732-4790-831b-44dbcba15a16.json +1 -0
  58. package/.nyc_output/processinfo/e184572f-281b-4bd6-81e3-58842eac98ee.json +1 -0
  59. package/.nyc_output/processinfo/efd98bd9-1699-472b-ab98-0808e5d39899.json +1 -0
  60. package/.nyc_output/processinfo/index.json +1 -0
  61. package/bin/accessibility-automation/cypress/index.js +1 -1
  62. package/bin/accessibility-automation/helper.js +60 -32
  63. package/bin/commands/runs.js +10 -3
  64. package/bin/helpers/build.js +2 -0
  65. package/bin/helpers/capabilityHelper.js +7 -1
  66. package/bin/helpers/constants.js +22 -0
  67. package/bin/helpers/helper.js +2 -1
  68. package/bin/helpers/packageInstaller.js +3 -2
  69. package/bin/helpers/readCypressConfigUtil.js +133 -11
  70. package/bin/helpers/utils.js +241 -3
  71. package/bin/templates/configTemplate.js +2 -0
  72. package/bin/testObservability/crashReporter/index.js +2 -2
  73. package/bin/testObservability/cypress/index.js +194 -96
  74. package/bin/testObservability/helper/cleanupQueueSync.js +1 -2
  75. package/bin/testObservability/helper/constants.js +4 -0
  76. package/bin/testObservability/helper/helper.js +21 -22
  77. package/bin/testObservability/helper/requestQueueHandler.js +1 -1
  78. package/bin/testObservability/plugin/index.js +6 -0
  79. package/bin/testObservability/plugin/ipcServer.js +1 -1
  80. package/bin/testObservability/reporter/index.js +26 -18
  81. package/log/usage.log +393 -4
  82. package/package.json +6 -5
@@ -13,6 +13,120 @@ exports.detectLanguage = (cypress_config_filename) => {
13
13
  return constants.CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS.includes(extension) ? extension : 'js'
14
14
  }
15
15
 
16
+ function resolveTsConfigPath(bsConfig, cypress_config_filepath) {
17
+ const working_dir = path.dirname(cypress_config_filepath);
18
+
19
+ // Priority order for finding tsconfig
20
+ const candidates = [
21
+ bsConfig.run_settings && bsConfig.run_settings.ts_config_file_path, // User specified
22
+ path.join(working_dir, 'tsconfig.json'), // Same directory as cypress config
23
+ path.join(working_dir, '..', 'tsconfig.json'), // Parent directory
24
+ path.join(process.cwd(), 'tsconfig.json') // Project root
25
+ ].filter(Boolean).map(p => path.resolve(p));
26
+
27
+ for (const candidate of candidates) {
28
+ if (fs.existsSync(candidate)) {
29
+ logger.debug(`Found tsconfig at: ${candidate}`);
30
+ return candidate;
31
+ }
32
+ }
33
+
34
+ return null;
35
+ }
36
+
37
+ function generateTscCommandAndTempTsConfig(bsConfig, bstack_node_modules_path, complied_js_dir, cypress_config_filepath) {
38
+ const working_dir = path.dirname(cypress_config_filepath);
39
+ const typescript_path = path.join(bstack_node_modules_path, 'typescript', 'bin', 'tsc');
40
+ const tsc_alias_path = require.resolve('tsc-alias/dist/bin/index.js');
41
+
42
+ // Smart tsconfig detection and validation
43
+ const resolvedTsConfigPath = resolveTsConfigPath(bsConfig, cypress_config_filepath);
44
+ let hasValidTsConfig = false;
45
+
46
+ if (resolvedTsConfigPath) {
47
+ try {
48
+ // Validate the tsconfig is readable and valid JSON
49
+ const tsConfigContent = fs.readFileSync(resolvedTsConfigPath, 'utf8');
50
+ JSON.parse(tsConfigContent);
51
+ hasValidTsConfig = true;
52
+ logger.info(`Using existing tsconfig: ${resolvedTsConfigPath}`);
53
+ } catch (error) {
54
+ logger.warn(`Invalid tsconfig file: ${resolvedTsConfigPath}, falling back to default configuration. Error: ${error.message}`);
55
+ hasValidTsConfig = false;
56
+ }
57
+ } else {
58
+ logger.info('No tsconfig found, using default TypeScript configuration');
59
+ }
60
+
61
+ let tempTsConfig;
62
+
63
+ if (hasValidTsConfig) {
64
+ // Scenario 1: User has valid tsconfig - use extends approach
65
+ tempTsConfig = {
66
+ extends: resolvedTsConfigPath,
67
+ compilerOptions: {
68
+ // Force override critical parameters for BrowserStack compatibility
69
+ "outDir": path.basename(complied_js_dir),
70
+ "listEmittedFiles": true,
71
+ // Ensure these are always set regardless of base tsconfig
72
+ "allowSyntheticDefaultImports": true,
73
+ "esModuleInterop": true
74
+ },
75
+ include: [cypress_config_filepath]
76
+ };
77
+ } else {
78
+ // Scenario 2: No tsconfig or invalid tsconfig - create standalone with all basic parameters
79
+ tempTsConfig = {
80
+ compilerOptions: {
81
+ // Preserve old command-line parameters for backwards compatibility
82
+ "outDir": path.basename(complied_js_dir),
83
+ "listEmittedFiles": true,
84
+ "allowSyntheticDefaultImports": true,
85
+ "module": "commonjs",
86
+ "declaration": false,
87
+
88
+ // Add essential missing parameters for robust compilation
89
+ "target": "es2017",
90
+ "moduleResolution": "node",
91
+ "esModuleInterop": true,
92
+ "allowJs": true,
93
+ "skipLibCheck": true,
94
+ "forceConsistentCasingInFileNames": true,
95
+ "resolveJsonModule": true,
96
+ "strict": false, // Avoid breaking existing code
97
+ "noEmitOnError": false // Continue compilation even with errors
98
+ },
99
+ include: [cypress_config_filepath],
100
+ exclude: ["node_modules", "dist", "build"]
101
+ };
102
+ }
103
+
104
+ // Write the temporary tsconfig
105
+ const tempTsConfigPath = path.join(working_dir, 'tsconfig.singlefile.tmp.json');
106
+ fs.writeFileSync(tempTsConfigPath, JSON.stringify(tempTsConfig, null, 2));
107
+ logger.info(`Temporary tsconfig created at: ${tempTsConfigPath}`);
108
+
109
+ // Platform-specific command generation
110
+ const isWindows = /^win/.test(process.platform);
111
+
112
+ if (isWindows) {
113
+ // Windows: Use && to chain commands, no space after SET
114
+ const setNodePath = isWindows
115
+ ? `set NODE_PATH=${bstack_node_modules_path}`
116
+ : `NODE_PATH="${bstack_node_modules_path}"`;
117
+
118
+ const tscCommand = `${setNodePath} && node "${typescript_path}" --project "${tempTsConfigPath}" && ${setNodePath} && node "${tsc_alias_path}" --project "${tempTsConfigPath}" --verbose`;
119
+ logger.info(`TypeScript compilation command: ${tscCommand}`);
120
+ return { tscCommand, tempTsConfigPath };
121
+ } else {
122
+ // Unix/Linux/macOS: Use ; to separate commands or && to chain
123
+ const nodePathPrefix = `NODE_PATH=${bstack_node_modules_path}`;
124
+ const tscCommand = `${nodePathPrefix} node "${typescript_path}" --project "${tempTsConfigPath}" && ${nodePathPrefix} node "${tsc_alias_path}" --project "${tempTsConfigPath}" --verbose`;
125
+ logger.info(`TypeScript compilation command: ${tscCommand}`);
126
+ return { tscCommand, tempTsConfigPath };
127
+ }
128
+ }
129
+
16
130
  exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_modules_path) => {
17
131
  const cypress_config_filename = bsConfig.run_settings.cypress_config_filename
18
132
  const working_dir = path.dirname(cypress_config_filepath);
@@ -22,19 +136,12 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module
22
136
  }
23
137
  fs.mkdirSync(complied_js_dir, { recursive: true })
24
138
 
25
- const typescript_path = path.join(bstack_node_modules_path, 'typescript', 'bin', 'tsc')
26
-
27
- let tsc_command = `NODE_PATH=${bstack_node_modules_path} node "${typescript_path}" --outDir "${complied_js_dir}" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "${cypress_config_filepath}"`
139
+ const { tscCommand, tempTsConfigPath } = generateTscCommandAndTempTsConfig(bsConfig, bstack_node_modules_path, complied_js_dir, cypress_config_filepath);
28
140
 
29
- if (/^win/.test(process.platform)) {
30
- tsc_command = `set NODE_PATH=${bstack_node_modules_path}&& node "${typescript_path}" --outDir "${complied_js_dir}" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "${cypress_config_filepath}"`
31
- }
32
-
33
-
34
141
  let tsc_output
35
142
  try {
36
- logger.debug(`Running: ${tsc_command}`)
37
- tsc_output = cp.execSync(tsc_command, { cwd: working_dir })
143
+ logger.debug(`Running: ${tscCommand}`)
144
+ tsc_output = cp.execSync(tscCommand, { cwd: working_dir })
38
145
  } catch (err) {
39
146
  // error while compiling ts files
40
147
  logger.debug(err.message);
@@ -44,6 +151,21 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module
44
151
  logger.debug(`Saved compiled js output at: ${complied_js_dir}`);
45
152
  logger.debug(`Finding compiled cypress config file in: ${complied_js_dir}`);
46
153
 
154
+ // Clean up the temporary tsconfig file
155
+ if (fs.existsSync(tempTsConfigPath)) {
156
+ fs.unlinkSync(tempTsConfigPath);
157
+ logger.debug(`Temporary tsconfig file removed: ${tempTsConfigPath}`);
158
+ }
159
+
160
+ if (tsc_output) {
161
+ logger.debug(tsc_output.toString());
162
+ }
163
+
164
+ if (!tsc_output) {
165
+ logger.error('No TypeScript compilation output available');
166
+ return null;
167
+ }
168
+
47
169
  const lines = tsc_output.toString().split('\n');
48
170
  let foundLine = null;
49
171
  for (let i = 0; i < lines.length; i++) {
@@ -53,7 +175,7 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module
53
175
  }
54
176
  }
55
177
  if (foundLine === null) {
56
- logger.error(`No compiled cypress config found. There might some error running ${tsc_command} command`)
178
+ logger.error(`No compiled cypress config found. There might some error running ${tscCommand} command`)
57
179
  return null
58
180
  } else {
59
181
  const compiled_cypress_config_filepath = foundLine.split('TSFILE: ').pop()
@@ -33,6 +33,7 @@ exports.validateBstackJson = (bsConfigPath) => {
33
33
  try {
34
34
  logger.info(`Reading config from ${bsConfigPath}`);
35
35
  let bsConfig = require(bsConfigPath);
36
+ bsConfig = exports.normalizeTestReportingConfig(bsConfig);
36
37
  resolve(bsConfig);
37
38
  } catch (e) {
38
39
  reject(
@@ -492,7 +493,6 @@ exports.setNodeVersion = (bsConfig, args) => {
492
493
  // specs can be passed via command line args as a string
493
494
  // command line args takes precedence over config
494
495
  exports.setUserSpecs = (bsConfig, args) => {
495
-
496
496
  if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) {
497
497
  bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
498
498
  return;
@@ -1499,7 +1499,6 @@ exports.splitStringByCharButIgnoreIfWithinARange = (str, splitChar, leftLimiter,
1499
1499
 
1500
1500
  // blindly send other passed configs with run_settings and handle at backend
1501
1501
  exports.setOtherConfigs = (bsConfig, args) => {
1502
-
1503
1502
  if(o11yHelpers.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
1504
1503
  bsConfig["run_settings"]["reporter"] = TEST_OBSERVABILITY_REPORTER;
1505
1504
  return;
@@ -1519,7 +1518,15 @@ exports.setOtherConfigs = (bsConfig, args) => {
1519
1518
  exports.readBsConfigJSON = (bsConfigPath) => {
1520
1519
  try {
1521
1520
  fs.accessSync(bsConfigPath, fs.constants.R_OK);
1522
- return fs.readFileSync(bsConfigPath, 'utf-8');
1521
+ const configContent = fs.readFileSync(bsConfigPath, 'utf-8');
1522
+ try {
1523
+ const bsConfig = JSON.parse(configContent);
1524
+ const normalizedBsConfig = exports.normalizeTestReportingConfig(bsConfig);
1525
+ return JSON.stringify(normalizedBsConfig);
1526
+ } catch (err) {
1527
+ logger.error(`Error parsing JSON from ${bsConfigPath}:`, err);
1528
+ return null;
1529
+ }
1523
1530
  } catch (err) {
1524
1531
  return null;
1525
1532
  }
@@ -1804,3 +1811,234 @@ exports.decodeJWTToken = (token) => {
1804
1811
  return undefined;
1805
1812
  }
1806
1813
  }
1814
+
1815
+ exports.validateAutoImportConflict = (runSettings) => {
1816
+ const constants = require('./constants');
1817
+
1818
+ // Validate auto_import_dev_dependencies type
1819
+ if (runSettings.auto_import_dev_dependencies !== undefined &&
1820
+ typeof runSettings.auto_import_dev_dependencies !== 'boolean') {
1821
+ throw new Error(constants.validationMessages.AUTO_IMPORT_INVALID_TYPE);
1822
+ }
1823
+
1824
+ // Skip validation if auto_import_dev_dependencies is not enabled
1825
+ if (!runSettings.auto_import_dev_dependencies) {
1826
+ return;
1827
+ }
1828
+
1829
+ // Check if any manual npm dependency configurations have values
1830
+ const hasNpmDeps = runSettings.npm_dependencies &&
1831
+ typeof runSettings.npm_dependencies === 'object' &&
1832
+ Object.keys(runSettings.npm_dependencies).length > 0;
1833
+
1834
+ const hasWinDeps = runSettings.win_npm_dependencies &&
1835
+ typeof runSettings.win_npm_dependencies === 'object' &&
1836
+ Object.keys(runSettings.win_npm_dependencies).length > 0;
1837
+
1838
+ const hasMacDeps = runSettings.mac_npm_dependencies &&
1839
+ typeof runSettings.mac_npm_dependencies === 'object' &&
1840
+ Object.keys(runSettings.mac_npm_dependencies).length > 0;
1841
+
1842
+ if (hasNpmDeps || hasWinDeps || hasMacDeps) {
1843
+ throw new Error(constants.validationMessages.AUTO_IMPORT_CONFLICT_ERROR);
1844
+ }
1845
+ };
1846
+
1847
+ exports.readPackageJsonDevDependencies = (projectDir) => {
1848
+ const fs = require('fs');
1849
+ const path = require('path');
1850
+ const constants = require('./constants');
1851
+
1852
+ const packageJsonPath = path.join(projectDir, 'package.json');
1853
+
1854
+ try {
1855
+ const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
1856
+
1857
+ // Remove BOM if present
1858
+ const cleanedContent = packageJsonContent.replace(/^\ufeff/, '');
1859
+
1860
+ if (!cleanedContent.trim()) {
1861
+ throw new Error(constants.validationMessages.PACKAGE_JSON_MALFORMED);
1862
+ }
1863
+
1864
+ let packageJson;
1865
+ try {
1866
+ packageJson = JSON.parse(cleanedContent);
1867
+ } catch (parseError) {
1868
+ throw new Error(constants.validationMessages.PACKAGE_JSON_MALFORMED);
1869
+ }
1870
+
1871
+ if (typeof packageJson !== 'object' || packageJson === null || Array.isArray(packageJson)) {
1872
+ throw new Error(constants.validationMessages.PACKAGE_JSON_NOT_OBJECT);
1873
+ }
1874
+
1875
+ // Handle missing devDependencies field
1876
+ if (packageJson.devDependencies === undefined) {
1877
+ return {};
1878
+ }
1879
+
1880
+ // Validate devDependencies format
1881
+ if (typeof packageJson.devDependencies !== 'object' ||
1882
+ packageJson.devDependencies === null ||
1883
+ Array.isArray(packageJson.devDependencies)) {
1884
+ throw new Error(constants.validationMessages.DEVDEPS_INVALID_FORMAT);
1885
+ }
1886
+
1887
+ return packageJson.devDependencies;
1888
+
1889
+ } catch (error) {
1890
+ if (error.code === 'ENOENT') {
1891
+ throw new Error(constants.validationMessages.PACKAGE_JSON_NOT_FOUND);
1892
+ } else if (error.code === 'EACCES') {
1893
+ throw new Error(constants.validationMessages.PACKAGE_JSON_PERMISSION_DENIED);
1894
+ } else if (error.message.includes(constants.validationMessages.PACKAGE_JSON_MALFORMED) ||
1895
+ error.message.includes(constants.validationMessages.PACKAGE_JSON_NOT_OBJECT) ||
1896
+ error.message.includes(constants.validationMessages.DEVDEPS_INVALID_FORMAT)) {
1897
+ throw error;
1898
+ } else {
1899
+ throw new Error(`Cannot read package.json: ${error.message}`);
1900
+ }
1901
+ }
1902
+ };
1903
+
1904
+ exports.filterDependenciesWithRegex = (dependencies, excludePatterns) => {
1905
+ const constants = require('./constants');
1906
+
1907
+ // Validate dependencies parameter
1908
+ if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies)) {
1909
+ throw new Error(constants.validationMessages.DEPENDENCIES_PARAM_INVALID);
1910
+ }
1911
+
1912
+ // Return all dependencies if no exclusion patterns
1913
+ if (!excludePatterns) {
1914
+ return dependencies;
1915
+ }
1916
+
1917
+ // Validate excludePatterns parameter
1918
+ if (!Array.isArray(excludePatterns)) {
1919
+ throw new Error(constants.validationMessages.EXCLUDE_DEPS_INVALID_TYPE);
1920
+ }
1921
+
1922
+ // Validate all patterns are strings
1923
+ for (const pattern of excludePatterns) {
1924
+ if (typeof pattern !== 'string') {
1925
+ throw new Error(constants.validationMessages.EXCLUDE_DEPS_INVALID_PATTERNS);
1926
+ }
1927
+ }
1928
+
1929
+ // If no patterns, return all dependencies
1930
+ if (excludePatterns.length === 0) {
1931
+ return dependencies;
1932
+ }
1933
+
1934
+ const filteredDependencies = {};
1935
+
1936
+ for (const [packageName, version] of Object.entries(dependencies)) {
1937
+ let shouldExclude = false;
1938
+
1939
+ for (const pattern of excludePatterns) {
1940
+ // Skip empty patterns
1941
+ if (!pattern) {
1942
+ continue;
1943
+ }
1944
+
1945
+ try {
1946
+ const regex = new RegExp(pattern);
1947
+ if (regex.test(packageName)) {
1948
+ shouldExclude = true;
1949
+ break;
1950
+ }
1951
+ } catch (regexError) {
1952
+ const errorMsg = constants.validationMessages.INVALID_REGEX_PATTERN.replace('{pattern}', pattern);
1953
+ throw new Error(errorMsg);
1954
+ }
1955
+ }
1956
+
1957
+ if (!shouldExclude) {
1958
+ filteredDependencies[packageName] = version;
1959
+ }
1960
+ }
1961
+
1962
+ return filteredDependencies;
1963
+ };
1964
+
1965
+ exports.ensureBrowserstackCypressCliDependency = (npmDependencies) => {
1966
+ // Validate npmDependencies parameter
1967
+ if (npmDependencies === undefined || npmDependencies === null ||
1968
+ typeof npmDependencies !== 'object' || Array.isArray(npmDependencies)) {
1969
+ return;
1970
+ }
1971
+
1972
+ // Check if browserstack-cypress-cli already exists
1973
+ if ("browserstack-cypress-cli" in npmDependencies) {
1974
+ return;
1975
+ }
1976
+
1977
+ logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies");
1978
+
1979
+ // Get version from package.json (similar to getAgentVersion)
1980
+ let version = "latest";
1981
+ try {
1982
+ const packageJsonPath = path.join(__dirname, '../../package.json');
1983
+ if (fs.existsSync(packageJsonPath)) {
1984
+ version = require(packageJsonPath).version;
1985
+ }
1986
+ } catch (err) {
1987
+ logger.debug("Could not read package.json version, using 'latest'");
1988
+ }
1989
+
1990
+ npmDependencies['browserstack-cypress-cli'] = version;
1991
+ logger.warn(`Adding browserstack-cypress-cli version ${version} in npm_dependencies`);
1992
+ };
1993
+
1994
+ exports.processAutoImportDependencies = (runSettings) => {
1995
+ // Always run validation first
1996
+ exports.validateAutoImportConflict(runSettings);
1997
+
1998
+ // Skip processing if auto_import_dev_dependencies is not enabled
1999
+ if (!runSettings.auto_import_dev_dependencies) {
2000
+ return;
2001
+ }
2002
+
2003
+ // Determine project directory using battle-tested logic
2004
+ let projectDir;
2005
+ if (runSettings.home_directory) {
2006
+ projectDir = runSettings.home_directory;
2007
+ } else {
2008
+ const path = require('path');
2009
+ projectDir = path.dirname(runSettings.cypressConfigFilePath);
2010
+ }
2011
+
2012
+ // Read devDependencies from package.json
2013
+ const devDependencies = exports.readPackageJsonDevDependencies(projectDir);
2014
+
2015
+ // Apply exclusion filters
2016
+ const filteredDependencies = exports.filterDependenciesWithRegex(devDependencies, runSettings.exclude_dependencies);
2017
+
2018
+ // Set the npm_dependencies in runSettings
2019
+ runSettings.npm_dependencies = filteredDependencies;
2020
+
2021
+ // Ensure browserstack-cypress-cli dependency is present when auto import is enabled
2022
+ exports.ensureBrowserstackCypressCliDependency(runSettings.npm_dependencies);
2023
+ };
2024
+ exports.normalizeTestReportingEnvVars = () => {
2025
+ if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING)){
2026
+ process.env.BROWSERSTACK_TEST_OBSERVABILITY = process.env.BROWSERSTACK_TEST_REPORTING;
2027
+ }
2028
+
2029
+ if (!this.isUndefined(process.env.BROWSERSTACK_TEST_REPORTING_DEBUG)){
2030
+ process.env.BROWSERSTACK_OBSERVABILITY_DEBUG = process.env.BROWSERSTACK_TEST_REPORTING_DEBUG;
2031
+ }
2032
+ }
2033
+
2034
+ exports.normalizeTestReportingConfig = (bsConfig) => {
2035
+ if (!this.isUndefined(bsConfig["testReporting"])) {
2036
+ bsConfig["testObservability"] = bsConfig["testReporting"];
2037
+ }
2038
+
2039
+ if (!this.isUndefined(bsConfig["testReportingOptions"])) {
2040
+ bsConfig["testObservabilityOptions"] = bsConfig["testReportingOptions"];
2041
+ }
2042
+
2043
+ return bsConfig;
2044
+ }
@@ -59,6 +59,8 @@ module.exports = function () {
59
59
  "parallels": "Number of parallels you want to run",
60
60
  "npm_dependencies": {
61
61
  },
62
+ "auto_import_dev_dependencies": false,
63
+ "exclude_dependencies": [],
62
64
  "package_config_options": {
63
65
  },
64
66
  "headless": true
@@ -7,7 +7,7 @@ const HttpsProxyAgent = require('https-proxy-agent');
7
7
  const logger = require("../../helpers/logger").winstonLogger;
8
8
  const utils = require('../../helpers/utils');
9
9
 
10
- const { API_URL, consoleHolder } = require('../helper/constants');
10
+ const { API_URL, consoleHolder, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
11
11
 
12
12
  /* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
13
13
  const httpsKeepAliveAgent = new https.Agent({
@@ -19,7 +19,7 @@ const httpsKeepAliveAgent = new https.Agent({
19
19
 
20
20
  const debug = (text) => {
21
21
  if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
22
- logger.info(`[ OBSERVABILITY ] ${text}`);
22
+ logger.info(`[ ${TEST_REPORTING_ANALYTICS} ] ${text}`);
23
23
  }
24
24
  }
25
25