diff --git a/.changeset/kind-schools-rule.md b/.changeset/kind-schools-rule.md new file mode 100644 index 000000000..f2344f9a3 --- /dev/null +++ b/.changeset/kind-schools-rule.md @@ -0,0 +1,22 @@ +--- +'@web/test-runner-chrome': patch +--- + +This changeset removes the Puppeteer/Chrome focus browser patches that shouldn't +be needed anymore, and can cause instability. + +The patches were added quite a while ago, and the upstream issues should +be resolved in Chromium. See: https://issues.chromium.org/issues/40272146. + +Also see: +https://github.com/puppeteer/puppeteer/issues/10350#issuecomment-1586858101. + +The patches are currently also resulting some instability of web test +runner. That is because the patch calls an exposed function from inside +the browser, while navigation later on during `stopSession` can happen; +breaking the handle for retrieving function call arguments passed to the +exposed function. + +Puppeteer team found this issue and also landed a fix to improve the +failure mode here. See: +https://github.com/puppeteer/puppeteer/pull/13759 diff --git a/.changeset/shaggy-chefs-dance.md b/.changeset/shaggy-chefs-dance.md new file mode 100644 index 000000000..1ba084713 --- /dev/null +++ b/.changeset/shaggy-chefs-dance.md @@ -0,0 +1,10 @@ +--- +'@web/test-runner-core': patch +--- + +Improve debug message for test runner uncaught exceptions + +This should make debugging easier. It wasn't very easy to figure out +where the errors originated from (because of how the actual uncaught +exception only happened with many concurrent builds inside a sandbox +environment that is hard to debug). diff --git a/package-lock.json b/package-lock.json index ea5bd2f01..b0ffe701d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9903,15 +9903,6 @@ "node": ">=0.8.0" } }, - "node_modules/async-mutex": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.4.0.tgz", - "integrity": "sha512-eJFZ1YhRR8UN8eBLoNzcDPcy/jqjsg6I1AP+KvWQX80BqOSW1oJPJXDylPUEeMr2ZQvHgnQ//Lp6f3RQ1zI7HA==", - "license": "MIT", - "dependencies": { - "tslib": "^2.4.0" - } - }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -38780,7 +38771,6 @@ "dependencies": { "@web/test-runner-core": "^0.13.0", "@web/test-runner-coverage-v8": "^0.8.0", - "async-mutex": "0.4.0", "chrome-launcher": "^0.15.0", "puppeteer-core": "^24.0.0" }, diff --git a/packages/test-runner-chrome/package.json b/packages/test-runner-chrome/package.json index 1fc6f739b..2159f9636 100644 --- a/packages/test-runner-chrome/package.json +++ b/packages/test-runner-chrome/package.json @@ -48,7 +48,6 @@ "dependencies": { "@web/test-runner-core": "^0.13.0", "@web/test-runner-coverage-v8": "^0.8.0", - "async-mutex": "0.4.0", "chrome-launcher": "^0.15.0", "puppeteer-core": "^24.0.0" }, diff --git a/packages/test-runner-chrome/src/ChromeLauncherPage.ts b/packages/test-runner-chrome/src/ChromeLauncherPage.ts index cf5cfebe5..aa4862f40 100644 --- a/packages/test-runner-chrome/src/ChromeLauncherPage.ts +++ b/packages/test-runner-chrome/src/ChromeLauncherPage.ts @@ -2,9 +2,6 @@ import { Page, JSCoverageEntry } from 'puppeteer-core'; import { TestRunnerCoreConfig } from '@web/test-runner-core'; import { v8ToIstanbul } from '@web/test-runner-coverage-v8'; import { SessionResult } from '@web/test-runner-core'; -import { Mutex } from 'async-mutex'; - -const mutex = new Mutex(); declare global { interface Window { @@ -49,43 +46,6 @@ export class ChromeLauncherPage { }); } - // Patching the browser page to workaround an issue in the new headless mode of Chrome where some functions - // with callbacks (requestAnimationFrame and requestIdleCallback) are not executing their callbacks. - // https://github.com/puppeteer/puppeteer/issues/10350 - if (!this.patchAdded) { - await this.puppeteerPage.exposeFunction('__bringTabToFront', (id: string) => { - const promise = new Promise(resolve => { - this.resolvers[id] = resolve as () => void; - }); - return mutex.runExclusive(async () => { - await this.puppeteerPage.bringToFront(); - await promise; - }); - }); - await this.puppeteerPage.exposeFunction('__releaseLock', (id: string) => { - this.resolvers[id]?.(); - }); - await this.puppeteerPage.evaluateOnNewDocument(() => { - // eslint-disable-next-line @typescript-eslint/ban-types - function patchFunction(name: string, fn: Function) { - (window as any)[name] = (...args: unknown[]) => { - const result = fn.call(window, ...args); - const id = Math.random().toString().substring(2); - // Make sure that the tab running the test code is brought back to the front. - window.__bringTabToFront(id); - fn.call(window, () => { - window.__releaseLock(id); - }); - return result; - }; - } - - patchFunction('requestAnimationFrame', window.requestAnimationFrame); - patchFunction('requestIdleCallback', window.requestIdleCallback); - }); - this.patchAdded = true; - } - await this.puppeteerPage.setViewport({ height: 600, width: 800 }); await this.puppeteerPage.goto(url); } diff --git a/packages/test-runner/src/startTestRunner.ts b/packages/test-runner/src/startTestRunner.ts index a22757561..5214691ba 100644 --- a/packages/test-runner/src/startTestRunner.ts +++ b/packages/test-runner/src/startTestRunner.ts @@ -73,7 +73,7 @@ export async function startTestRunner(options: StartTestRunnerParams = {}) { if (autoExitProcess) { process.on('uncaughtException', error => { /* eslint-disable-next-line no-console */ - console.error(error); + console.error(`Uncaught exception, stopping test runner..\n`, error); stop(); }); }