Commit Graph
1 Commits
Author SHA1 Message Date
Miranda Limonczenko 3879060a79 test(docs): check anchors in docs E2E link checks (#52174)
Closes DOCS-1254

## Problem

The docs E2E link check only confirms that a docs-owned link resolves to
a page. It strips the `#anchor` first, so a link to a renamed or removed
heading still passes.

For example, on production today:

- `guides/auth/redirect-urls` links to
`reference/javascript/auth-signinwithoauth#sign-in-using-a-third-party-provider-with-redirect`,
which is a tab value, not an element id.
- `guides/database/import-data` links to
`guides/platform/database-size#disk-management`, a heading that no
longer exists.

A full run found 58 broken anchor links on 53 guide pages. See the
[snapshot](https://app.notion.com/p/4015004b775f81538b15c28286177d31).
DOCS-1516 tracks the fixes.

## Solution

For each docs-owned link on a changed page:

- **Link to another page with an anchor:** the target page must have an
element with that `id`, or an `a[name]` with that value. The ids come
from the HTML that the existing status fetch already returns, so there
are no extra requests. Each target page is fetched once per run and
cached.
- **Same-page `#anchor`:** checked against the loaded page.
- **Failures:** each one is a soft assertion that names the page, the
link, and the missing anchor. A link that doesn't resolve reports only
its status, not a second anchor failure.

Pages with a lot of links still finish in time. For example, the
Personal access tokens guide links to over 200 API reference pages, and
checking every one for anchors made its test time out. The check now
downloads a linked page only when one of its links points to a section.

The link filtering moved into a pure `docsOwnedLinkTargets` function
with `node:test` coverage. `e2e/docs` gains a `test` script that runs it
along with the existing scope tests.

This complements #52100, which catches the opposite direction: unchanged
pages that link to a heading the PR removes.

## Manual testing

1. Run the unit tests:

   ```bash
   pnpm -C e2e/docs test
   ```

2. Run the suite against production for a page with a broken anchor and
a page without one:

   ```bash
   cd e2e/docs

DOCS_E2E_PAGE_PATHS=/docs/guides/auth/redirect-urls,/docs/guides/platform/ipv4-address
\
     PLAYWRIGHT_BASE_URL=https://supabase.com \
     pnpm exec playwright test --grep-invert @a11y
   ```
**Note:** A separate PR is cleaning up our anchor links. You can also
break a link locally and test.

3. Confirm `redirect-urls` fails, naming
`#sign-in-using-a-third-party-provider-with-redirect`, and
`ipv4-address` passes.
2026-10-23 12:17:30 -07:00