Build a SvelteKit boilerplate with end-to-end testing using Playwright. Include a GitHub Actions workflow that spins up an ephemeral preview environment, runs E2E tests against it, and posts results as a PR comment.
Assistant
Providing complete SvelteKit boilerplate with Playwright E2E and ephemeral preview
The boilerplate includes SvelteKit setup with Playwright tests, a GitHub Actions workflow that builds, starts an ephemeral preview server on localhost, runs E2E tests against it, and posts summarized results as a PR comment. The workflow handles waiting for the server and cleans up after tests, ensuring a clean ephemeral environment per run.
Below is a minimal SvelteKit + Playwright boilerplate and a GitHub Actions workflow that:
Builds the app and spins up a preview server (ephemeral for the job)
Runs Playwright E2E tests against that server
Uploads the HTML report as an artifact
Posts a short pass/fail summary as a PR comment
You can copy the files below into a new repo (or adapt to an existing one).
name: E2E Playwright
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
jobs:
e2e:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Build
run: npm run build
- name: Start preview server (ephemeral env)
run: |
npm run preview -- --host 0.0.0.0 --port 4173 > preview.log 2>&1 &
echo $! > preview.pid
- name: Wait for server to be ready
run: npx wait-on http://127.0.0.1:4173
- name: Run Playwright E2E tests
run: npx playwright test
env:
BASE_URL: http://127.0.0.1:4173
- name: Stop preview server
if: always()
run: |
kill $(cat preview.pid) || true
- name: Upload Playwright HTML report
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report
- name: Post PR comment with results
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const { owner, repo, number } = context.issue;
const data = JSON.parse(fs.readFileSync('playwright-report.json', 'utf8'));
// Summaries
const passed = data.stats.passed;
const failed = data.stats.failed;
const skipped = data.stats.skipped;
const status = failed > 0 ? '❌ Failed' : '✅ Passed';
// Build a short list of specs
const summaries = data.suites
.flatMap(s => s.specs)
.map(spec => {
const specFailed = spec.tests.some(t =>
t.results.some(r => r.status === 'failed')
);
return `${specFailed ? '❌' : '✅'} ${spec.title}`;
})
.join('\n');
const body = `
**Playwright E2E**: ${status}
Passed: ${passed} | Failed: ${failed} | Skipped: ${skipped}
${summaries}
(Full HTML report is available in the Actions artifacts.)
`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body
});
Usage
Clone or create a new repo, then copy the above files into place.
Run locally:
bash
npm install
npm run dev # or npm run preview after build
npm run test:e2e
Push to GitHub. On each PR, the workflow will:
build SvelteKit
start an ephemeral preview on port 4173
run Playwright tests against it
upload the HTML report
comment on the PR with a short summary
That’s it! You now have a SvelteKit boilerplate with Playwright E2E and a CI workflow that spins up a preview environment and reports results back to your pull requests.