Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(chrome-ext): flaky tests (#1868)
Elijah Potterc10b4c634725
diff --git a/packages/chrome-plugin/tests/lexical.spec.ts b/packages/chrome-plugin/tests/lexical.spec.tsindex c12011b6c..8baf7947e 100644--- a/packages/chrome-plugin/tests/lexical.spec.ts+++ b/packages/chrome-plugin/tests/lexical.spec.ts@@ -1,6 +1,7 @@import { expect, test } from './fixtures';import {clickHarperHighlight,+ getHarperHighlights,getLexicalEditor,randomString,replaceEditorContent,@@ -37,10 +38,11 @@ test('Can ignore suggestion.', async ({ page }) => {await page.waitForTimeout(3000);- await clickHarperHighlight(page);+ const opened = await clickHarperHighlight(page);+ expect(opened).toBe(true);await page.getByTitle('Ignore this lint').click();- await page.waitForTimeout(3000);+ await expect(getHarperHighlights(page)).toHaveCount(0);// Nothing should change.expect(lexical).toContainText(cacheSalt);diff --git a/packages/chrome-plugin/tests/prosemirror.spec.ts b/packages/chrome-plugin/tests/prosemirror.spec.tsindex 4cb02a2ba..3769ebc39 100644--- a/packages/chrome-plugin/tests/prosemirror.spec.ts+++ b/packages/chrome-plugin/tests/prosemirror.spec.ts@@ -1,6 +1,7 @@import { expect, test } from './fixtures';import {clickHarperHighlight,+ getHarperHighlights,getProseMirrorEditor,randomString,replaceEditorContent,@@ -37,10 +38,11 @@ test('Can ignore suggestion.', async ({ page }) => {await page.waitForTimeout(3000);- await clickHarperHighlight(page);+ const opened = await clickHarperHighlight(page);+ expect(opened).toBe(true);await page.getByTitle('Ignore this lint').click();- await page.waitForTimeout(3000);+ await expect(getHarperHighlights(page)).toHaveCount(0);// Nothing should change.expect(pm).toContainText(cacheSalt);diff --git a/packages/chrome-plugin/tests/slate.spec.ts b/packages/chrome-plugin/tests/slate.spec.tsindex 8ad80381e..824e3c2a2 100644--- a/packages/chrome-plugin/tests/slate.spec.ts+++ b/packages/chrome-plugin/tests/slate.spec.ts@@ -1,6 +1,7 @@import { expect, test } from './fixtures';import {clickHarperHighlight,+ getHarperHighlights,getSlateEditor,randomString,replaceEditorContent,@@ -37,10 +38,11 @@ test('Can ignore suggestion.', async ({ page }) => {await page.waitForTimeout(3000);- await clickHarperHighlight(page);+ const opened = await clickHarperHighlight(page);+ expect(opened).toBe(true);await page.getByTitle('Ignore this lint').click();- await page.waitForTimeout(3000);+ await expect(getHarperHighlights(page)).toHaveCount(0);// Nothing should change.expect(slate).toContainText(cacheSalt);diff --git a/packages/chrome-plugin/tests/testUtils.ts b/packages/chrome-plugin/tests/testUtils.tsindex ca54d47dc..cd8ed4fa8 100644--- a/packages/chrome-plugin/tests/testUtils.ts+++ b/packages/chrome-plugin/tests/testUtils.ts@@ -44,20 +44,20 @@ export function getHarperHighlights(page: Page): Locator {export async function clickHarperHighlight(page: Page): Promise<boolean> {const highlights = getHarperHighlights(page);- if ((await highlights.count()) == 0) {+ // Wait briefly for at least one highlight to appear.+ // If none appear within a reasonable time, return false.+ try {+ await highlights.first().waitFor({ state: 'visible', timeout: 5000 });+ } catch {return false;}const box = await highlights.first().boundingBox();+ if (box == null) return false;- if (box == null) {- return false;- }-- // Locate the center of the element.+ // Locate the center of the element and click to open the popup.const cx = box.x + box.width / 2;const cy = box.y + box.height / 2;-await page.mouse.click(cx, cy);return true;}@@ -102,10 +102,13 @@ export async function testCanIgnoreTextareaSuggestion(testPageUrl: string) {await page.waitForTimeout(6000);- await clickHarperHighlight(page);+ // Open the popup for the first highlight and click Ignore.+ const opened = await clickHarperHighlight(page);+ expect(opened).toBe(true);await page.getByTitle('Ignore this lint').click();- await page.waitForTimeout(3000);+ // Wait for highlights to disappear after ignoring.+ await expect(getHarperHighlights(page)).toHaveCount(0);// Nothing should change.expect(editor).toHaveValue(cacheSalt);