browserstack-cypress-cli 1.36.17 → 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.
package/bin/helpers/utils.js
CHANGED
|
@@ -491,10 +491,20 @@ exports.setNodeVersion = (bsConfig, args) => {
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
// specs can be passed from bstack configuration file
|
|
494
|
+
// True when the spec list for this run comes from BROWSERSTACK_RERUN_TESTS rather than
|
|
495
|
+
// the user's config/CLI args. Shared by setUserSpecs and getNumberOfSpecFiles so the two
|
|
496
|
+
// cannot drift apart — getNumberOfSpecFiles rewrites specs only for runs setUserSpecs
|
|
497
|
+
// actually sourced from the re-run env.
|
|
498
|
+
exports.isReRunSpecsSession = () => {
|
|
499
|
+
return o11yHelpers.isBrowserstackInfra()
|
|
500
|
+
&& o11yHelpers.isTestObservabilitySession()
|
|
501
|
+
&& o11yHelpers.shouldReRunObservabilityTests();
|
|
502
|
+
}
|
|
503
|
+
|
|
494
504
|
// specs can be passed via command line args as a string
|
|
495
505
|
// command line args takes precedence over config
|
|
496
506
|
exports.setUserSpecs = (bsConfig, args) => {
|
|
497
|
-
if(
|
|
507
|
+
if(this.isReRunSpecsSession()) {
|
|
498
508
|
// BROWSERSTACK_RERUN_TESTS arrives comma+space separated (e.g. "a.ts, b.ts"); normalise
|
|
499
509
|
// like the other spec sources below, else sanitizeSpecsPattern builds "{a.ts, b.ts}" whose
|
|
500
510
|
// space-prefixed brace alternatives never match and the failed-spec filter collapses.
|
|
@@ -1232,6 +1242,16 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig, turboScaleSession
|
|
|
1232
1242
|
files = files.map((x) => { return x.replaceAll("\\", "/") })
|
|
1233
1243
|
// setting specs for turboScale as we don't have patched API for turboscale so we will rely on info from CLI
|
|
1234
1244
|
bsConfig.run_settings.specs = files;
|
|
1245
|
+
} else if (this.isReRunSpecsSession() && files.length) {
|
|
1246
|
+
// BROWSERSTACK_RERUN_TESTS arrives as bare filenames ("a.ts,b.ts"). run_settings is
|
|
1247
|
+
// forwarded to the remote machines verbatim, and a bare filename does not resolve
|
|
1248
|
+
// against the project root there, so Cypress exits having run no spec at all. The
|
|
1249
|
+
// glob above already resolved them against cypressProjectDir — persist those
|
|
1250
|
+
// project-relative paths so the remote receives something it can resolve.
|
|
1251
|
+
bsConfig.run_settings.specs = files
|
|
1252
|
+
.map((file) => path.relative(bsConfig.run_settings.cypressProjectDir, file).replaceAll("\\", "/"))
|
|
1253
|
+
.join(",");
|
|
1254
|
+
logger.debug(`Re-run specs resolved to project-relative paths: ${bsConfig.run_settings.specs}`);
|
|
1235
1255
|
}
|
|
1236
1256
|
return files;
|
|
1237
1257
|
} catch (err) {
|
|
@@ -50,7 +50,8 @@ const shouldSkipCommand = (command) => {
|
|
|
50
50
|
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) {
|
|
51
51
|
return true;
|
|
52
52
|
}
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|