Skip to content

Commit

Permalink
test: add basic a test case using playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Aug 15, 2023
1 parent 125f6ec commit e67dddc
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -50,6 +51,7 @@
"@arianrhodsandlot/eslint-config": "0.8.0",
"@iconify/json": "2.2.102",
"@iconify/tailwind": "0.1.3",
"@playwright/test": "1.36.2",
"@sergeymakinen/vite-plugin-html-minimize": "1.0.6",
"@tailwindcss/typography": "0.5.9",
"@types/emscripten": "1.39.7",
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/classes/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ 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.canvas.dataset.testid = 'emulator'
updateStyle(this.canvas, {
backgroundColor: 'black',
backgroundImage:
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/setup-wizard/local-file-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function LocalFileButton() {

return (
<>
<BaseButton className='w-60' onClick={onClick}>
<BaseButton className='w-60' data-testid='select-a-rom' onClick={onClick}>
<span className='icon-[mdi--zip-box-outline] h-5 w-5' />
{state.loading ? (
<>
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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 },
})
14 changes: 14 additions & 0 deletions tests/e2e/setup-wizard/single-rom.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/roms/nes/240p Test Suite.zip
Binary file not shown.

0 comments on commit e67dddc

Please sign in to comment.