Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/browser/src/client/public/error-catcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ function catchWindowErrors(errorEvent, prop, cb) {
cb(e)
}
else {
console.error(e[prop])
// `ErrorEvent` doesn't necessary have `ErrotEvent.error` defined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// `ErrorEvent` doesn't necessary have `ErrotEvent.error` defined
// `ErrorEvent` doesn't necessary have `ErrorEvent.error` defined

// but some has `ErrorEvent.message` defined, e.g. ResizeObserver error.
// https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent/error
// https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#observation_errors
console.error(e.message ? new Error(e.message) : e)
}
}
const addEventListener = window.addEventListener.bind(window)
Expand Down
24 changes: 24 additions & 0 deletions test/browser/fixtures/unhandled-non-error/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test } from "vitest";

test("ResizeObserver error", async () => {
const divElem = document.createElement("div");
divElem.style.width = "100px";
divElem.style.height = "100px";
document.body.appendChild(divElem);

const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
(entry.target as HTMLElement).style.width =
`${entry.contentBoxSize[0].inlineSize + 10}px`;
}
});
const promise = Promise.withResolvers();
window.addEventListener("error", (event) => {
if (event.message.includes("ResizeObserver loop")) {
promise.resolve(null);
}
});
resizeObserver.observe(divElem);
await promise.promise;
resizeObserver.unobserve(divElem);
});
15 changes: 15 additions & 0 deletions test/browser/fixtures/unhandled-non-error/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitest/config'
import { instances, provider } from '../../settings'

export default defineConfig({
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)),
test: {
browser: {
enabled: true,
provider,
instances,
headless: true,
},
},
})
4 changes: 3 additions & 1 deletion test/browser/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const devInstances: BrowserInstanceOption[] = [
const playwrightInstances: BrowserInstanceOption[] = [
{ browser: 'chromium' },
{ browser: 'firefox' },
{ browser: 'webkit' },
// hard to setup playwright webkit on some machines (e.g. ArchLinux)
// this allows skipping it locally by BROWSER_NO_WEBKIT=true
...(process.env.BROWSER_NO_WEBKIT ? [] : [{ browser: 'webkit' as const }]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being set anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for me to run test locally by BROWSER_NO_WEBKIT=1 pnpm -C test/browser ... commands as I cannot setup playwright on Archlinux.

]

const webdriverioInstances: BrowserInstanceOption[] = [
Expand Down
14 changes: 14 additions & 0 deletions test/browser/specs/unhandled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ test('disables tracking', async () => {
})
expect(stderr).toBe('')
})

test('print unhandled non error', async () => {
const { testTree, stderr } = await runBrowserTests({
root: './fixtures/unhandled-non-error',
})
expect(stderr).toContain('[Error: ResizeObserver loop completed with undelivered notifications.]')
expect(testTree()).toMatchInlineSnapshot(`
{
"basic.test.ts": {
"ResizeObserver error": "passed",
},
}
`)
})
Loading