Repository navigation
👷 [RUM-19777] Run BrowserStack unit tests with Vitest (webdriverio provider) - #5136
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🔁 Datadog re-ran 🎯 Code Coverage (details) 🔗 Commit SHA: d0beb4b | Docs | View more details | Give us feedback! |
8d63fc5 to
8ad2817
Compare
8ad2817 to
80c77b4
Compare
80c77b4 to
840afce
Compare
728322c to
4c500f2
Compare
bafed24 to
aac904a
Compare
aac904a to
3b57986
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
The default full-matrix run applies Safari’s hostname to Chromium too, causing secure-cookie tests to fail on Android Chrome 145+. Individually selected Chromium runs retain localhost and avoid this defect.
🤖 Bits Code Review · Commit 3b57986
3b57986 to
733adf8
Compare
There was a problem hiding this comment.
Running the documented full BrowserStack matrix without BS_BROWSER applies Safari’s insecure hostname to every browser, suppressing CookieStore coverage and breaking secure-cookie assertions on Android Chrome 145+.
🤖 Bits Code Review · Commit 733adf8
Spike: check whether Vitest Browser Mode can cover our full BrowserStack matrix (Chrome 80, Edge 80, Firefox 78, Safari 14, Android Chrome), which the playwright provider can't. - vite.bs.config.ts: webdriverio provider against hub.browserstack.com, with a WebDriver keepalive (Vitest uses its own WebSocket, so BrowserStack otherwise kills the session as idle) - downlevel dependencies and Vitest's static client assets to ES2020 - polyfills (Object.hasOwn, BroadcastChannel, ...) for orchestrator and tester pages - serve from bs-local.com so Safari can reach the server - report page errors to the terminal (Safari exposes no console logs) - webdriverio 9 -> 10 (v9's bundled undici 6 breaks on Node 26) browser-core results: all 72 files pass on Chrome 80, Edge 80, Safari 14 and Android Chrome; Firefox 78 passes 71/72 (trackRuntimeError.spec.ts triggers an iframe reload when run as a whole).
Point `yarn test:unit:bs` (CI `unit-bs` matrix) at the webdriverio BrowserStack config, to see where the approach stands on the full suite. - verbose reporter, so the BrowserStack wrapper doesn't kill silent runs, and a per-browser junit file in test-report/unit-bs - no coverage on BrowserStack - same exclusions as karma.bs.conf.js (developer extension everywhere, Angular on Chrome/Edge 80 and Firefox 78) Files stay isolated (one iframe per file): running without isolation currently fails 151 tests (state leaking across files, shim gaps).
BrowserStack served Chrome 80 through Selenium 2.53 (JSON Wire protocol), which rejects the `POST /window/rect` Vitest sends before each test file. Also make a failed viewport resize non-fatal.
- trackRuntimeError.spec: `stop()` resolved to `window.stop()`, which made Firefox 78 reload the Vitest test iframe. Unsubscribe from the observable instead. - polyfill AggregateError (Firefox < 79), used by Vitest to report errors - only serve from bs-local.com on Safari: other browsers need `localhost` (a secure context) for `secure` cookies (cookieAccess.spec on Android)
The observable moved to js-core in #5022.
The error reporter sent its reports with the page's `XMLHttpRequest`, which specs instrument (ex: `xhrObservable`). Reporting the errors `trackRuntimeError.spec.ts` throws on purpose therefore added `loadend` listeners through the SDK instrumentation, that the leak detection reported as leaked once the spec ended, failing the tests on every BrowserStack browser (and reporting its own errors in a loop). Save `open` and `send` when the reporter loads, before any spec runs, and use them instead. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
`forEach.ts` restores the page URL after each test, so going back to the original pathname in `datadogProfiler.spec.ts`'s `afterEach` is redundant. It also always changed the URL (dropping Vitest's query string), making `forEach.ts` restore it again: about 80 history changes for this spec, close to Safari's limit of 100 per 30 seconds, which made Safari on BrowserStack fail with "Attempt to use history.pushState() more than 100 times per 30 seconds" depending on the test order. This spec now makes 6. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
Some BrowserStack runs fail with "The iframe was reloaded during a test" (5 times on Chrome Android, Edge and Safari over the last 2 days, in different specs), and the logs don't tell what reloads the page: no Vite reload is logged and no spec navigates. Make the error reporter also report, for each page load, the navigation type (`reload`, `navigate` or `back_forward`), `document.wasDiscarded` and the full URL, and the `beforeunload`, `pagehide`, `freeze` and `visibilitychange` events fired by the browser (events dispatched by specs are ignored). Events fired while the page unloads are sent with `sendBeacon`, saved before the tests run. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
The page lifecycle report showed that, when a BrowserStack run fails with "The iframe was reloaded during a test", the test iframe is reloaded in place (`beforeunload`, then `navigation=reload` with the same URL, not discarded). Vite's client, loaded in the test iframe even with `hmr: false`, calls `location.reload()` once its WebSocket closes and the server answers again, which would happen when the BrowserStack tunnel drops the connection. Report when the WebSockets to the test server (Vite's and Vitest's own) open, error and close, with the close code and reason, to confirm it and see which connections drop. Access tokens are masked. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
Vite's client is loaded in the test pages even though Vitest turns HMR off, and keeps a WebSocket to the server. On BrowserStack, that connection gets dropped (code 1006, detected when the client sends its ping every 30s: after 60, 90 and 120s in the reported runs) while Vitest's own WebSocket stays up, and the client then reloads the page once the server answers again. This failed runs with "The iframe was reloaded during a test" on every browser, in random specs. Unlike Vitest's, nothing is ever sent to the browser on Vite's WebSocket, so it is likely dropped for inactivity: send a keepalive message on it every 15s. And patch Vite's client so it doesn't reload the page (nor log) if it is dropped anyway; the error reporter still reports the WebSocket closing. The patch throws if a Vite upgrade changes the code it targets. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
They were added to find what reloaded the test page on BrowserStack (Vite's client, after its WebSocket got dropped), which is now fixed. Keep reporting page errors. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
…ck videos - Polyfill `String.prototype.replaceAll`: Vitest's pretty-format uses it to print assertion diffs, and Chrome/Edge 80 don't have it. - Pin Vite to 8.3.7 in the root and the developer extension, the version Vitest resolves, so the lockfile has a single Vite. - Lower `connectTimeout` to 4 minutes, under the BrowserStack wrapper's 5-minute no-output timeout, so Vitest reports a failed connection instead of being killed. - Turn off BrowserStack video recording, as the Karma setup did. Environment: Datadog workspace Co-Authored-By: Claude Code claude-opus-5-5 <noreply@anthropic.com>
733adf8 to
d0beb4b
Compare
There was a problem hiding this comment.
The default full-matrix invocation applies Safari’s HTTP hostname to every browser, breaking secure-cookie expectations and reducing CookieStore coverage on recent Android Chrome.
🤖 Bits Code Review · Commit d0beb4b
| // BrowserStack rewrites localhost to bs-local.com for Safari: serve from that host directly | ||
| // (it resolves to 127.0.0.1) so the page is reachable and cookies match the page host. Other | ||
| // browsers keep `localhost`, which is a secure context (needed e.g. for `secure` cookies). | ||
| api: { host: configurations.some(({ name }) => name === 'Safari') ? 'bs-local.com' : 'localhost' }, |
There was a problem hiding this comment.
Scope the Safari hostname to Safari browsers
Running yarn test:unit:bs without BS_BROWSER includes Safari, so this shared setting serves every browser from HTTP bs-local.com. Android Chrome consequently loses its localhost secure context: on Chrome 145+, the cookieAccess test expecting both ordinary and Secure Partitioned cookies fails because the secure cookie is rejected, and CookieStore coverage is skipped. Preserve localhost for non-Safari browsers through browser-specific projects/servers or equivalent URL handling; the API hostname cannot simply be overridden on an individual Vitest browser instance.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
Motivation
Every previous Vitest attempt stalled on BrowserStack: Vitest's default Playwright provider can't pick exact browser versions or drive real Android devices, and Vitest's client needs Chrome 87+ / Safari 15.4+, while our unit matrix is Chrome 80, Edge 80, Firefox 78, Safari 14 and Android Chrome.
This PR moves
unit-bsto Vitest using the webdriverio provider, which reaches that exact matrix on real BrowserStack devices. Stacked on #5135. The Karma BrowserStack config is still in the repo (unused) so reverting is a one-line change; it is deleted in a follow-up PR.Closes RUM-19777
Changes
yarn test:unit:bs(CIunit-bsmatrix) runsvitest run --config test/unit-vitest/vite.bs.config.ts.test/unit-vitest/vite.bs.config.ts: webdriverio provider againsthub.browserstack.com:seleniumVersion: 4.0.0) on desktop browsers: BrowserStack otherwise serves Chrome 80 through Selenium 2.53, which rejects the window resize Vitest sends before each file. Viewport errors are non-fatal anyway.idleTimeout: 300): Vitest talks to the page over its own WebSocket, so BrowserStack otherwise kills the session as idle.||=/??=. A plugin transpiles dependency JS and routes Vitest's prebuilt/__vitest__/assets through the Vite pipeline (@oxc-project/runtimefor injected helpers).Object.hasOwn,Array.prototype.at, … (from 👷 Migrate unit tests to Vitest #4874), a same-originBroadcastChannel(Safari < 15.4) andAggregateError(Firefox < 79).bs-local.comfor Safari only (BrowserStack rewriteslocalhostthere); other browsers keeplocalhost, a secure context needed bysecurecookie tests.karma.bs.conf.js.trackRuntimeError.spec:stop()resolved towindow.stop(), which made Firefox 78 reload the test iframe; it now unsubscribes from the observable.UND_ERR_INVALID_ARG).Results
All five
unit-bsjobs pass the full suite. Job durations (CI Visibility, minutes, single run):unit-bsChrome 80unit-bsAndroid Chromeunit-bsEdge 80unit-bsFirefox 78unit-bsSafari 14Open issues
browserDisconnectTolerance). We saw one BrowserStack tunnel drop and one Edge connect timeout. Planned:bs-wrapper.tsexits with a dedicated code on these infrastructure errors + GitLabretry: exit_codesonunit-bs.Test instructions
Needs
BS_USERNAME/BS_ACCESS_KEY(e.g. in.env):BS_BROWSERis one ofedge,firefox,safari-desktop,chrome-desktop,chrome-mobile.Checklist