|
| 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