browserstack-cypress-cli 1.36.18 → 1.36.20

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.
@@ -212,7 +212,7 @@ module.exports = function run(args, rawArgs) {
212
212
  logger.debug("Completed setting the configs");
213
213
 
214
214
  if(!isBrowserstackInfra) {
215
- if(process.env.BS_TESTOPS_BUILD_COMPLETED) {
215
+ if(process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
216
216
  setEventListeners(bsConfig);
217
217
  }
218
218
 
@@ -226,7 +226,7 @@ module.exports = function run(args, rawArgs) {
226
226
  if(process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true') {
227
227
  setAccessibilityEventListeners(bsConfig);
228
228
  }
229
- if(process.env.BS_TESTOPS_BUILD_COMPLETED) {
229
+ if(process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
230
230
  setEventListeners(bsConfig);
231
231
  }
232
232
  markBlockEnd('validateConfig');
@@ -4,7 +4,8 @@ const { readCypressConfigFile } = require('./readCypressConfigUtil');
4
4
 
5
5
  const logger = require("./logger").winstonLogger,
6
6
  Constants = require("./constants"),
7
- Utils = require("./utils");
7
+ Utils = require("./utils"),
8
+ testhubUtils = require("../testhub/utils");
8
9
 
9
10
  const caps = (bsConfig, zip) => {
10
11
  return new Promise(function (resolve, reject) {
@@ -131,6 +132,18 @@ const caps = (bsConfig, zip) => {
131
132
  obj.run_settings = JSON.stringify(bsConfig.run_settings);
132
133
  }
133
134
 
135
+ // The only route by which a cypress session can name its TestHub build: every session
136
+ // this build spawns inherits these caps. Written unconditionally so an empty uuid records
137
+ // that build start ran and had nothing to name, which an absent key cannot express.
138
+ // "null" is the sentinel a failed build start leaves behind, not a uuid.
139
+ const testhubBuildUuid = process.env.BROWSERSTACK_TESTHUB_UUID;
140
+ obj.testhubBuildUuid = Utils.isUndefined(testhubBuildUuid) || testhubBuildUuid === "null"
141
+ ? ""
142
+ : testhubBuildUuid;
143
+ obj.buildProductMap = testhubUtils.getProductMap(bsConfig);
144
+
145
+ logger.debug(`TestHub build uuid stamped on caps: ${obj.testhubBuildUuid || "<empty>"}`);
146
+
134
147
  obj.cypress_cli_user_agent = Utils.getUserAgent();
135
148
 
136
149
  logger.info(`Cypress CLI User Agent: ${obj.cypress_cli_user_agent}`);
@@ -50,7 +50,8 @@ const shouldSkipCommand = (command) => {
50
50
  if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) {
51
51
  return true;
52
52
  }
53
- return command.attributes.name == 'log' || (command.attributes.name == 'task' && (['test_observability_platform_details', 'test_observability_step', 'test_observability_command', 'browserstack_log', 'test_observability_log'].some(event => command.attributes.args.includes(event))));
53
+ /* the batch task is filtered too, else each dispatch refills the queue */
54
+ return command.attributes.name == 'log' || (command.attributes.name == 'task' && (['test_observability_platform_details', 'test_observability_step', 'test_observability_command', 'test_observability_batch', 'browserstack_log', 'test_observability_log'].some(event => command.attributes.args.includes(event))));
54
55
  }
55
56
 
56
57
  Cypress.on('log:changed', (attrs) => {
@@ -339,6 +340,83 @@ Cypress.Commands.add('fatal', (message, file) => {
339
340
  });
340
341
  });
341
342
 
343
+ /* console.warn, not cy.task — a diagnostic must not use the mechanism it reports on */
344
+ const warnFlushFailure = (stage, err) => {
345
+ try {
346
+ console.warn(`BrowserStack Test Observability: suppressed ${stage} error, event(s) dropped: ${err && err.message ? err.message : err}`);
347
+ } catch (e) { /* logging must never throw either */ }
348
+ };
349
+
350
+ /*
351
+ * [SDK-7399] One cy.task per drain, not per event. Each round-trip costs ~0.8s on a
352
+ * remote terminal, so a command-heavy spec spent minutes in afterEach, exceeded
353
+ * spec_timeout and was killed — unrun tests then reported as skipped, with nothing
354
+ * thrown. 600 events: 581s as 600 calls, 109s as one.
355
+ * Stays on cy.task: cy.now('task') throws on Cypress 14, so it would "fix" this by
356
+ * delivering nothing. The try/catch is only a backstop for synchronous throws — a
357
+ * cy.task failure surfaces later, while the command queue drains.
358
+ */
359
+
360
+ /* Remote terminal: a single cy.task payload of 768KB succeeds, 1MB fails.
361
+ * Split well under that; drop only what cannot be sent at all. The two must stay
362
+ * distinct — an event between them still sends on its own. */
363
+ const MAX_BATCH_CHARS = 512 * 1024;
364
+ const MAX_EVENT_CHARS = 768 * 1024;
365
+
366
+ const flushEventsQueue = () => {
367
+ try {
368
+ const queued = eventsQueue;
369
+ eventsQueue = []; /* cleared before dispatch so a throw cannot replay these events */
370
+ if (queued.length === 0) return;
371
+
372
+ let batch = [];
373
+ let batchChars = 0;
374
+
375
+ const sendBatch = () => {
376
+ if (batch.length === 0) return;
377
+ const toSend = batch;
378
+ batch = [];
379
+ batchChars = 0;
380
+ try {
381
+ /* every push site uses { log: false }, so per-event options are not forwarded */
382
+ cy.task('test_observability_batch', toSend, { log: false });
383
+ } catch (e) {
384
+ warnFlushFailure(`batch dispatch of ${toSend.length} event(s)`, e);
385
+ }
386
+ };
387
+
388
+ queued.forEach(event => {
389
+ try {
390
+ const payload = sanitizeForTask(event.data);
391
+ if (payload === null) {
392
+ warnFlushFailure(`unserializable payload for '${event.task}'`,
393
+ new Error('event skipped'));
394
+ return;
395
+ }
396
+ const size = JSON.stringify(payload).length;
397
+ if (size > MAX_EVENT_CHARS) {
398
+ /* past the largest size measured to send; 768KB-1MB is untested, so skip */
399
+ warnFlushFailure(`event too large to send for '${event.task}' (${size} chars)`,
400
+ new Error('event skipped'));
401
+ return;
402
+ }
403
+ /* oversized-but-sendable: let it travel alone */
404
+ if (batch.length > 0 && batchChars + size > MAX_BATCH_CHARS) sendBatch();
405
+ batch.push({ task: event.task, data: payload });
406
+ batchChars += size;
407
+ if (batchChars >= MAX_BATCH_CHARS) sendBatch();
408
+ } catch (e) {
409
+ warnFlushFailure(`preparing '${event.task}'`, e); /* skip one event, not the rest */
410
+ }
411
+ });
412
+
413
+ sendBatch();
414
+ } catch (e) {
415
+ warnFlushFailure('queue flush', e);
416
+ eventsQueue = [];
417
+ }
418
+ };
419
+
342
420
  beforeEach(() => {
343
421
  /* browserstack internal helper hook */
344
422
 
@@ -346,13 +424,7 @@ beforeEach(() => {
346
424
  return;
347
425
  }
348
426
 
349
- if (eventsQueue.length > 0) {
350
- eventsQueue.forEach(event => {
351
- const payload = sanitizeForTask(event.data);
352
- if (payload !== null) cy.task(event.task, payload, event.options);
353
- });
354
- }
355
- eventsQueue = [];
427
+ flushEventsQueue();
356
428
  testRunStarted = true;
357
429
  });
358
430
 
@@ -362,13 +434,6 @@ afterEach(function() {
362
434
  return;
363
435
  }
364
436
 
365
- if (eventsQueue.length > 0) {
366
- eventsQueue.forEach(event => {
367
- const payload = sanitizeForTask(event.data);
368
- if (payload !== null) cy.task(event.task, payload, event.options);
369
- });
370
- }
371
-
372
- eventsQueue = [];
437
+ flushEventsQueue();
373
438
  testRunStarted = false;
374
439
  });
@@ -11,6 +11,13 @@ const browserstackTestObservabilityPlugin = (on, config, callbacks) => {
11
11
 
12
12
  connectIPCClient(config);
13
13
 
14
+ const IPC_EVENT_FOR_TASK = {
15
+ test_observability_log: IPC_EVENTS.LOG,
16
+ test_observability_command: IPC_EVENTS.COMMAND,
17
+ test_observability_platform_details: IPC_EVENTS.PLATFORM_DETAILS,
18
+ test_observability_step: IPC_EVENTS.CUCUMBER,
19
+ };
20
+
14
21
  on('task', {
15
22
  test_observability_log(log) {
16
23
  ipc.of.browserstackTestObservability.emit(IPC_EVENTS.LOG, log);
@@ -27,6 +34,21 @@ const browserstackTestObservabilityPlugin = (on, config, callbacks) => {
27
34
  test_observability_step(log) {
28
35
  ipc.of.browserstackTestObservability.emit(IPC_EVENTS.CUCUMBER, log);
29
36
  return null;
37
+ },
38
+ /* [SDK-7399] One task per flush instead of one per event — see cypress/index.js.
39
+ * Fans out to the same IPC events; the per-event tasks stay for back-compat. */
40
+ test_observability_batch(events) {
41
+ if (!Array.isArray(events)) return null;
42
+ events.forEach((event) => {
43
+ try {
44
+ const ipcEvent = event && IPC_EVENT_FOR_TASK[event.task];
45
+ if (!ipcEvent) return;
46
+ ipc.of.browserstackTestObservability.emit(ipcEvent, event.data);
47
+ } catch (e) {
48
+ /* one bad entry must not drop the rest */
49
+ }
50
+ });
51
+ return null;
30
52
  }
31
53
  });
32
54
 
@@ -41,9 +41,9 @@ class TestHubHandler {
41
41
  const response = await nodeRequest( "POST", TESTHUB_CONSTANTS.TESTHUB_BUILD_API, data, config);
42
42
  const launchData = this.extractDataFromResponse(user_config, data, response, config);
43
43
  } catch (error) {
44
- console.log(error);
44
+ logger.debug(`EXCEPTION IN BUILD START EVENT : ${error}`);
45
+ testhubUtils.handleErrorForObservability(error.success === false ? error : null);
45
46
  if (error.success === false) { // non 200 response
46
- testhubUtils.logBuildError(error);
47
47
  return;
48
48
  }
49
49
 
@@ -88,6 +88,10 @@ exports.setTestObservabilityVariables = (
88
88
  };
89
89
 
90
90
  exports.handleErrorForObservability = (error = null) => {
91
+ // Downstream reads isTestObservabilitySession(), not these ids, to decide whether
92
+ // observability is live. extractDataFromResponse clears it inline for a 2xx carrying
93
+ // success=false; this covers the paths that never get a usable response at all.
94
+ process.env.BROWSERSTACK_TEST_OBSERVABILITY = "false";
91
95
  process.env.BROWSERSTACK_TESTHUB_UUID = "null";
92
96
  process.env.BROWSERSTACK_TESTHUB_JWT = "null";
93
97
  process.env.BS_TESTOPS_BUILD_COMPLETED = "false";
@@ -164,7 +168,7 @@ exports.handleErrorForAccessibility = (user_config, error = null) => {
164
168
  };
165
169
 
166
170
  exports.logBuildError = (error, product = "") => {
167
- if (error === undefined) {
171
+ if (isUndefined(error)) {
168
172
  logger.error(`${product.toUpperCase()} Build creation failed`);
169
173
 
170
174
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.36.18",
3
+ "version": "1.36.20",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {