The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(docs) Add scaffolding and CI/CD step for Docs Playwright (#48120)
Miranda Limonczenko9199aad57e3e
diff --git a/.github/workflows/docs-e2e.yml b/.github/workflows/docs-e2e.ymlnew file mode 100644index 00000000000..eae790a43ed--- /dev/null+++ b/.github/workflows/docs-e2e.yml@@ -0,0 +1,122 @@+name: Docs E2E Tests++on:+ pull_request:+ types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]+ branches: ['master']+ paths:+ - 'apps/docs/content/guides/getting-started/quickstarts/nextjs.mdx'+ - 'apps/docs/content/_partials/quickstart_db_setup.mdx'+ - 'apps/docs/content/_partials/api_settings.mdx'+ - 'e2e/docs/**'+ - 'pnpm-lock.yaml'+ - '.github/workflows/docs-e2e.yml'+ workflow_dispatch:+ inputs:+ base_url:+ description: 'Base URL to test against'+ required: false+ default: 'https://supabase.com'+ type: string++concurrency:+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}+ cancel-in-progress: true++permissions:+ contents: read+ deployments: read+ statuses: read+ pull-requests: read++env:+ CI: true++jobs:+ e2e:+ name: Docs E2E+ if: github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false+ timeout-minutes: 30+ runs-on: blacksmith-4vcpu-ubuntu-2404++ steps:+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0+ with:+ persist-credentials: false+ sparse-checkout: |+ e2e/docs+ patches++ # Vercel skips the docs preview when a PR only changes the harness+ # (e2e/docs, workflow). Wait for a preview only when apps/docs changed.+ - name: Detect docs app changes+ if: github.event_name == 'pull_request'+ id: filter+ uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2+ with:+ filters: |+ docs_app:+ - 'apps/docs/**'++ - name: Wait for Vercel docs preview+ if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && steps.filter.outputs.docs_app == 'true'+ id: deployment+ uses: vercel/wait-for-deployment-action@0e2b0c5c5cce31f1648108aeec56467187aca037+ with:+ project-slug: docs+ environment: preview+ timeout: '900'++ - name: Resolve base URL+ id: base-url+ env:+ EVENT_NAME: ${{ github.event_name }}+ BASE_URL_INPUT: ${{ inputs.base_url }}+ DEPLOYMENT_URL: ${{ steps.deployment.outputs.deployment-url }}+ DOCS_APP_CHANGED: ${{ steps.filter.outputs.docs_app }}+ run: |+ if [ "$EVENT_NAME" = "workflow_dispatch" ]; then+ printf 'url=%s\n' "$BASE_URL_INPUT" >> "$GITHUB_OUTPUT"+ echo "use_bypass=false" >> "$GITHUB_OUTPUT"+ elif [ "$DOCS_APP_CHANGED" = "true" ] && [ -n "$DEPLOYMENT_URL" ]; then+ printf 'url=%s\n' "$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"+ echo "use_bypass=true" >> "$GITHUB_OUTPUT"+ else+ # Harness-only PRs have no docs preview; test against production.+ echo "url=https://supabase.com" >> "$GITHUB_OUTPUT"+ echo "use_bypass=false" >> "$GITHUB_OUTPUT"+ fi++ - uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9+ name: Install pnpm+ with:+ run_install: false++ - name: Use Node.js+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0+ with:+ node-version-file: '.nvmrc'+ cache: 'pnpm'++ - name: Install dependencies+ run: pnpm install --frozen-lockfile --filter=e2e-docs...++ - name: Install Playwright Chromium+ run: pnpm -C e2e/docs exec playwright install chromium --with-deps --only-shell++ - name: Run docs E2E+ working-directory: e2e/docs+ run: pnpm run e2e:docs+ env:+ PLAYWRIGHT_BASE_URL: ${{ steps.base-url.outputs.url }}+ VERCEL_AUTOMATION_BYPASS_SECRET: ${{ steps.base-url.outputs.use_bypass == 'true' && secrets.VERCEL_AUTOMATION_BYPASS_DOCS || '' }}++ - name: Upload Playwright report+ if: failure()+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2+ with:+ name: docs-playwright-report+ path: |+ e2e/docs/playwright-report/+ e2e/docs/test-results/+ retention-days: 7diff --git a/e2e/docs/.gitignore b/e2e/docs/.gitignorenew file mode 100644index 00000000000..68c5d18f00d--- /dev/null+++ b/e2e/docs/.gitignore@@ -0,0 +1,5 @@+node_modules/+/test-results/+/playwright-report/+/blob-report/+/playwright/.cache/diff --git a/e2e/docs/README.md b/e2e/docs/README.mdnew file mode 100644index 00000000000..deb4ca41c8a--- /dev/null+++ b/e2e/docs/README.md@@ -0,0 +1,83 @@+# Supabase Docs E2E Tests++Playwright end-to-end tests for the docs site under `apps/docs`.+Add new docs journeys under `features/`. They all run together as one suite.++## Setup++Install the Playwright browser once from this directory:++```bash+cd e2e/docs+pnpm exec playwright install chromium+```++## Choosing a target URL++Tests run against whatever `PLAYWRIGHT_BASE_URL` points to, defaulting to the+local docs dev server at `http://localhost:3001`.++- **Local docs server** — in a separate terminal, start docs from the repo root:++ ```bash+ pnpm dev:docs+ ```++- **A deployed site** — set the base URL inline:++ ```bash+ PLAYWRIGHT_BASE_URL=https://supabase.com pnpm e2e:docs+ ```++If the target is a protected Vercel preview, also set+`VERCEL_AUTOMATION_BYPASS_SECRET` so the tests can bypass deployment protection.++The local docs server requires a full monorepo install and credentials for some+content, so the quickest way to run the suite is against a deployed site. Reach+for the local server only when you need to test unpublished content changes.++## Running the tests++From the repo root:++```bash+pnpm e2e:docs+```++Or from this directory:++```bash+pnpm run e2e:docs+```++### UI mode for debugging++```bash+pnpm e2e:docs:ui+```++### Run a single file++```bash+pnpm run e2e:docs -- features/<name>.spec.ts+```++## Debugging++- View the HTML report after a run:++ ```bash+ pnpm -C e2e/docs exec playwright show-report+ ```++- Traces and screenshots for failures are saved in `test-results/`.++## CI++`.github/workflows/docs-e2e.yml` runs this suite on pull requests that touch the+tested docs pages or `e2e/docs`. When the PR changes `apps/docs`, the workflow+waits for the matching Vercel preview and points `PLAYWRIGHT_BASE_URL` at it.+When only the harness or workflow changes, Vercel skips the docs preview, so+the suite falls back to production. Draft PRs are skipped until marked ready+for review. The workflow can also be triggered manually with an optional+`base_url` input that defaults to production.diff --git a/e2e/docs/features/quickstarts.spec.ts b/e2e/docs/features/quickstarts.spec.tsnew file mode 100644index 00000000000..afc09c46370--- /dev/null+++ b/e2e/docs/features/quickstarts.spec.ts@@ -0,0 +1,45 @@+import { expect, test } from '@playwright/test'++import { collectDocsOwnedLinks } from '../utils/docs-links.js'++const QUICKSTART_PATH = '/docs/guides/getting-started/quickstarts/nextjs'+const ARTICLE_SELECTOR = '#sb-docs-guide-main-article'++test.describe('Next.js quickstart', () => {+ test('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 response = await page.goto(QUICKSTART_PATH)+ expect(response, `Expected a response for ${QUICKSTART_PATH}`).not.toBeNull()+ expect(+ response!.ok(),+ `Quickstart page should return a successful status, got ${response!.status()}`+ ).toBeTruthy()++ const article = page.locator(ARTICLE_SELECTOR)+ await expect(article, 'Guide article should be present').toBeVisible()+ await expect(+ article.getByRole('heading', { level: 1 }),+ 'Guide article should include an h1'+ ).toBeVisible()++ const links = await collectDocsOwnedLinks(page, baseURL!)++ for (const url of links) {+ try {+ const linkResponse = await page.request.get(url)+ 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()+ }+ }+ })+})diff --git a/e2e/docs/package.json b/e2e/docs/package.jsonnew file mode 100644index 00000000000..3a53ee4976e--- /dev/null+++ b/e2e/docs/package.json@@ -0,0 +1,13 @@+{+ "name": "e2e-docs",+ "version": "1.0.0",+ "private": true,+ "type": "module",+ "scripts": {+ "e2e:docs": "playwright test",+ "e2e:ui": "playwright test --ui"+ },+ "dependencies": {+ "@playwright/test": "^1.59.1"+ }+}diff --git a/e2e/docs/playwright.config.ts b/e2e/docs/playwright.config.tsnew file mode 100644index 00000000000..27712136db9--- /dev/null+++ b/e2e/docs/playwright.config.ts@@ -0,0 +1,50 @@+import { defineConfig } from '@playwright/test'++const IS_CI = !!process.env.CI++export default defineConfig({+ testDir: './features',+ testMatch: /.*\.spec\.ts/,+ timeout: 60_000,+ forbidOnly: IS_CI,+ retries: IS_CI ? 2 : 0,+ maxFailures: 3,+ expect: {+ timeout: 15_000,+ },+ fullyParallel: false,+ workers: 1,+ use: {+ baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:3001',+ browserName: 'chromium',+ headless: true,+ navigationTimeout: 30_000,+ screenshot: 'only-on-failure',+ trace: 'retain-on-failure',+ video: 'off',+ extraHTTPHeaders: process.env.VERCEL_AUTOMATION_BYPASS_SECRET+ ? {+ 'x-vercel-protection-bypass': process.env.VERCEL_AUTOMATION_BYPASS_SECRET,+ 'x-vercel-set-bypass-cookie': 'true',+ }+ : undefined,+ },+ projects: [+ {+ name: 'Features',+ testDir: './features',+ testMatch: /.*\.spec\.ts/,+ use: {+ browserName: 'chromium',+ },+ },+ ],+ reporter: IS_CI+ ? [['list'], ['html', { open: 'never', outputFolder: './playwright-report' }]]+ : [+ ['list'],+ ['html', { open: 'never', outputFolder: './playwright-report' }],+ ['json', { outputFile: './test-results/test-results.json' }],+ ],+ outputDir: './test-results',+})diff --git a/e2e/docs/tsconfig.json b/e2e/docs/tsconfig.jsonnew file mode 100644index 00000000000..d59602689dc--- /dev/null+++ b/e2e/docs/tsconfig.json@@ -0,0 +1,9 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "nodenext",+ "skipLibCheck": true,+ "esModuleInterop": true,+ "strict": true+ }+}diff --git a/e2e/docs/utils/docs-links.ts b/e2e/docs/utils/docs-links.tsnew file mode 100644index 00000000000..5796b0b84ce--- /dev/null+++ b/e2e/docs/utils/docs-links.ts@@ -0,0 +1,42 @@+import type { Page } from '@playwright/test'++const ARTICLE_SELECTOR = '#sb-docs-guide-main-article'+const DOCS_PATH_PREFIX = '/docs'++/**+ * Collect unique docs-owned links from the main guide article.+ *+ * Cross-app paths such as `/ui` and `/dashboard` are excluded because the+ * docs preview does not own those routes.+ */+export async function collectDocsOwnedLinks(page: Page, baseURL: string): Promise<string[]> {+ const origin = new URL(baseURL).origin+ const hrefs = await page+ .locator(`${ARTICLE_SELECTOR} a[href]`)+ .evaluateAll((anchors) =>+ anchors.map((anchor) => (anchor as HTMLAnchorElement).getAttribute('href') ?? '')+ )+ const links = new Set<string>()++ for (const href of hrefs) {+ if (!href || href.startsWith('#')) continue++ let url: URL+ try {+ url = new URL(href, baseURL)+ } catch {+ continue+ }++ if (!['http:', 'https:'].includes(url.protocol)) continue+ if (url.origin !== origin) continue+ if (url.pathname !== DOCS_PATH_PREFIX && !url.pathname.startsWith(`${DOCS_PATH_PREFIX}/`)) {+ continue+ }++ url.hash = ''+ links.add(url.toString())+ }++ return [...links].sort()+}diff --git a/package.json b/package.jsonindex e76e4c7dd3c..7ccfdf72a22 100644--- a/package.json+++ b/package.json@@ -34,6 +34,8 @@"e2e:setup:platform": "SKIP_ASSET_UPLOAD=1 NODE_OPTIONS=\"--max-old-space-size=4096\" pnpm run build:studio && pnpm --prefix ./apps/studio start","e2e": "pnpm --prefix e2e/studio run e2e","e2e:ui": "pnpm --prefix e2e/studio run e2e:ui",+ "e2e:docs": "pnpm --prefix e2e/docs run e2e:docs",+ "e2e:docs:ui": "pnpm --prefix e2e/docs run e2e:ui","perf:kong": "ab -t 5 -c 20 -T application/json http://localhost:8000/","perf:meta": "ab -t 5 -c 20 -T application/json http://localhost:5555/tables","setup:cli": "supabase start -x studio && supabase status --output json > keys.json && node scripts/generateLocalEnv.js",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex c64b8b7953d..3a8f291d2a4 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2007,6 +2007,12 @@ importers:specifier: ^7.3.2version: 7.3.5(@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])+ e2e/docs:+ dependencies:+ '@playwright/test':+ specifier: ^1.59.1+ version: 1.59.1+e2e/studio:dependencies:'@playwright/test':