Skip to content

Commit 21605f6

Browse files
committed
feat: add e2e tests
1 parent 10a5583 commit 21605f6

File tree

10 files changed

+1387
-0
lines changed

10 files changed

+1387
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [main, master]
5+
pull_request:
6+
branches: [main, master]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm install -g pnpm && pnpm install
18+
- name: Install Playwright Browsers
19+
run: pnpm exec playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: pnpm exec playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

cmp/compiler/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# Playwright
3+
node_modules/
4+
/test-results/
5+
/playwright-report/
6+
/blob-report/
7+
/playwright/.cache/
8+
/playwright/.auth/
9+
10+
# Translation server logs
11+
translation-server.log

cmp/compiler/playwright.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// import dotenv from 'dotenv';
8+
// import path from 'path';
9+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
10+
11+
/**
12+
* See https://playwright.dev/docs/test-configuration.
13+
*/
14+
export default defineConfig({
15+
testDir: "./tests",
16+
fullyParallel: false,
17+
/* Fail the build on CI if you accidentally left test.only in the source code. */
18+
forbidOnly: !!process.env.CI,
19+
/* Retry on CI only */
20+
retries: process.env.CI ? 2 : 0,
21+
/* Run tests sequentially with a single worker */
22+
workers: 1,
23+
/* Timeout for each test (includes beforeAll/afterAll hooks) */
24+
timeout: 180000, // 3 minutes - accounts for packing compiler, installing deps, starting servers
25+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26+
reporter: "html",
27+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
28+
use: {
29+
/* Base URL to use in actions like `await page.goto('')`. */
30+
// baseURL: 'http://localhost:3000',
31+
32+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
33+
trace: "on-first-retry",
34+
/* Action timeout (individual page actions like click, fill, etc) */
35+
actionTimeout: 30000, // 30 seconds for individual actions
36+
},
37+
38+
/* Configure projects for major browsers */
39+
projects: [
40+
{
41+
name: "chromium",
42+
use: { ...devices["Desktop Chrome"] },
43+
},
44+
],
45+
46+
/* Run your local dev server before starting the tests */
47+
// webServer: {
48+
// command: 'npm run start',
49+
// url: 'http://localhost:3000',
50+
// reuseExistingServer: !process.env.CI,
51+
// },
52+
});

cmp/compiler/tests/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Playwright artifacts
2+
playwright-report/
3+
test-results/
4+
5+
# Prepared fixtures (with node_modules)
6+
fixtures/

cmp/compiler/tests/QUICK_START.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# E2E Tests - Quick Start
2+
3+
## First Time Setup (5 minutes)
4+
5+
```bash
6+
# 1. Install dependencies
7+
pnpm install
8+
9+
# 2. Install Playwright browsers
10+
pnpm playwright:install
11+
12+
# 3. Prepare test fixtures (takes 2-3 minutes)
13+
pnpm test:prepare
14+
```
15+
16+
## Running Tests
17+
18+
```bash
19+
# Run all tests
20+
pnpm test:e2e
21+
22+
# Run in interactive UI mode (recommended for development)
23+
pnpm test:e2e:dev
24+
25+
# Run only shared tests
26+
pnpm test:e2e:shared
27+
28+
# Debug a specific test
29+
pnpm test:e2e:debug
30+
```
31+
32+
## How It Works
33+
34+
### Fast Test Execution Strategy
35+
36+
Instead of installing dependencies on every test run, we use a two-stage approach:
37+
38+
```
39+
┌─────────────────────────────────────────────────────────────┐
40+
│ Stage 1: Preparation (ONE TIME - run pnpm test:prepare) │
41+
├─────────────────────────────────────────────────────────────┤
42+
│ │
43+
│ demo/next16/ ──────┐ │
44+
│ ├──> tests/fixtures/next/ │
45+
│ + pnpm install ────┘ (with node_modules) │
46+
│ │
47+
│ demo/vite/ ──────┐ │
48+
│ ├──> tests/fixtures/vite/ │
49+
│ + pnpm install ────┘ (with node_modules) │
50+
│ │
51+
└─────────────────────────────────────────────────────────────┘
52+
53+
┌─────────────────────────────────────────────────────────────┐
54+
│ Stage 2: Test Execution (FAST - every test run) │
55+
├─────────────────────────────────────────────────────────────┤
56+
│ │
57+
│ tests/fixtures/next/ ──> /tmp/lingo-test-next-xyz/ │
58+
│ (copy with node_modules) (isolated test environment) │
59+
│ │
60+
│ ✅ No dependency installation needed │
61+
│ ✅ Each test gets clean copy │
62+
│ ✅ Fast execution (~seconds per test) │
63+
│ │
64+
└─────────────────────────────────────────────────────────────┘
65+
```
66+
67+
### Why This Approach?
68+
69+
**Without preparation:**
70+
71+
- ❌ Install deps on every test: ~2-3 min per test
72+
- ❌ Total test time: ~10-15 minutes for 5 tests
73+
74+
**With preparation:**
75+
76+
- ✅ Prepare once: ~2-3 minutes (one time)
77+
- ✅ Each test: ~10-30 seconds
78+
- ✅ Total test time: ~2-5 minutes for 5 tests
79+
80+
**10x faster test execution!**
81+
82+
## When to Re-run `pnpm test:prepare`
83+
84+
- When demo app `package.json` changes
85+
- When you update demo app dependencies
86+
- After pulling major changes to demo apps
87+
- If fixtures get corrupted
88+
89+
## Directory Structure
90+
91+
```
92+
tests/
93+
├── fixtures/ # ← Prepared fixtures (gitignored)
94+
│ ├── next/ # ← Next.js with node_modules
95+
│ └── vite/ # ← Vite with node_modules
96+
├── e2e/
97+
│ └── shared/
98+
│ └── development.test.ts
99+
└── helpers/
100+
├── prepare-fixtures.ts # ← Prepares fixtures
101+
└── setup-fixture.ts # ← Copies fixtures to temp dir
102+
```
103+
104+
## Example Test Flow
105+
106+
```typescript
107+
import { setupFixture } from "../../helpers/setup-fixture";
108+
109+
test("my test", async ({ page }) => {
110+
// 1. Copy prepared fixture to temp dir (fast - already has node_modules)
111+
const fixture = await setupFixture({ framework: "next" });
112+
113+
// 2. Start dev server (dependencies already installed)
114+
const devServer = await fixture.startDev();
115+
116+
try {
117+
// 3. Run your test
118+
await page.goto(`http://localhost:${devServer.port}`);
119+
// ... test assertions ...
120+
} finally {
121+
// 4. Cleanup
122+
devServer.stop();
123+
await fixture.clean();
124+
}
125+
});
126+
```
127+
128+
## CI/CD Integration
129+
130+
In CI, run both stages:
131+
132+
```yaml
133+
- name: Prepare fixtures
134+
run: pnpm test:prepare
135+
136+
- name: Run E2E tests
137+
run: pnpm test:e2e
138+
```
139+
140+
You could also cache the `tests/fixtures/` directory to speed up CI runs.

0 commit comments

Comments
 (0)