diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..5387bd7 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,21 @@ +name: test +on: [push] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: true + + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: pnpm + + - run: pnpm lint + - run: pnpm playwright install + - run: pnpm t diff --git a/package.json b/package.json index e637878..5d7ffd8 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "scripts": { "dev": "vite", "build": "vite build", - "preview": "vite preview", - "lint": "eslint src" + "preview": "vite build && vite preview", + "lint": "eslint src", + "test": "playwright test -c tests/e2e" }, "dependencies": { "@fontsource-variable/fredoka": "5.0.8", diff --git a/src/core/classes/emulator.ts b/src/core/classes/emulator.ts index 907a541..cbd884f 100644 --- a/src/core/classes/emulator.ts +++ b/src/core/classes/emulator.ts @@ -149,13 +149,13 @@ export class Emulator { this.core = core ?? '' this.canvas = document.createElement('canvas') this.canvas.id = 'canvas' - this.canvas.hidden = true this.canvas.width = 900 this.canvas.height = 900 this.previousActiveElement = document.activeElement this.canvas.tabIndex = 0 this.coreConfig = coreConfig this.retroarchConfig = retroarchConfig + this.canvas.dataset.testid = 'emulator' updateStyle(this.canvas, { backgroundColor: 'black', backgroundImage: diff --git a/src/views/components/setup-wizard/local-file-button.tsx b/src/views/components/setup-wizard/local-file-button.tsx index ecd66ad..bcfed5f 100644 --- a/src/views/components/setup-wizard/local-file-button.tsx +++ b/src/views/components/setup-wizard/local-file-button.tsx @@ -38,7 +38,7 @@ export function LocalFileButton() { return ( <> - + {state.loading ? ( <> diff --git a/tests/e2e/playwright.config.ts b/tests/e2e/playwright.config.ts new file mode 100644 index 0000000..c8dcd31 --- /dev/null +++ b/tests/e2e/playwright.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from '@playwright/test' + +export default defineConfig({ + testDir: '.', + snapshotDir: 'snapshots', + snapshotPathTemplate: '{snapshotDir}/{testFilePath}/{testName}-{arg}{ext}', + use: { baseURL: 'http://localhost:5173', trace: 'on-first-retry' }, + webServer: { command: 'pnpm dev', url: 'http://127.0.0.1:5173', reuseExistingServer: true }, +}) diff --git a/tests/e2e/setup-wizard/single-rom.spec.ts b/tests/e2e/setup-wizard/single-rom.spec.ts new file mode 100644 index 0000000..a574ec0 --- /dev/null +++ b/tests/e2e/setup-wizard/single-rom.spec.ts @@ -0,0 +1,14 @@ +import { expect, test } from '@playwright/test' + +test('play a single ROM file', async ({ page }) => { + await page.goto('/') + const fileChooserPromise = page.waitForEvent('filechooser') + await page.getByTestId('select-a-rom').click() + const fileChooser = await fileChooserPromise + await fileChooser.setFiles('tests/fixtures/roms/nes/240p Test Suite.zip') + + const emulator = page.getByTestId('emulator') + await page.waitForLoadState('networkidle') + await expect(emulator).toBeVisible() + await expect(emulator).toHaveScreenshot('240p Test Suite.png') +}) diff --git a/tests/e2e/snapshots/setup-wizard/setup-wizard/single-rom.spec.ts/image.png b/tests/e2e/snapshots/setup-wizard/setup-wizard/single-rom.spec.ts/image.png new file mode 100644 index 0000000..cf913d2 Binary files /dev/null and b/tests/e2e/snapshots/setup-wizard/setup-wizard/single-rom.spec.ts/image.png differ diff --git a/tests/e2e/snapshots/setup-wizard/single-rom.spec.ts/play-a-single-ROM-file-240p-Test-Suite.png b/tests/e2e/snapshots/setup-wizard/single-rom.spec.ts/play-a-single-ROM-file-240p-Test-Suite.png new file mode 100644 index 0000000..cf913d2 Binary files /dev/null and b/tests/e2e/snapshots/setup-wizard/single-rom.spec.ts/play-a-single-ROM-file-240p-Test-Suite.png differ diff --git a/tests/fixtures/roms/nes/240p Test Suite.zip b/tests/fixtures/roms/nes/240p Test Suite.zip new file mode 100644 index 0000000..a09f062 Binary files /dev/null and b/tests/fixtures/roms/nes/240p Test Suite.zip differ