browserstack-cypress-cli 1.36.8 → 1.36.10

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.
@@ -364,6 +364,15 @@ module.exports = function run(args, rawArgs) {
364
364
  // stop the Local instance
365
365
  if (!turboScaleSession) await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData);
366
366
 
367
+ // SDK-6211: send the Test Observability build-stop now — polling has resolved, so
368
+ // the build has finished running on BrowserStack. builds_th.finished_at is stamped
369
+ // server-side when the collector receives this stop event, so firing it here (before
370
+ // the 5s safety wait, artifact download and HTML report generation below) keeps the
371
+ // TRA build "Duration" aligned with the test window instead of the full CLI wall-clock.
372
+ // printBuildLink no-ops on non-observability runs and is idempotent (buildStopped
373
+ // guard); the later handleSyncExit stop becomes a no-op that still honors the exit code.
374
+ await printBuildLink(true);
375
+
367
376
  // waiting for 5 secs for upload to complete (as a safety measure)
368
377
  await new Promise(resolve => setTimeout(resolve, 5000));
369
378
 
@@ -274,7 +274,7 @@ exports.getCiInfo = () => {
274
274
  name: "GitHub Actions",
275
275
  build_url: `${env.GITHUB_SERVER_URL || 'https://github.com'}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}`,
276
276
  job_name: env.GITHUB_WORKFLOW || env.GITHUB_JOB,
277
- build_number: env.GITHUB_RUN_NUMBER
277
+ build_number: env.GITHUB_RUN_ID
278
278
  };
279
279
  }
280
280
  // Buildkite
@@ -6,6 +6,40 @@ const STEP_KEYWORDS = ['given', 'when', 'then', 'and', 'but', '*'];
6
6
  let eventsQueue = [];
7
7
  let testRunStarted = false;
8
8
 
9
+ /*
10
+ * Command args (command.attributes.args) and cy.log items are captured raw and can hold
11
+ * circular Cypress runtime objects (e.g. a config-like object whose `renderOptions.host`
12
+ * points back to itself). cy.task() JSON-serializes its payload to ship it from the browser
13
+ * to the Node plugin process, so a circular arg makes Cypress throw
14
+ * "Converting circular structure to JSON" and aborts the run. Decycle the payload before
15
+ * handing it to cy.task so o11y instrumentation can never break the customer's tests. [SDK-6016]
16
+ */
17
+ const getCircularReplacer = () => {
18
+ const seen = new WeakSet();
19
+ return (key, value) => {
20
+ if (typeof value === 'object' && value !== null) {
21
+ if (seen.has(value)) return '[Circular]';
22
+ seen.add(value);
23
+ }
24
+ return value;
25
+ };
26
+ };
27
+
28
+ /*
29
+ * Returns a decycled, JSON-safe plain object, or `null` if the payload still cannot be
30
+ * serialized for a non-circular reason (BigInt, a throwing toJSON, a Proxy trap, etc.).
31
+ * `null` is a "skip this event" sentinel — callers must NOT forward it to cy.task, because
32
+ * the Node o11y handler expects a structured event payload, not an error stub. Skipping keeps
33
+ * graceful degradation total: no crash, and no malformed event reaches the collector.
34
+ */
35
+ const sanitizeForTask = (data) => {
36
+ try {
37
+ return JSON.parse(JSON.stringify(data, getCircularReplacer()));
38
+ } catch (e) {
39
+ return null;
40
+ }
41
+ };
42
+
9
43
  const browserStackLog = (message) => {
10
44
 
11
45
  if (!Cypress.env('BROWSERSTACK_LOGS')) return;
@@ -208,7 +242,12 @@ Cypress.on('command:enqueued', (attrs) => {
208
242
  if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
209
243
  const message = args.reduce((result, logItem) => {
210
244
  if (typeof logItem === 'object') {
211
- return [result, JSON.stringify(logItem)].join(' ');
245
+ /* Route through sanitizeForTask so a non-circular serialization failure can never
246
+ * throw out of the command:enqueued handler (same graceful-degradation contract as
247
+ * the flush sites). sanitizeForTask returns a decycled plain object (safe to stringify)
248
+ * or null; on null, contribute nothing for this item rather than crash. */
249
+ const safeLog = sanitizeForTask(logItem);
250
+ return [result, safeLog === null ? '' : JSON.stringify(safeLog)].join(' ');
212
251
  }
213
252
  return [result, logItem ? logItem.toString() : ''].join(' ');
214
253
  }, '');
@@ -309,7 +348,8 @@ beforeEach(() => {
309
348
 
310
349
  if (eventsQueue.length > 0) {
311
350
  eventsQueue.forEach(event => {
312
- cy.task(event.task, event.data, event.options);
351
+ const payload = sanitizeForTask(event.data);
352
+ if (payload !== null) cy.task(event.task, payload, event.options);
313
353
  });
314
354
  }
315
355
  eventsQueue = [];
@@ -324,7 +364,8 @@ afterEach(function() {
324
364
 
325
365
  if (eventsQueue.length > 0) {
326
366
  eventsQueue.forEach(event => {
327
- cy.task(event.task, event.data, event.options);
367
+ const payload = sanitizeForTask(event.data);
368
+ if (payload !== null) cy.task(event.task, payload, event.options);
328
369
  });
329
370
  }
330
371
 
@@ -93,7 +93,16 @@ const supportFileCleanup = () => {
93
93
  exports.buildStopped = false;
94
94
 
95
95
  exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
96
- if(!this.isTestObservabilitySession() || exports.buildStopped) return;
96
+ if(!this.isTestObservabilitySession()) return;
97
+ // SDK-6211: the build-stop may be sent early (runs.js fires it at poll-resolution, before the
98
+ // post-test 5s wait + artifact download + report generation, so builds_th.finished_at — which
99
+ // the collector stamps at stop-event receipt — reflects the test window rather than the full CLI
100
+ // wall-clock). A later call here must therefore still honor the exit code instead of returning
101
+ // silently, preserving the original failing-build exit behaviour.
102
+ if(exports.buildStopped) {
103
+ if(exitCode) process.exit(exitCode);
104
+ return;
105
+ }
97
106
  exports.buildStopped = true;
98
107
  try {
99
108
  if(shouldStopSession) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.36.8",
3
+ "version": "1.36.10",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {