Skip to content

Commit

Permalink
test(visual): Fix e2e tests in new headless mode
Browse files Browse the repository at this point in the history
- Don't use intersection observer in the test code, instead just poll.
- Patch visual-regression to focus tab before taking a screenshot.
  • Loading branch information
melink14 committed Dec 18, 2024
1 parent 2560055 commit 5281117
Show file tree
Hide file tree
Showing 4 changed files with 690 additions and 109 deletions.
27 changes: 17 additions & 10 deletions extension/test/e2e_visual_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,23 @@ async function takeSnapshot(name: string) {
}

function waitForVisiblePopup(): Promise<void> {
return new Promise((resolve) => {
const popup = document.querySelector<HTMLDivElement>('#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<HTMLDivElement>('#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();
});
}

Expand Down
Loading

0 comments on commit 5281117

Please sign in to comment.