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 Sep 19, 2023
1 parent 2c07144 commit 76a7ae7
Show file tree
Hide file tree
Showing 9 changed files with 49 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
5 changes: 3 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
2 changes: 1 addition & 1 deletion src/core/classes/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 76a7ae7

Please sign in to comment.