Skip to content

Commit d8b09d0

Browse files
authored
Merge pull request #2928 from devversion/fixes
fix(test-runner-chrome): remove focus browser patches
2 parents dbd418f + 24e3290 commit d8b09d0

File tree

6 files changed

+33
-52
lines changed

6 files changed

+33
-52
lines changed

.changeset/kind-schools-rule.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@web/test-runner-chrome': patch
3+
---
4+
5+
This changeset removes the Puppeteer/Chrome focus browser patches that shouldn't
6+
be needed anymore, and can cause instability.
7+
8+
The patches were added quite a while ago, and the upstream issues should
9+
be resolved in Chromium. See: https://issues.chromium.org/issues/40272146.
10+
11+
Also see:
12+
https://github.com/puppeteer/puppeteer/issues/10350#issuecomment-1586858101.
13+
14+
The patches are currently also resulting some instability of web test
15+
runner. That is because the patch calls an exposed function from inside
16+
the browser, while navigation later on during `stopSession` can happen;
17+
breaking the handle for retrieving function call arguments passed to the
18+
exposed function.
19+
20+
Puppeteer team found this issue and also landed a fix to improve the
21+
failure mode here. See:
22+
https://github.com/puppeteer/puppeteer/pull/13759

.changeset/shaggy-chefs-dance.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@web/test-runner-core': patch
3+
---
4+
5+
Improve debug message for test runner uncaught exceptions
6+
7+
This should make debugging easier. It wasn't very easy to figure out
8+
where the errors originated from (because of how the actual uncaught
9+
exception only happened with many concurrent builds inside a sandbox
10+
environment that is hard to debug).

package-lock.json

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/test-runner-chrome/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"dependencies": {
4949
"@web/test-runner-core": "^0.13.0",
5050
"@web/test-runner-coverage-v8": "^0.8.0",
51-
"async-mutex": "0.4.0",
5251
"chrome-launcher": "^0.15.0",
5352
"puppeteer-core": "^24.0.0"
5453
},

packages/test-runner-chrome/src/ChromeLauncherPage.ts

-40
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { Page, JSCoverageEntry } from 'puppeteer-core';
22
import { TestRunnerCoreConfig } from '@web/test-runner-core';
33
import { v8ToIstanbul } from '@web/test-runner-coverage-v8';
44
import { SessionResult } from '@web/test-runner-core';
5-
import { Mutex } from 'async-mutex';
6-
7-
const mutex = new Mutex();
85

96
declare global {
107
interface Window {
@@ -49,43 +46,6 @@ export class ChromeLauncherPage {
4946
});
5047
}
5148

52-
// Patching the browser page to workaround an issue in the new headless mode of Chrome where some functions
53-
// with callbacks (requestAnimationFrame and requestIdleCallback) are not executing their callbacks.
54-
// https://github.com/puppeteer/puppeteer/issues/10350
55-
if (!this.patchAdded) {
56-
await this.puppeteerPage.exposeFunction('__bringTabToFront', (id: string) => {
57-
const promise = new Promise(resolve => {
58-
this.resolvers[id] = resolve as () => void;
59-
});
60-
return mutex.runExclusive(async () => {
61-
await this.puppeteerPage.bringToFront();
62-
await promise;
63-
});
64-
});
65-
await this.puppeteerPage.exposeFunction('__releaseLock', (id: string) => {
66-
this.resolvers[id]?.();
67-
});
68-
await this.puppeteerPage.evaluateOnNewDocument(() => {
69-
// eslint-disable-next-line @typescript-eslint/ban-types
70-
function patchFunction(name: string, fn: Function) {
71-
(window as any)[name] = (...args: unknown[]) => {
72-
const result = fn.call(window, ...args);
73-
const id = Math.random().toString().substring(2);
74-
// Make sure that the tab running the test code is brought back to the front.
75-
window.__bringTabToFront(id);
76-
fn.call(window, () => {
77-
window.__releaseLock(id);
78-
});
79-
return result;
80-
};
81-
}
82-
83-
patchFunction('requestAnimationFrame', window.requestAnimationFrame);
84-
patchFunction('requestIdleCallback', window.requestIdleCallback);
85-
});
86-
this.patchAdded = true;
87-
}
88-
8949
await this.puppeteerPage.setViewport({ height: 600, width: 800 });
9050
await this.puppeteerPage.goto(url);
9151
}

packages/test-runner/src/startTestRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function startTestRunner(options: StartTestRunnerParams = {}) {
7373
if (autoExitProcess) {
7474
process.on('uncaughtException', error => {
7575
/* eslint-disable-next-line no-console */
76-
console.error(error);
76+
console.error(`Uncaught exception, stopping test runner..\n`, error);
7777
stop();
7878
});
7979
}

0 commit comments

Comments
 (0)