Skip to content

Commit e072717

Browse files
committed
Add docs API reference smoke test
The API reference had been crashing after hydration because we relied on CJS component shims that loaded a second copy of the docs plugin contexts. We already patched the runtime and aliased Docusaurus to fix the bug, but there was nothing preventing regressions. This commit adds a dedicated Playwright config and test that builds the docs site, serves the static bundle, loads /wordpress-playground/api, and fails if hydration throws page or console errors. A new Nx target and CI job run the smoke test with Chromium so every PR proves the API docs render before we deploy.
1 parent e0a6b0d commit e072717

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ jobs:
254254
path: packages/playground/components/playwright-report/
255255
if-no-files-found: ignore
256256

257+
test-docs-api-reference:
258+
runs-on: ubuntu-latest
259+
steps:
260+
- uses: actions/checkout@v4
261+
with:
262+
submodules: true
263+
- uses: ./.github/actions/prepare-playground
264+
- name: Install Playwright Browsers
265+
run: npx playwright install --with-deps chromium
266+
- name: Verify docs API reference
267+
run: npx nx run docs-site:api-e2e
268+
257269
test-built-npm-packages:
258270
runs-on: ubuntu-latest
259271
steps:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
const port = process.env.DOCS_E2E_PORT ?? '4173';
4+
const host = process.env.DOCS_E2E_HOST ?? '127.0.0.1';
5+
const baseUrl = process.env.DOCS_E2E_BASE_URL ?? `http://${host}:${port}`;
6+
7+
export default defineConfig({
8+
testDir: './tests',
9+
timeout: 60_000,
10+
expect: {
11+
timeout: 10_000,
12+
},
13+
use: {
14+
baseURL: baseUrl,
15+
trace: 'retain-on-failure',
16+
screenshot: 'only-on-failure',
17+
video: 'retain-on-failure',
18+
},
19+
webServer: {
20+
command: `npx http-server dist/docs/build -p ${port} -c-1`,
21+
url: `${baseUrl}/wordpress-playground/`,
22+
reuseExistingServer: !process.env.CI,
23+
timeout: 120_000,
24+
},
25+
});

packages/docs/site/project.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
},
8080
"dependsOn": ["build:json"]
8181
},
82+
"api-e2e": {
83+
"executor": "nx:run-commands",
84+
"options": {
85+
"commands": [
86+
"npm run build:docs",
87+
"npx playwright test --config=packages/docs/site/playwright.config.ts --project=chromium"
88+
],
89+
"parallel": false
90+
}
91+
},
8292
"lint": {
8393
"executor": "@nx/linter:eslint",
8494
"outputs": ["{options.outputFile}"],
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Docs API reference', () => {
4+
test('loads without runtime errors', async ({ page }) => {
5+
const pageErrors: Error[] = [];
6+
const consoleErrors: string[] = [];
7+
8+
page.on('pageerror', (error) => {
9+
pageErrors.push(error);
10+
});
11+
12+
page.on('console', (message) => {
13+
if (message.type() === 'error') {
14+
const text = message.text();
15+
// Ignore benign production React hint that is injected in dev.
16+
if (text.includes('Download the React DevTools')) {
17+
return;
18+
}
19+
consoleErrors.push(text);
20+
}
21+
});
22+
23+
await page.goto('/wordpress-playground/api', {
24+
waitUntil: 'networkidle',
25+
});
26+
await expect(page.locator('.apiPage')).toBeVisible();
27+
28+
expect(
29+
pageErrors,
30+
pageErrors.map((error) => error.message).join('\n')
31+
).toHaveLength(0);
32+
expect(consoleErrors, consoleErrors.join('\n')).toHaveLength(0);
33+
});
34+
});

0 commit comments

Comments
 (0)