browserstack-cypress-cli 1.36.15 → 1.36.17

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.
@@ -378,32 +378,35 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
378
378
  }
379
379
 
380
380
  const globPattern = process.cwd() + supportFilesData.supportFile;
381
- glob(globPattern, {}, (err, files) => {
382
- if(err) {
383
- logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
384
- return;
385
- }
386
-
387
- files.forEach(file => {
388
- try {
389
- const fileName = path.basename(file);
390
- if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) {
391
-
392
- const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
393
- let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
394
- if(!defaultFileContent.includes(cypressCommandEventListener)) {
395
- let newFileContent = defaultFileContent +
396
- '\n' +
397
- cypressCommandEventListener +
398
- '\n';
399
- fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
400
- supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
401
- }
381
+ // Synchronous for the same reason as testObservability setEventListeners
382
+ // (SDK-7121): the caller archives the suite right after this returns, so an
383
+ // async glob callback would race the archive and ship un-instrumented specs.
384
+ let files;
385
+ try {
386
+ files = glob.sync(globPattern, {});
387
+ } catch(err) {
388
+ logger.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files', true, err);
389
+ return;
390
+ }
391
+ files.forEach(file => {
392
+ try {
393
+ const fileName = path.basename(file);
394
+ if(['e2e.js', 'e2e.ts', 'component.ts', 'component.js'].includes(fileName) && !file.includes('node_modules')) {
395
+
396
+ const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
397
+ let cypressCommandEventListener = getAccessibilityCypressCommandEventListener(path.extname(file));
398
+ if(!defaultFileContent.includes(cypressCommandEventListener)) {
399
+ let newFileContent = defaultFileContent +
400
+ '\n' +
401
+ cypressCommandEventListener +
402
+ '\n';
403
+ fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
404
+ supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
402
405
  }
403
- } catch(e) {
404
- logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
405
406
  }
406
- });
407
+ } catch(e) {
408
+ logger.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
409
+ }
407
410
  });
408
411
  } catch(e) {
409
412
  logger.debug(`Unable to parse support files to set event listeners with error ${e}`, true, e);
@@ -495,7 +495,10 @@ exports.setNodeVersion = (bsConfig, args) => {
495
495
  // command line args takes precedence over config
496
496
  exports.setUserSpecs = (bsConfig, args) => {
497
497
  if(o11yHelpers.isBrowserstackInfra() && o11yHelpers.isTestObservabilitySession() && o11yHelpers.shouldReRunObservabilityTests()) {
498
- bsConfig.run_settings.specs = process.env.BROWSERSTACK_RERUN_TESTS;
498
+ // BROWSERSTACK_RERUN_TESTS arrives comma+space separated (e.g. "a.ts, b.ts"); normalise
499
+ // like the other spec sources below, else sanitizeSpecsPattern builds "{a.ts, b.ts}" whose
500
+ // space-prefixed brace alternatives never match and the failed-spec filter collapses.
501
+ bsConfig.run_settings.specs = this.fixCommaSeparatedString(process.env.BROWSERSTACK_RERUN_TESTS);
499
502
  return;
500
503
  }
501
504
 
@@ -301,27 +301,29 @@ exports.setEventListeners = (bsConfig) => {
301
301
  try {
302
302
  const supportFilesData = helper.getSupportFiles(bsConfig, false);
303
303
  if(!supportFilesData.supportFile) return;
304
- glob(process.cwd() + supportFilesData.supportFile, {}, (err, files) => {
305
- if(err) return exports.debug('EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files');
306
- files.forEach(file => {
307
- try {
308
- if (isE2ESupportFile(file) || !files.some(f => isE2ESupportFile(f))) {
309
- const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
310
-
311
- let cypressCommandEventListener = getCypressCommandEventListener(file.includes('js'));
312
- if(!defaultFileContent.includes(cypressCommandEventListener)) {
313
- let newFileContent = defaultFileContent +
314
- '\n' +
315
- cypressCommandEventListener +
316
- '\n'
317
- fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
318
- supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
319
- }
304
+ // Must be synchronous: runs.js proceeds to md5 hashing and zip archiving
305
+ // immediately after this returns. An async glob callback races the archive
306
+ // (SDK-7121) — a lost race ships an un-instrumented suite, and md5 caching
307
+ // makes it sticky, so TRA receives no test events.
308
+ const files = glob.sync(process.cwd() + supportFilesData.supportFile, {});
309
+ files.forEach(file => {
310
+ try {
311
+ if (isE2ESupportFile(file) || !files.some(f => isE2ESupportFile(f))) {
312
+ const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
313
+
314
+ let cypressCommandEventListener = getCypressCommandEventListener(file.includes('js'));
315
+ if(!defaultFileContent.includes(cypressCommandEventListener)) {
316
+ let newFileContent = defaultFileContent +
317
+ '\n' +
318
+ cypressCommandEventListener +
319
+ '\n'
320
+ fs.writeFileSync(file, newFileContent, {encoding: 'utf-8'});
321
+ supportFileContentMap[file] = supportFilesData.cleanupParams ? supportFilesData.cleanupParams : defaultFileContent;
320
322
  }
321
- } catch(e) {
322
- exports.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
323
323
  }
324
- });
324
+ } catch(e) {
325
+ exports.debug(`Unable to modify file contents for ${file} to set event listeners with error ${e}`, true, e);
326
+ }
325
327
  });
326
328
  } catch(e) {
327
329
  exports.debug(`Unable to parse support files to set event listeners with error ${e}`, true, e);
@@ -879,7 +881,10 @@ const getReRunSpecs = (rawArgs) => {
879
881
  }
880
882
  }
881
883
  if(startIdx != -1) rawArgs.splice(startIdx, numEle + 1);
882
- finalArgs = [...rawArgs, '--spec', process.env.BROWSERSTACK_RERUN_TESTS];
884
+ // Normalise the comma+space separated rerun list ("a.ts, b.ts") to comma-only before
885
+ // handing it to cypress --spec; a leading space makes cypress miss every spec but the first.
886
+ const reRunSpecs = process.env.BROWSERSTACK_RERUN_TESTS.split(",").map(spec => spec.trim()).filter(Boolean).join(",");
887
+ finalArgs = [...rawArgs, '--spec', reRunSpecs];
883
888
  }
884
889
  return finalArgs.filter(item => item !== '--disable-test-observability' && item !== '--disable-browserstack-automation');
885
890
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.36.15",
3
+ "version": "1.36.17",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {