browserstack-cypress-cli 1.28.0 → 1.28.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.
@@ -191,7 +191,9 @@ const getAccessibilityCypressCommandEventListener = () => {
191
191
  const setAccessibilityEventListeners = () => {
192
192
  try {
193
193
  const cypressCommandEventListener = getAccessibilityCypressCommandEventListener();
194
- glob(process.cwd() + '/cypress/support/*.js', {}, (err, files) => {
194
+
195
+ // Searching form command.js recursively
196
+ glob(process.cwd() + '/**/cypress/support/*.js', {}, (err, files) => {
195
197
  if(err) return logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
196
198
  files.forEach(file => {
197
199
  try {
@@ -267,16 +267,26 @@ exports.getCiInfo = () => {
267
267
  return null;
268
268
  }
269
269
 
270
- exports.getBuildDetails = (bsConfig) => {
270
+ exports.getBuildDetails = (bsConfig, isO11y = false) => {
271
+ const isTestObservabilityOptionsPresent = isO11y && !utils.isUndefined(bsConfig["testObservabilityOptions"]);
272
+
271
273
  let buildName = '',
272
274
  projectName = '',
273
275
  buildDescription = '',
274
276
  buildTags = [];
275
-
277
+
276
278
  /* Pick from environment variables */
277
279
  buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName;
278
280
  projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName;
279
-
281
+
282
+ /* Pick from testObservabilityOptions */
283
+ if(isTestObservabilityOptionsPresent) {
284
+ buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"];
285
+ projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"];
286
+ if(!utils.isUndefined(bsConfig["testObservabilityOptions"]["buildTag"])) buildTags = [...buildTags, ...bsConfig["testObservabilityOptions"]["buildTag"]];
287
+ buildDescription = buildDescription || bsConfig["testObservabilityOptions"]["buildDescription"];
288
+ }
289
+
280
290
  /* Pick from run settings */
281
291
  buildName = buildName || bsConfig["run_settings"]["build_name"];
282
292
  projectName = projectName || bsConfig["run_settings"]["project_name"];
@@ -1,3 +1,5 @@
1
+ const path = require('path');
2
+
1
3
  exports.consoleHolder = Object.assign({},console);
2
4
  exports.BATCH_SIZE = 1000;
3
5
  exports.BATCH_INTERVAL = 2000;
@@ -28,3 +30,5 @@ exports.OBSERVABILITY_ENV_VARS = [
28
30
  ];
29
31
 
30
32
  exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';
33
+
34
+ exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
@@ -25,7 +25,15 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
25
25
  const { name, version } = require('../../../package.json');
26
26
 
27
27
  const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../../helpers/constants');
28
- const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER } = require('./constants');
28
+ const { consoleHolder, API_URL, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL } = require('./constants');
29
+
30
+ const ALLOWED_MODULES = [
31
+ 'cypress/package.json',
32
+ 'mocha/lib/reporters/base.js',
33
+ 'mocha/lib/utils.js',
34
+ 'mocha'
35
+ ];
36
+
29
37
  exports.pending_test_uploads = {
30
38
  count: 0
31
39
  };
@@ -331,7 +339,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
331
339
  projectName,
332
340
  buildDescription,
333
341
  buildTags
334
- } = helper.getBuildDetails(user_config);
342
+ } = helper.getBuildDetails(user_config, true);
335
343
  const data = {
336
344
  'format': 'json',
337
345
  'project_name': projectName,
@@ -715,32 +723,85 @@ exports.getOSDetailsFromSystem = async (product) => {
715
723
  };
716
724
  }
717
725
 
718
- exports.requireModule = (module, internal = false) => {
719
- logger.debug(`Getting ${module} from ${process.cwd()}`);
720
- let local_path = "";
721
- if(process.env["browserStackCwd"]){
722
- local_path = path.join(process.env["browserStackCwd"], 'node_modules', module);
723
- } else if(internal) {
724
- local_path = path.join(process.cwd(), 'node_modules', 'browserstack-cypress-cli', 'node_modules', module);
725
- } else {
726
- local_path = path.join(process.cwd(), 'node_modules', module);
727
- }
728
- if(!fs.existsSync(local_path)) {
729
- logger.debug(`${module} doesn\'t exist at ${process.cwd()}`);
730
- logger.debug(`Getting ${module} from ${GLOBAL_MODULE_PATH}`);
731
-
732
- let global_path;
733
- if(['jest-runner', 'jest-runtime'].includes(module))
734
- global_path = path.join(GLOBAL_MODULE_PATH, 'jest', 'node_modules', module);
735
- else
736
- global_path = path.join(GLOBAL_MODULE_PATH, module);
737
- if(!fs.existsSync(global_path)) {
738
- throw new Error(`${module} doesn't exist.`);
726
+ let WORKSPACE_MODULE_PATH;
727
+
728
+ exports.requireModule = (module) => {
729
+ const modulePath = exports.resolveModule(module);
730
+ if (modulePath.error) {
731
+ throw new Error(`${module} doesn't exist.`);
732
+ }
733
+
734
+ return require(modulePath.path);
735
+ };
736
+
737
+ exports.resolveModule = (module) => {
738
+ if (!ALLOWED_MODULES.includes(module)) {
739
+ throw new Error('Invalid module name');
740
+ }
741
+
742
+ if (WORKSPACE_MODULE_PATH == undefined) {
743
+ try {
744
+ WORKSPACE_MODULE_PATH = execSync('npm ls').toString().trim();
745
+ WORKSPACE_MODULE_PATH = WORKSPACE_MODULE_PATH.split('\n')[0].split(' ')[1];
746
+ } catch (e) {
747
+ WORKSPACE_MODULE_PATH = null;
748
+ exports.debug(`Could not locate npm module path with error ${e}`);
739
749
  }
740
- return require(global_path);
741
750
  }
742
- return require(local_path);
743
- }
751
+
752
+ /*
753
+ Modules will be resolved in the following order,
754
+ current working dir > workspaces dir > NODE_PATH env var > global node modules path
755
+ */
756
+
757
+ try {
758
+ exports.debug('requireModuleV2');
759
+
760
+ return {path: require.resolve(module), foundAt: 'resolve'};
761
+ } catch (_) {
762
+ /* Find from current working directory */
763
+ exports.debug(`Getting ${module} from ${process.cwd()}`);
764
+ let local_path = path.join(process.cwd(), 'node_modules', module);
765
+ if (!fs.existsSync(local_path)) {
766
+ exports.debug(`${module} doesn't exist at ${process.cwd()}`);
767
+
768
+ /* Find from workspaces */
769
+ if (WORKSPACE_MODULE_PATH) {
770
+ exports.debug(`Getting ${module} from path ${WORKSPACE_MODULE_PATH}`);
771
+ let workspace_path = null;
772
+ workspace_path = path.join(WORKSPACE_MODULE_PATH, 'node_modules', module);
773
+ if (workspace_path && fs.existsSync(workspace_path)) {
774
+ exports.debug(`Found ${module} from ${WORKSPACE_MODULE_PATH}`);
775
+
776
+ return {path: workspace_path, foundAt: 'workspaces'};
777
+ }
778
+ }
779
+
780
+ /* Find from node path */
781
+ let node_path = null;
782
+ if (!exports.isUndefined(process.env.NODE_PATH)) {
783
+ node_path = path.join(process.env.NODE_PATH, module);
784
+ }
785
+ if (node_path && fs.existsSync(node_path)) {
786
+ exports.debug(`Getting ${module} from ${process.env.NODE_PATH}`);
787
+
788
+ return {path: node_path, foundAt: 'nodePath'};
789
+ }
790
+
791
+ /* Find from global node modules path */
792
+ exports.debug(`Getting ${module} from ${GLOBAL_MODULE_PATH}`);
793
+
794
+ let global_path = path.join(GLOBAL_MODULE_PATH, module);
795
+ if (!global_path || !fs.existsSync(global_path)) {
796
+ return {error: 'module_not_found'};
797
+ }
798
+
799
+ return {path: global_path, foundAt: 'local'};
800
+ }
801
+
802
+ return {path: local_path, foundAt: 'global'};
803
+ }
804
+ };
744
805
 
745
806
  const getReRunSpecs = (rawArgs) => {
746
807
  if (this.isTestObservabilitySession() && this.shouldReRunObservabilityTests()) {
@@ -763,7 +824,7 @@ const getReRunSpecs = (rawArgs) => {
763
824
 
764
825
  const getLocalSessionReporter = () => {
765
826
  if(this.isTestObservabilitySession() && process.env.BS_TESTOPS_JWT) {
766
- return ['--reporter', TEST_OBSERVABILITY_REPORTER];
827
+ return ['--reporter', TEST_OBSERVABILITY_REPORTER_LOCAL];
767
828
  } else {
768
829
  return [];
769
830
  }
@@ -156,14 +156,14 @@ class MyReporter {
156
156
  })
157
157
 
158
158
  .on(EVENT_TEST_BEGIN, async (test) => {
159
- if (test.isSkipped) return;
159
+ if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
160
160
  if(this.testObservability == true) {
161
161
  await this.testStarted(test);
162
162
  }
163
163
  })
164
164
 
165
165
  .on(EVENT_TEST_END, async (test) => {
166
- if (test.isSkipped) return;
166
+ if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
167
167
  if(this.testObservability == true) {
168
168
  if(!this.runStatusMarkedHash[test.testAnalyticsId]) {
169
169
  if(test.testAnalyticsId) this.runStatusMarkedHash[test.testAnalyticsId] = true;
@@ -448,7 +448,7 @@ class MyReporter {
448
448
  }
449
449
 
450
450
  // Send pending hook finsihed events for hook starts
451
- if (eventType === 'TestRunFinished') {
451
+ if (eventType === 'TestRunFinished' || eventType === 'TestRunSkipped') {
452
452
  Object.values(this.hooksStarted).forEach(async hookData => {
453
453
  hookData['event_type'] = 'HookRunFinished';
454
454
  hookData['hook_run'] = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.28.0",
3
+ "version": "1.28.1",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {