|
| 1 | +# E2E Testing with Playwright |
| 2 | + |
| 3 | +This directory contains end-to-end tests for the SQLMesh VS Code extension using Playwright. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +1. **Install dependencies:** |
| 8 | + ```bash |
| 9 | + pnpm install |
| 10 | + ``` |
| 11 | + |
| 12 | +2. **Download VS Code executable (one-time setup):** |
| 13 | + ```bash |
| 14 | + pnpm run fetch-vscode |
| 15 | + ``` |
| 16 | + |
| 17 | + This downloads VS Code and caches it in `.vscode-test/` directory. The paths are saved to `.vscode-test/paths.json` for Playwright to use. |
| 18 | + |
| 19 | +3. **Install Playwright browsers:** |
| 20 | + ```bash |
| 21 | + npx playwright install |
| 22 | + ``` |
| 23 | + |
| 24 | +## Running Tests |
| 25 | + |
| 26 | +- **Run all E2E tests:** |
| 27 | + ```bash |
| 28 | + pnpm run test:e2e |
| 29 | + ``` |
| 30 | + |
| 31 | +- **Run tests with UI (interactive):** |
| 32 | + ```bash |
| 33 | + pnpm run test:e2e:ui |
| 34 | + ``` |
| 35 | + |
| 36 | +- **Run tests in headed mode (visible browser):** |
| 37 | + ```bash |
| 38 | + pnpm run test:e2e:headed |
| 39 | + ``` |
| 40 | + |
| 41 | +## Test Structure |
| 42 | + |
| 43 | +- `scripts/fetch-vscode.ts` - Downloads and caches VS Code executable |
| 44 | +- `playwright.config.ts` - Playwright configuration for Electron testing |
| 45 | +- `tests/webview.e2e.spec.ts` - E2E tests for webview panels |
| 46 | + |
| 47 | +## How It Works |
| 48 | + |
| 49 | +1. **VS Code as Electron app:** Playwright launches VS Code as an Electron application with the extension loaded in development mode |
| 50 | +2. **Extension isolation:** Each test runs with a fresh user data directory (`/tmp/vscode-test`) |
| 51 | +3. **Webview testing:** Tests can interact with webview content using frame locators |
| 52 | +4. **Visual regression:** Screenshots are captured and compared for pixel-perfect testing |
| 53 | + |
| 54 | +## CI/CD |
| 55 | + |
| 56 | +- The `.vscode-test` directory should be cached in CI to avoid re-downloading VS Code |
| 57 | +- Tests run in headless mode by default in CI environments |
| 58 | +- Screenshots are stored as test artifacts for comparison |
| 59 | + |
| 60 | +## Adding New Tests |
| 61 | + |
| 62 | +Create new test files in the `tests/` directory following the pattern: |
| 63 | + |
| 64 | +```typescript |
| 65 | +import { test, expect, _electron as electron } from '@playwright/test'; |
| 66 | +import path from 'path'; |
| 67 | +import fs from 'fs-extra'; |
| 68 | + |
| 69 | +const VS_CODE_EXE = fs.readJsonSync('.vscode-test/paths.json').executablePath; |
| 70 | +const EXT_PATH = path.join(__dirname, '..'); |
| 71 | + |
| 72 | +test('my new test', async () => { |
| 73 | + const electronApp = await electron.launch({ |
| 74 | + executablePath: VS_CODE_EXE, |
| 75 | + args: [ |
| 76 | + `--extensionDevelopmentPath=${EXT_PATH}`, |
| 77 | + '--disable-workspace-trust', |
| 78 | + '--disable-telemetry', |
| 79 | + '--user-data-dir=/tmp/vscode-test', |
| 80 | + ], |
| 81 | + }); |
| 82 | + |
| 83 | + const window = await electronApp.firstWindow(); |
| 84 | + |
| 85 | + // Your test logic here... |
| 86 | + |
| 87 | + await electronApp.close(); |
| 88 | +}); |
| 89 | +``` |
0 commit comments