Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(chrome-ext): find permanent solution to HN integration test failures (#2213)
Elijah Potterfb656ff07740
diff --git a/packages/chrome-plugin/tests/hn.spec.ts b/packages/chrome-plugin/tests/hn.spec.tsindex 231e94315..22e33176f 100644--- a/packages/chrome-plugin/tests/hn.spec.ts+++ b/packages/chrome-plugin/tests/hn.spec.ts@@ -1,3 +1,4 @@+import type { Page } from '@playwright/test';import { test } from './fixtures';import {assertHarperHighlightBoxes,@@ -8,14 +9,22 @@ import {testCanIgnoreTextareaSuggestion,} from './testUtils';-const TEST_PAGE_URL = 'https://news.ycombinator.com/item?id=45798898';+/** Must be computed. */+async function getTestPageUrl(page: Page) {+ await page.goto('https://news.ycombinator.com');-testBasicSuggestionTextarea(TEST_PAGE_URL);-testCanIgnoreTextareaSuggestion(TEST_PAGE_URL);-testCanBlockRuleTextareaSuggestion(TEST_PAGE_URL);+ const firstLink = page.locator('.subline').first().locator('a').last();+ await firstLink.click();++ return page.url();+}++testBasicSuggestionTextarea(getTestPageUrl);+testCanIgnoreTextareaSuggestion(getTestPageUrl);+testCanBlockRuleTextareaSuggestion(getTestPageUrl);test('Hacker News wraps correctly', async ({ page }) => {- await page.goto(TEST_PAGE_URL);+ await page.goto(await getTestPageUrl(page));await page.waitForTimeout(2000);await page.reload();@@ -35,7 +44,7 @@ test('Hacker News wraps correctly', async ({ page }) => {});test('Hacker News scrolls correctly', async ({ page }) => {- await page.goto(TEST_PAGE_URL);+ await page.goto(await getTestPageUrl(page));await page.waitForTimeout(2000);await page.reload();diff --git a/packages/chrome-plugin/tests/testUtils.ts b/packages/chrome-plugin/tests/testUtils.tsindex c6c90a435..b639d9f29 100644--- a/packages/chrome-plugin/tests/testUtils.ts+++ b/packages/chrome-plugin/tests/testUtils.ts@@ -67,9 +67,21 @@ export function getTextarea(page: Page): Locator {return page.locator('textarea');}-export async function testBasicSuggestionTextarea(testPageUrl: string) {+/** A string or function that resolves to a test page. */+export type TestPageUrlProvider = string | ((page: Page) => Promise<string>);++async function resolveTestPage(prov: TestPageUrlProvider, page: Page): Promise<string> {+ if (typeof prov === 'string') {+ return prov;+ } else {+ return await prov(page);+ }+}++export async function testBasicSuggestionTextarea(testPageUrl: TestPageUrlProvider) {test('Can apply basic suggestion.', async ({ page }) => {- await page.goto(testPageUrl);+ const url = await resolveTestPage(testPageUrl, page);+ await page.goto(url);await page.waitForTimeout(2000);await page.reload();@@ -88,9 +100,10 @@ export async function testBasicSuggestionTextarea(testPageUrl: string) {});}-export async function testCanIgnoreTextareaSuggestion(testPageUrl: string) {+export async function testCanIgnoreTextareaSuggestion(testPageUrl: TestPageUrlProvider) {test('Can ignore suggestion.', async ({ page }) => {- await page.goto(testPageUrl);+ const url = await resolveTestPage(testPageUrl, page);+ await page.goto(url);await page.waitForTimeout(2000);await page.reload();@@ -116,9 +129,10 @@ export async function testCanIgnoreTextareaSuggestion(testPageUrl: string) {});}-export async function testCanBlockRuleTextareaSuggestion(testPageUrl: string) {+export async function testCanBlockRuleTextareaSuggestion(testPageUrl: TestPageUrlProvider) {test('Can hide with rule block button', async ({ page }) => {- await page.goto(testPageUrl);+ const url = await resolveTestPage(testPageUrl, page);+ await page.goto(url);const editor = getTextarea(page);await replaceEditorContent(editor, 'This is an test.');