browserstack-cypress-cli 1.36.18 → 1.36.19

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.
@@ -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
 
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.19",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {