diff --git a/.gitignore b/.gitignore index fc3a09f..0d394f2 100644 --- a/.gitignore +++ b/.gitignore @@ -45,5 +45,9 @@ wxwidgets-clean/ /tests/wasm-app/standalone/*/*.js /tests/wasm-app/standalone/*/*.html /tests/wasm-app/standalone/*/*.wasm +/tests/wasm-app/kicad/*.js +/tests/wasm-app/kicad/*.wasm +!tests/wasm-app/kicad/pcbnew.html /temp/ *.log +*.tmp diff --git a/tests/e2e/kicad/pcbnew-load.spec.ts b/tests/e2e/kicad/pcbnew-load.spec.ts new file mode 100644 index 0000000..c4b569c --- /dev/null +++ b/tests/e2e/kicad/pcbnew-load.spec.ts @@ -0,0 +1,96 @@ +import { test, expect } from '../utils/fixtures'; + +test.describe('KiCad PCBnew WASM', () => { + + test('WASM runtime initializes', async ({ page, testLogger }) => { + // Navigate to KiCad app + await page.goto('/kicad/pcbnew.html'); + + // Wait for runtime initialization (longer timeout for KiCad - 15MB WASM) + await page.waitForFunction(() => { + return document.querySelector('#canvas')?.style.display === 'block'; + }, { timeout: 120000 }); // 2 min timeout for large WASM + + // Verify canvas is visible + const canvas = page.locator('#canvas'); + await expect(canvas).toBeVisible(); + + // Check for successful initialization logs + const initLog = testLogger.consoleLogs.find(l => + l.includes('[KICAD] Runtime initialized') + ); + expect(initLog).toBeTruthy(); + + // Check that app started creating + const appLog = testLogger.consoleLogs.find(l => + l.includes('[KICAD_OUT] Creating app') + ); + expect(appLog).toBeTruthy(); + + // Take screenshot of initial state + await page.screenshot({ + path: 'test-results/kicad-pcbnew-01-initial.png', + fullPage: true + }); + + // Log any errors for debugging (but don't fail on WASM exceptions yet) + const errors = testLogger.errors.filter(e => + !e.includes('favicon') && + !e.includes('SharedArrayBuffer') + ); + + if (errors.length > 0) { + console.log('Errors during initialization:', errors); + } + + // For now, we expect initialization errors due to incomplete port + // The test passes if runtime initializes - we track errors for debugging + }); + + test('canvas is properly sized', async ({ page }) => { + await page.goto('/kicad/pcbnew.html'); + + // Wait for load + await page.waitForFunction(() => { + return document.querySelector('#canvas')?.style.display === 'block'; + }, { timeout: 120000 }); + + // Wait for initial render + await page.waitForTimeout(2000); + + // Get canvas and verify it's sized properly + const canvas = page.locator('#canvas'); + const box = await canvas.boundingBox(); + expect(box).toBeTruthy(); + expect(box!.width).toBeGreaterThan(100); + expect(box!.height).toBeGreaterThan(100); + + // Screenshot for visual inspection + await page.screenshot({ + path: 'test-results/kicad-pcbnew-02-rendered.png', + fullPage: true + }); + }); + + // This test documents the current state - expect to fail until port is complete + test.skip('loads without errors', async ({ page, testLogger }) => { + await page.goto('/kicad/pcbnew.html'); + + await page.waitForFunction(() => { + return document.querySelector('#canvas')?.style.display === 'block'; + }, { timeout: 120000 }); + + await page.waitForTimeout(2000); + + // Check for errors + const errors = testLogger.errors.filter(e => + !e.includes('favicon') && + !e.includes('SharedArrayBuffer') + ); + + // This will fail until KiCad WASM port is complete + // Current known issue: WASM exception during wxWidgets initialization + expect(errors).toHaveLength(0); + }); + +}); diff --git a/tests/package.json b/tests/package.json index 033952e..2fd3cdd 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,13 +1,16 @@ { "name": "kicad-wasm-tests", "version": "1.0.0", - "description": "Playwright tests for wxWidgets WASM port", + "description": "Playwright tests for wxWidgets WASM and KiCad", "scripts": { "test": "playwright test", "test:ui": "playwright test --ui", "test:headed": "playwright test --headed", "build-wasm": "cd wasm-app && make -f Makefile.wasm", - "serve": "npx serve wasm-app -p 8080" + "serve": "npx serve wasm-app -p 8080 -c ../serve.json", + "setup:kicad": "./scripts/setup-kicad-wasm.sh", + "test:kicad": "playwright test kicad/", + "test:kicad:headed": "playwright test kicad/ --headed" }, "devDependencies": { "@playwright/test": "^1.40.0", diff --git a/tests/playwright.config.ts b/tests/playwright.config.ts index d546fef..8cbfbaa 100644 --- a/tests/playwright.config.ts +++ b/tests/playwright.config.ts @@ -72,7 +72,7 @@ export default defineConfig({ ], webServer: { - command: `npx serve wasm-app -p ${port}`, + command: `npx serve wasm-app -p ${port} -c ../serve.json`, port: port, reuseExistingServer: !process.env.CI, }, diff --git a/tests/scripts/setup-kicad-wasm.sh b/tests/scripts/setup-kicad-wasm.sh new file mode 100755 index 0000000..c66bde8 --- /dev/null +++ b/tests/scripts/setup-kicad-wasm.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Copies KiCad WASM build output from Docker volume to test directory + +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +KICAD_TEST="$PROJECT_ROOT/tests/wasm-app/kicad" + +mkdir -p "$KICAD_TEST" + +echo "Copying KiCad WASM files from Docker build..." +docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \ + kicad-wasm-builder:/workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.js "$KICAD_TEST/" +docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \ + kicad-wasm-builder:/workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.wasm "$KICAD_TEST/" + +# Worker file for pthreads (if exists) +docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \ + kicad-wasm-builder:/workspace/build-wasm/kicad-pcbnew/pcbnew/pcbnew.worker.js "$KICAD_TEST/" 2>/dev/null || true + +# wxWidgets WASM JavaScript glue code (defines JS functions called from WASM) +echo "Copying wxWidgets WASM glue code..." +cp "$PROJECT_ROOT/wxwidgets/build/wasm/wx.js" "$KICAD_TEST/" + +echo "KiCad WASM files copied to $KICAD_TEST" +ls -lh "$KICAD_TEST" diff --git a/tests/serve.json b/tests/serve.json new file mode 100644 index 0000000..035b913 --- /dev/null +++ b/tests/serve.json @@ -0,0 +1,11 @@ +{ + "headers": [ + { + "source": "**/*", + "headers": [ + { "key": "Cross-Origin-Opener-Policy", "value": "same-origin" }, + { "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" } + ] + } + ] +} diff --git a/tests/wasm-app/kicad/pcbnew.html b/tests/wasm-app/kicad/pcbnew.html new file mode 100644 index 0000000..01febb1 --- /dev/null +++ b/tests/wasm-app/kicad/pcbnew.html @@ -0,0 +1,160 @@ + + +
+ + +