mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 01:49:12 +08:00
Closes DOCS-1278 ## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Feature. Adds E2E test scaffolding and a CI check for the marketing site. ## What is the current behavior? Closes [FE-4047](https://linear.app/supabase/issue/FE-4047). The marketing site has no E2E coverage. Docs has a suite in `e2e/docs`, but its runner, git helpers and axe reporting are private to that package, so a second site cannot reuse them. ## What is the new behavior? * **A www suite scoped to changed content.** Changed `.mdx` files in `_blog`, `_events`, `_customers` and `_alternatives` map to the URLs they render. Pages with `disable_page_build: true` are skipped because they 404 by design. Capped at 20 pages. Enforces `heading-order` and `page-has-heading-one`, matching docs. * **`e2e/shared` The docs site is also static with similar needs. This folder shares the docs logic with www. * **A CI check that is safe to mark required.** Path scoping lives in a `Detect changed paths` step rather than a `paths:` trigger, so the check reports on every pull request instead of being skipped. `waitForVercelDocsPreview.js` becomes `waitForVercelPreview.js`, shared by both workflows. ## How the check behaves The job always reports a check run, so it is safe to mark required. Path scoping happens in a step rather than a `paths:` trigger, which would leave non-www pull requests waiting on a check that never reports. | Case | Behavior | | --- | --- | | Fork pull request adds new pages | Passes without testing. The Vercel wait is gated on `head.repo.full_name == github.repository`, so forks resolve no preview URL. The job emits a `::warning` and a job summary containing a ready-to-run `gh workflow run www-e2e.yml` command with the resolved page paths, so a maintainer can run it against the preview. | | Vercel preview times out or fails | Passes without testing. The wait step is `continue-on-error: true`, so a 900s timeout or a failed deployment leaves the URL unset and the suite skips. Vercel's own `Vercel – zone-www-dot-com` check already reports the failure. | | Draft pull request | Job does not run at all, gated at the job level on `pull_request.draft == false`. `ready_for_review` is in the trigger's `types`, so marking it ready runs the check. | | Another app changed, www untouched | Job runs and every step skips. The `www` filter matches only the four content directories, `e2e/www`, `e2e/shared`, the lockfile, and this workflow. | | Only the harness changed | Passes without testing. Scope resolves to zero pages, and the Vercel wait is additionally gated on `www_app`, so it does not wait for a preview Vercel skipped. | | No preview resolves, any reason | Skips rather than falling back to production. Production does not serve pages the pull request adds, so testing it would fail a valid change. | ### Not covered Changes to `apps/www` components and routes do not trigger this check — only the four content directories do. A follow-up can check global components such as the navigation and the footer. ## Manual testing 1. Start the site: `pnpm dev:www` 2. Run `pnpm e2e:www` with no www content changed. It should resolve zero pages and skip Playwright, not fail. 3. Touch a post, then run `pnpm e2e:www` again: `echo "" >> apps/www/_blog/2024-01-01-some-post.mdx`. The resolved `/blog/...` path should be listed before Playwright starts. 4. Run against production with no local server: `PLAYWRIGHT_BASE_URL=https://supabase.com WWW_E2E_PAGE_PATHS=/blog/postgres-language-server pnpm e2e:www` 5. Point step 4 at a page with a known heading problem. The failure should name the rule, the CSS selector and the markup. 6. Confirm docs still passes on the shared runner: `pnpm dev:docs`, then `pnpm e2e:docs` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added WWW end-to-end testing for affected content pages, including accessibility checks. * Added standard and full-site test commands, configurable preview testing, and failure reports. * Added shared utilities for page discovery, accessibility scanning, and test execution. * **Documentation** * Documented WWW test setup, coverage, debugging, CI behavior, and running checks against production or preview environments. * **Improvements** * Updated documentation test workflows to better identify affected changes and handle preview environments. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
147 lines
4.6 KiB
TypeScript
147 lines
4.6 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
import type { TestInfo } from '@playwright/test'
|
|
|
|
import { parsePagePaths } from '../../shared/paths.ts'
|
|
import {
|
|
attachScanReport,
|
|
blockingViolations,
|
|
ENFORCED_RULES,
|
|
formatViolations,
|
|
scanArticle,
|
|
scanLooksEmpty,
|
|
settleForAxe,
|
|
shouldEnforceAll,
|
|
unloadedResult,
|
|
violationIds,
|
|
} from '../utils/axe-helpers.js'
|
|
import {
|
|
articleSelectorForPagePath,
|
|
browserLikeUserAgent,
|
|
collectDocsOwnedLinks,
|
|
} from '../utils/docs-links.js'
|
|
|
|
const pagePaths = parsePagePaths(process.env.DOCS_E2E_PAGE_PATHS)
|
|
|
|
function annotate(testInfo: TestInfo, description: string) {
|
|
testInfo.annotations.push({ type: 'warning', description })
|
|
console.warn(`::warning title=Accessibility::${description}`)
|
|
}
|
|
|
|
test.describe('Docs owned pages', () => {
|
|
// Without this, every test in this file runs on one worker.
|
|
test.describe.configure({ mode: 'parallel' })
|
|
|
|
test('resolved page list must not be empty', () => {
|
|
expect(
|
|
pagePaths.length,
|
|
'No pages to test. `pnpm e2e:docs` resolves pages from git changes by default, ' +
|
|
'or set DOCS_E2E_PAGE_PATHS explicitly.'
|
|
).toBeGreaterThan(0)
|
|
})
|
|
|
|
for (const pagePath of pagePaths) {
|
|
test(`${pagePath} loads and docs-owned article links resolve`, async ({ page }, testInfo) => {
|
|
const baseURL = testInfo.project.use.baseURL
|
|
expect(baseURL, 'A Playwright base URL should be configured').toBeTruthy()
|
|
|
|
const articleSelector = articleSelectorForPagePath(pagePath)
|
|
const response = await page.goto(pagePath)
|
|
expect(response, `Expected a response for ${pagePath}`).not.toBeNull()
|
|
expect(
|
|
response!.ok(),
|
|
`Page should return a successful status, got ${response!.status()}`
|
|
).toBeTruthy()
|
|
|
|
const article = page.locator(articleSelector)
|
|
await expect(article, 'Page article should be present').toBeVisible()
|
|
|
|
const links = await collectDocsOwnedLinks(page, baseURL!, articleSelector)
|
|
const userAgent = await browserLikeUserAgent(page)
|
|
|
|
for (const url of links) {
|
|
try {
|
|
const linkResponse = await page.request.get(url, { headers: { 'user-agent': userAgent } })
|
|
expect
|
|
.soft(linkResponse.ok(), `${url} should resolve (status ${linkResponse.status()})`)
|
|
.toBeTruthy()
|
|
} catch (error) {
|
|
expect
|
|
.soft(
|
|
null,
|
|
`${url} should be reachable (${error instanceof Error ? error.message : error})`
|
|
)
|
|
.toBeTruthy()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
for (const pagePath of pagePaths) {
|
|
test(`${pagePath} has no blocking accessibility violations @a11y`, async ({
|
|
page,
|
|
}, testInfo) => {
|
|
test.setTimeout(120_000)
|
|
|
|
const include = articleSelectorForPagePath(pagePath)
|
|
|
|
let response
|
|
try {
|
|
response = await page.goto(pagePath)
|
|
} catch (error) {
|
|
await attachScanReport(testInfo, unloadedResult(pagePath, pagePath, null, include))
|
|
throw error
|
|
}
|
|
|
|
const status = response?.status() ?? null
|
|
|
|
if (!response?.ok()) {
|
|
await attachScanReport(testInfo, unloadedResult(pagePath, page.url(), status, include))
|
|
expect(
|
|
response?.ok(),
|
|
`Expected a successful response for ${pagePath}, got ${status}`
|
|
).toBeTruthy()
|
|
return
|
|
}
|
|
|
|
await settleForAxe(page)
|
|
|
|
await expect(
|
|
page.locator(include),
|
|
`No article matching "${include}" on ${pagePath}. This suite covers guides and ` +
|
|
'troubleshooting entries; other routes have no article element to scan.'
|
|
).toBeVisible()
|
|
|
|
const result = await scanArticle(page, pagePath, include)
|
|
result.status = status
|
|
|
|
await attachScanReport(testInfo, result)
|
|
|
|
if (scanLooksEmpty(result)) {
|
|
annotate(
|
|
testInfo,
|
|
`${pagePath} scanned only ${result.elementCount} element(s) in ${include}, so a clean ` +
|
|
'result here proves nothing. Most likely the page had not finished rendering.'
|
|
)
|
|
}
|
|
|
|
const blocking = blockingViolations(result)
|
|
|
|
const reported = result.violations.filter((violation) => !blocking.includes(violation))
|
|
if (reported.length) {
|
|
annotate(
|
|
testInfo,
|
|
`${pagePath} has ${reported.length} non-blocking accessibility finding(s): ` +
|
|
reported.map((v) => `${v.id} (${v.nodes.length})`).join(', ')
|
|
)
|
|
}
|
|
|
|
const enforced = shouldEnforceAll() ? 'all WCAG 2.1 A/AA rules' : ENFORCED_RULES.join(', ')
|
|
|
|
expect(
|
|
violationIds(blocking),
|
|
`${pagePath} has blocking a11y violations (${enforced}):\n${formatViolations(blocking)}`
|
|
).toEqual([])
|
|
})
|
|
}
|
|
})
|