Skip to content

Commit 8d63fc5

Browse files
committed
🐛 fix BrowserStack failures on Firefox 78 and Android Chrome
- 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)
1 parent af64018 commit 8d63fc5

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎packages/browser-core/src/domain/error/trackRuntimeError.spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { disableJasmineUncaughtExceptionTracking, wait } from '../../../test'
2+
import type { Subscription } from '../../tools/observable'
23
import type { UnhandledErrorCallback } from './trackRuntimeError'
34
import { instrumentOnError, instrumentUnhandledRejection, trackRuntimeError } from './trackRuntimeError'
45
import type { RawError } from './error.types'
@@ -10,15 +11,16 @@ describe('trackRuntimeError', () => {
1011
disableJasmineUncaughtExceptionTracking()
1112

1213
const errorObservable = trackRuntimeError()
14+
let subscription: Subscription | undefined
1315
const errorNotification = new Promise<RawError>((resolve) => {
14-
errorObservable.subscribe((e: RawError) => resolve(e))
16+
subscription = errorObservable.subscribe((e: RawError) => resolve(e))
1517
})
1618

1719
try {
1820
await invokeAndWaitForErrorHandlers(callback)
1921
return await errorNotification
2022
} finally {
21-
stop()
23+
subscription?.unsubscribe()
2224
}
2325
}
2426

‎test/unit-vitest/vite.bs.config.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ const config = mergeConfig(
128128
browser: {
129129
headless: false,
130130
// BrowserStack rewrites localhost to bs-local.com for Safari: serve from that host directly
131-
// (it resolves to 127.0.0.1) so the page is reachable and cookies match the page host.
132-
api: { host: 'bs-local.com' },
131+
// (it resolves to 127.0.0.1) so the page is reachable and cookies match the page host. Other
132+
// browsers keep `localhost`, which is a secure context (needed e.g. for `secure` cookies).
133+
api: { host: configurations.some(({ name }) => name === 'Safari') ? 'bs-local.com' : 'localhost' },
133134
orchestratorScripts: [
134135
{ content: ERROR_REPORTER, type: 'text/javascript' },
135136
{ src: POLYFILLS_PATH, type: 'text/javascript' },

‎test/unit-vitest/vitestBrowserPolyfills.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,17 @@
156156

157157
globalThis.BroadcastChannel = BroadcastChannelPolyfill
158158
}
159+
160+
// Firefox < 79. Vitest uses it to report multiple errors.
161+
if (typeof AggregateError === 'undefined') {
162+
class AggregateErrorPolyfill extends Error {
163+
constructor(errors, message) {
164+
super(message)
165+
this.name = 'AggregateError'
166+
this.errors = Array.from(errors)
167+
}
168+
}
169+
170+
globalThis.AggregateError = AggregateErrorPolyfill
171+
}
159172
})()

0 commit comments

Comments
 (0)