diff --git a/extension/test/e2e_visual_test.ts b/extension/test/e2e_visual_test.ts index e924ff139..c8d58db16 100644 --- a/extension/test/e2e_visual_test.ts +++ b/extension/test/e2e_visual_test.ts @@ -321,16 +321,23 @@ async function takeSnapshot(name: string) { } function waitForVisiblePopup(): Promise { - return new Promise((resolve) => { - const popup = document.querySelector('#rikaichan-window'); - if (!popup) { - return; - } - const o = new IntersectionObserver(() => { - resolve(); - o.disconnect(); - }); - o.observe(popup); + return new Promise((resolve, reject) => { + const startTime = Date.now(); + const checkElement = () => { + if (document.querySelector('#rikaichan-window')) { + resolve(); + return; + } + // Timing out here gives a better error message than waiting for + // the global test timeout. + if (Date.now() - startTime > 2000) { + reject(new Error("Rikaikun popup wasn't visible for 2000ms")); + return; + } + + requestAnimationFrame(checkElement); + }; + checkElement(); }); } diff --git a/patches/@web+test-runner-visual-regression+0.9.0.patch b/patches/@web+test-runner-visual-regression+0.9.0.patch new file mode 100644 index 000000000..3030dc341 --- /dev/null +++ b/patches/@web+test-runner-visual-regression+0.9.0.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/@web/test-runner-visual-regression/dist/visualRegressionPlugin.js b/node_modules/@web/test-runner-visual-regression/dist/visualRegressionPlugin.js +index bd4e733..416bd33 100644 +--- a/node_modules/@web/test-runner-visual-regression/dist/visualRegressionPlugin.js ++++ b/node_modules/@web/test-runner-visual-regression/dist/visualRegressionPlugin.js +@@ -42,6 +42,8 @@ function visualRegressionPlugin(options = {}) { + if (!element) { + throw new VisualRegressionError_1.VisualRegressionError('Something went wrong diffing element, the browser could not find it.'); + } ++ // Screenshots must be done in the foreground. ++ page.bringToFront(); + const screenshot = (await element.screenshot({ encoding: 'binary' })); + return (0, visualDiffCommand_1.visualDiffCommand)(mergedOptions, screenshot, payload.name, context); + }