Skip to content

Commit 877aa6f

Browse files
feat: enable Playwright tests in CI with proper browser and viewer setup
- Add 'Install Playwright browsers' step (chromium --with-deps) to CI workflow - Add 'Start viewer for Playwright tests' step with health-check wait loop - Remove Playwright exclusion from vitest.config.ci.ts — tests run in CI now - Expand Playwright docs guide with comprehensive CI setup (3-step walkthrough, complete GitHub Actions example, headed vs headless tip) - Add Playwright troubleshooting row to CI/CD guide Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8f92d03 commit 877aa6f

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ jobs:
3434
- name: Build all packages
3535
run: pnpm build
3636

37+
- name: Install Playwright browsers
38+
run: npx playwright install chromium --with-deps
39+
40+
- name: Start viewer for Playwright tests
41+
run: |
42+
cd packages/viewer
43+
PORT=3100 node dist/server/index.js &
44+
echo "Waiting for viewer on port 3100..."
45+
timeout 30 bash -c 'until curl -sf http://localhost:3100 > /dev/null 2>&1; do sleep 1; done'
46+
echo "Viewer is ready"
47+
3748
- name: Test vitest package
3849
run: npx vitest run --config vitest.config.ci.ts
3950
working-directory: packages/vitest

docs/docs/vitest/guides/ci-cd.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ These are generated using exactly the pipeline described above — JSON export,
274274
| `--config` ignored via pnpm | Double `--config` argument | Use `npx vitest run --config ...` directly |
275275
| Tests pass locally, fail in CI | Environment differences | Check Node.js version, use CI-specific config |
276276
| No output in CI logs | `detailLevel: 'silent'` | Use `'spec+summary+headers'` for visible output |
277+
| Playwright tests pending in CI | Missing browsers or no app running | See [Playwright CI setup](./playwright.mdx#ci-configuration) |
277278
278279
## Related
279280

docs/docs/vitest/guides/playwright.mdx

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,81 @@ export default defineConfig({
161161

162162
## CI Configuration
163163

164-
Playwright in CI requires browser binaries. Add a caching step for speed:
164+
Playwright tests in CI need two things the local environment already has:
165+
**browser binaries** and a **running application to test against**.
166+
167+
### Step 1 — Install Browsers
168+
169+
```yaml
170+
- name: Install Playwright browsers
171+
run: npx playwright install chromium --with-deps
172+
```
173+
174+
The `--with-deps` flag installs system-level libraries (fonts, codecs) that
175+
headless Chromium needs on Linux runners. Only install the browsers you actually
176+
test against — `chromium` alone is usually sufficient.
177+
178+
### Step 2 — Start Your Application
179+
180+
Playwright tests navigate to a running web app. Start it in the background
181+
before running tests:
165182

166183
```yaml
167-
# .github/workflows/ci.yml (excerpt)
168-
- name: Install Playwright
169-
run: npx playwright install --with-deps chromium
184+
- name: Start application
185+
run: |
186+
npm run start &
187+
# Wait until the server responds (up to 30 seconds)
188+
timeout 30 bash -c 'until curl -sf http://localhost:3000 > /dev/null 2>&1; do sleep 1; done'
189+
echo "Application is ready"
190+
```
191+
192+
:::caution Don't forget the wait
193+
Without the health-check loop, tests may start before the server is ready —
194+
leading to flaky connection-refused failures.
195+
:::
196+
197+
### Step 3 — Run Tests
170198

171-
- name: Run E2E tests
199+
```yaml
200+
- name: Run tests (including Playwright)
172201
run: npx vitest run --config vitest.config.ci.ts
173202
```
174203

175-
:::tip
176-
Only install the browsers you actually test against. `chromium` alone is usually
177-
sufficient — add `firefox` or `webkit` only if you need cross-browser coverage.
204+
### Complete GitHub Actions Example
205+
206+
```yaml
207+
steps:
208+
- uses: actions/checkout@v4
209+
- uses: actions/setup-node@v4
210+
with:
211+
node-version: 22
212+
213+
- run: npm ci
214+
215+
- name: Build
216+
run: npm run build
217+
218+
- name: Install Playwright browsers
219+
run: npx playwright install chromium --with-deps
220+
221+
- name: Start application
222+
run: |
223+
npm run start &
224+
timeout 30 bash -c 'until curl -sf http://localhost:3000 > /dev/null 2>&1; do sleep 1; done'
225+
226+
- name: Run tests
227+
run: npx vitest run --config vitest.config.ci.ts
228+
```
229+
230+
:::tip Headed vs headless
231+
Use the `CI` environment variable to toggle headed mode:
232+
```typescript
233+
const { page } = useBrowser({
234+
launch: { headless: process.env.CI === 'true' },
235+
});
236+
```
237+
GitHub Actions sets `CI=true` automatically, so tests run headless in CI and
238+
can optionally run headed locally for visual debugging.
178239
:::
179240

180241
## Troubleshooting

packages/vitest/vitest.config.ci.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default defineConfig({
99
globals: true,
1010
environment: 'node',
1111
include: ['_src/test/**/*.Spec.ts'],
12-
exclude: ['_src/test/Playwright/**'], // Playwright tests need a running viewer + browsers — run locally or in dedicated e2e job
1312
setupFiles: ['./_src/app/setup.ts'],
1413
pool: 'forks',
1514
fileParallelism: false,

0 commit comments

Comments
 (0)