GeezerVison is showing github.com — test(app): initial e2e test setup · iyoda/opencode@03d7467
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/test.yml +63Lines changed: 63 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | - name: Setup Bun | 19 | 19 | uses: ./.github/actions/setup-bun | 20 | 20 |
| | 21 | + - name: Install Playwright browsers | | 22 | + run: bun --cwd packages/app x playwright install --with-deps | | 23 | + | | 24 | + - name: Seed opencode data | | 25 | + run: bun --cwd packages/opencode script/seed-e2e.ts | | 26 | + env: | | 27 | + MODELS_DEV_API_JSON: ${{ github.workspace }}/packages/opencode/test/tool/fixtures/models-api.json | | 28 | + OPENCODE_DISABLE_MODELS_FETCH: "true" | | 29 | + OPENCODE_DISABLE_SHARE: "true" | | 30 | + OPENCODE_DISABLE_LSP_DOWNLOAD: "true" | | 31 | + OPENCODE_DISABLE_DEFAULT_PLUGINS: "true" | | 32 | + OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: "true" | | 33 | + OPENCODE_TEST_HOME: ${{ runner.temp }}/opencode-e2e/home | | 34 | + XDG_DATA_HOME: ${{ runner.temp }}/opencode-e2e/share | | 35 | + XDG_CACHE_HOME: ${{ runner.temp }}/opencode-e2e/cache | | 36 | + XDG_CONFIG_HOME: ${{ runner.temp }}/opencode-e2e/config | | 37 | + XDG_STATE_HOME: ${{ runner.temp }}/opencode-e2e/state | | 38 | + OPENCODE_E2E_PROJECT_DIR: ${{ github.workspace }} | | 39 | + OPENCODE_E2E_SESSION_TITLE: "E2E Session" | | 40 | + OPENCODE_E2E_MESSAGE: "Seeded for UI e2e" | | 41 | + OPENCODE_E2E_MODEL: "opencode/gpt-5-nano" | | 42 | + | | 43 | + - name: Run opencode server | | 44 | + run: bun --cwd packages/opencode run dev -- --print-logs --log-level WARN serve --port 4096 --hostname 0.0.0.0 & | | 45 | + env: | | 46 | + MODELS_DEV_API_JSON: ${{ github.workspace }}/packages/opencode/test/tool/fixtures/models-api.json | | 47 | + OPENCODE_DISABLE_MODELS_FETCH: "true" | | 48 | + OPENCODE_DISABLE_SHARE: "true" | | 49 | + OPENCODE_DISABLE_LSP_DOWNLOAD: "true" | | 50 | + OPENCODE_DISABLE_DEFAULT_PLUGINS: "true" | | 51 | + OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: "true" | | 52 | + OPENCODE_TEST_HOME: ${{ runner.temp }}/opencode-e2e/home | | 53 | + XDG_DATA_HOME: ${{ runner.temp }}/opencode-e2e/share | | 54 | + XDG_CACHE_HOME: ${{ runner.temp }}/opencode-e2e/cache | | 55 | + XDG_CONFIG_HOME: ${{ runner.temp }}/opencode-e2e/config | | 56 | + XDG_STATE_HOME: ${{ runner.temp }}/opencode-e2e/state | | 57 | + OPENCODE_CLIENT: "app" | | 58 | + | | 59 | + - name: Wait for opencode server | | 60 | + run: | | | 61 | + for i in {1..60}; do | | 62 | + curl -fsS "http://localhost:4096/global/health" > /dev/null && exit 0 | | 63 | + sleep 1 | | 64 | + done | | 65 | + exit 1 | | 66 | +
| 21 | 67 | - name: run | 22 | 68 | run: | | 23 | 69 | | | 26 | 72 | bun turbo test | 27 | 73 | env: | 28 | 74 | CI: true | | 75 | + MODELS_DEV_API_JSON: ${{ github.workspace }}/packages/opencode/test/tool/fixtures/models-api.json | | 76 | + OPENCODE_DISABLE_MODELS_FETCH: "true" | | 77 | + OPENCODE_DISABLE_SHARE: "true" | | 78 | + OPENCODE_DISABLE_LSP_DOWNLOAD: "true" | | 79 | + OPENCODE_DISABLE_DEFAULT_PLUGINS: "true" | | 80 | + OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: "true" | | 81 | + OPENCODE_TEST_HOME: ${{ runner.temp }}/opencode-e2e/home | | 82 | + XDG_DATA_HOME: ${{ runner.temp }}/opencode-e2e/share | | 83 | + XDG_CACHE_HOME: ${{ runner.temp }}/opencode-e2e/cache | | 84 | + XDG_CONFIG_HOME: ${{ runner.temp }}/opencode-e2e/config | | 85 | + XDG_STATE_HOME: ${{ runner.temp }}/opencode-e2e/state | | 86 | + PLAYWRIGHT_SERVER_HOST: "localhost" | | 87 | + PLAYWRIGHT_SERVER_PORT: "4096" | | 88 | + VITE_OPENCODE_SERVER_HOST: "localhost" | | 89 | + VITE_OPENCODE_SERVER_PORT: "4096" | | 90 | + OPENCODE_CLIENT: "app" | | 91 | + timeout-minutes: 30 |
Collapse file Copy file name to clipboardExpand all lines: bun.lock +10Lines changed: 10 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 44 | 44 | "luxon": "3.6.1", | 45 | 45 | "marked": "17.0.1", | 46 | 46 | "marked-shiki": "1.2.1", | | 47 | + "@playwright/test": "1.51.0", | 47 | 48 | "typescript": "5.8.2", | 48 | 49 | "@typescript/native-preview": "7.0.0-dev.20251207.1", | 49 | 50 | "zod": "4.1.8", | |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | src/assets/theme.css | | 2 | +e2e/test-results | | 3 | +e2e/playwright-report |
Collapse file Copy file name to clipboardExpand all lines: packages/app/README.md +15Lines changed: 15 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,21 @@ It correctly bundles Solid in production mode and optimizes the build for the be | 29 | 29 | The build is minified and the filenames include the hashes.<br> | 30 | 30 | Your app is ready to be deployed! | 31 | 31 |
| | 32 | +## E2E Testing | | 33 | + | | 34 | +The Playwright runner expects the app already running at `http://localhost:3000`. | | 35 | + | | 36 | +```bash | | 37 | +bun add -D @playwright/test | | 38 | +bunx playwright install | | 39 | +bun run test:e2e | | 40 | +``` | | 41 | + | | 42 | +Environment options: | | 43 | + | | 44 | +- `PLAYWRIGHT_BASE_URL` (default: `http://localhost:3000`) | | 45 | +- `PLAYWRIGHT_PORT` (default: `3000`) | | 46 | + | 32 | 47 | ## Deployment | 33 | 48 |
| 34 | 49 | You can deploy the `dist` folder to any static host provider (netlify, surge, now, etc.) |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { test, expect } from "@playwright/test" | | 2 | + | | 3 | +test("home shows recent projects header", async ({ page }) => { | | 4 | + await page.goto("/") | | 5 | + await expect(page.getByText("Recent projects")).toBeVisible() | | 6 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/app/package.json +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | "start": "vite", | 13 | 13 | "dev": "vite", | 14 | 14 | "build": "vite build", | 15 | | - "serve": "vite preview" | | 15 | + "serve": "vite preview", | | 16 | + "test": "playwright test", | | 17 | + "test:e2e": "playwright test", | | 18 | + "test:e2e:ui": "playwright test --ui", | | 19 | + "test:e2e:report": "playwright show-report e2e/playwright-report" | 16 | 20 | }, | 17 | 21 | "license": "MIT", | 18 | 22 | "devDependencies": { | 19 | 23 | "@happy-dom/global-registrator": "20.0.11", | | 24 | + "@playwright/test": "1.57.0", | 20 | 25 | "@tailwindcss/vite": "catalog:", | 21 | 26 | "@tsconfig/bun": "1.0.9", | 22 | 27 | "@types/bun": "catalog:", | |
Collapse file Copy file name to clipboard +43Lines changed: 43 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { defineConfig, devices } from "@playwright/test" | | 2 | + | | 3 | +const port = Number(process.env.PLAYWRIGHT_PORT ?? 3000) | | 4 | +const baseURL = process.env.PLAYWRIGHT_BASE_URL ?? `http://localhost:${port}` | | 5 | +const serverHost = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost" | | 6 | +const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096" | | 7 | +const command = `bun run dev -- --host 0.0.0.0 --port ${port}` | | 8 | +const reuse = !process.env.CI | | 9 | + | | 10 | +export default defineConfig({ | | 11 | + testDir: "./e2e", | | 12 | + outputDir: "./e2e/test-results", | | 13 | + timeout: 60_000, | | 14 | + expect: { | | 15 | + timeout: 10_000, | | 16 | + }, | | 17 | + fullyParallel: true, | | 18 | + forbidOnly: !!process.env.CI, | | 19 | + retries: process.env.CI ? 2 : 0, | | 20 | + reporter: [["html", { outputFolder: "e2e/playwright-report", open: "never" }], ["line"]], | | 21 | + webServer: { | | 22 | + command, | | 23 | + url: baseURL, | | 24 | + reuseExistingServer: reuse, | | 25 | + timeout: 120_000, | | 26 | + env: { | | 27 | + VITE_OPENCODE_SERVER_HOST: serverHost, | | 28 | + VITE_OPENCODE_SERVER_PORT: serverPort, | | 29 | + }, | | 30 | + }, | | 31 | + use: { | | 32 | + baseURL, | | 33 | + trace: "on-first-retry", | | 34 | + screenshot: "only-on-failure", | | 35 | + video: "retain-on-failure", | | 36 | + }, | | 37 | + projects: [ | | 38 | + { | | 39 | + name: "chromium", | | 40 | + use: { ...devices["Desktop Chrome"] }, | | 41 | + }, | | 42 | + ], | | 43 | +}) |
Collapse file Copy file name to clipboard +50Lines changed: 50 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +const dir = process.env.OPENCODE_E2E_PROJECT_DIR ?? process.cwd() | | 2 | +const title = process.env.OPENCODE_E2E_SESSION_TITLE ?? "E2E Session" | | 3 | +const text = process.env.OPENCODE_E2E_MESSAGE ?? "Seeded for UI e2e" | | 4 | +const model = process.env.OPENCODE_E2E_MODEL ?? "opencode/gpt-5-nano" | | 5 | +const parts = model.split("/") | | 6 | +const providerID = parts[0] ?? "opencode" | | 7 | +const modelID = parts[1] ?? "gpt-5-nano" | | 8 | +const now = Date.now() | | 9 | + | | 10 | +const seed = async () => { | | 11 | + const { Instance } = await import("../src/project/instance") | | 12 | + const { InstanceBootstrap } = await import("../src/project/bootstrap") | | 13 | + const { Session } = await import("../src/session") | | 14 | + const { Identifier } = await import("../src/id/id") | | 15 | + const { Project } = await import("../src/project/project") | | 16 | + | | 17 | + await Instance.provide({ | | 18 | + directory: dir, | | 19 | + init: InstanceBootstrap, | | 20 | + fn: async () => { | | 21 | + const session = await Session.create({ title }) | | 22 | + const messageID = Identifier.descending("message") | | 23 | + const partID = Identifier.descending("part") | | 24 | + const message = { | | 25 | + id: messageID, | | 26 | + sessionID: session.id, | | 27 | + role: "user" as const, | | 28 | + time: { created: now }, | | 29 | + agent: "build", | | 30 | + model: { | | 31 | + providerID, | | 32 | + modelID, | | 33 | + }, | | 34 | + } | | 35 | + const part = { | | 36 | + id: partID, | | 37 | + sessionID: session.id, | | 38 | + messageID, | | 39 | + type: "text" as const, | | 40 | + text, | | 41 | + time: { start: now }, | | 42 | + } | | 43 | + await Session.updateMessage(message) | | 44 | + await Session.updatePart(part) | | 45 | + await Project.update({ projectID: Instance.project.id, name: "E2E Project" }) | | 46 | + }, | | 47 | + }) | | 48 | +} | | 49 | + | | 50 | +await seed() |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/share/share-next.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,10 @@ export namespace ShareNext { | 15 | 15 | return Config.get().then((x) => x.enterprise?.url ?? "https://opncd.ai") | 16 | 16 | } | 17 | 17 |
| | 18 | + const disabled = process.env["OPENCODE_DISABLE_SHARE"] === "true" || process.env["OPENCODE_DISABLE_SHARE"] === "1" | | 19 | + | 18 | 20 | export async function init() { | | 21 | + if (disabled) return | 19 | 22 | Bus.subscribe(Session.Event.Updated, async (evt) => { | 20 | 23 | await sync(evt.properties.info.id, [ | 21 | 24 | { | @@ -63,6 +66,7 @@ export namespace ShareNext { | 63 | 66 | } | 64 | 67 |
| 65 | 68 | export async function create(sessionID: string) { | | 69 | + if (disabled) return { id: "", url: "", secret: "" } | 66 | 70 | log.info("creating share", { sessionID }) | 67 | 71 | const result = await fetch(`${await url()}/api/share`, { | 68 | 72 | method: "POST", | @@ -110,6 +114,7 @@ export namespace ShareNext { | 110 | 114 |
| 111 | 115 | const queue = new Map<string, { timeout: NodeJS.Timeout; data: Map<string, Data> }>() | 112 | 116 | async function sync(sessionID: string, data: Data[]) { | | 117 | + if (disabled) return | 113 | 118 | const existing = queue.get(sessionID) | 114 | 119 | if (existing) { | 115 | 120 | for (const item of data) { | @@ -145,6 +150,7 @@ export namespace ShareNext { | 145 | 150 | } | 146 | 151 |
| 147 | 152 | export async function remove(sessionID: string) { | | 153 | + if (disabled) return | 148 | 154 | log.info("removing share", { sessionID }) | 149 | 155 | const share = await get(sessionID) | 150 | 156 | if (!share) return | |
|