Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Nov 6, 2023
1 parent 3cfeaa6 commit 21a8a4b
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 167 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ jobs:
- run: pnpm playwright install chromium
- run: pnpm build
- run: pnpm test:e2e
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report
retention-days: 30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.astro
dist
node_modules
playwright-report
test-results
110 changes: 110 additions & 0 deletions tests/e2e/instance-ra-nightly.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { expect, test } from '@playwright/test'

test.describe('instance methods with nightly retroarch', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/tests/e2e/test-page/nightly.html')
})

test('save state', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await page.getByText('saveState', { exact: true }).click()
const event = await page.waitForEvent('console', (consoleMessage) => consoleMessage.type() === 'info')
const [message] = event.args()
expect(message.toString()).toBe('{state: Blob, thumbnail: Blob}')
})

test('load state', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('gbc', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('load-state-pristine.png')

await canvas.press('Enter', { delay: 500 })
await expect(canvas).toHaveScreenshot('load-state-touched.png')

await page.getByText('saveState', { exact: true }).click()
await page.waitForEvent('console', (consoleMessage) => consoleMessage.type() === 'info')

await page.getByText('restart', { exact: true }).click()
await expect(canvas).toHaveScreenshot('load-state-pristine.png')

await page.getByText('loadState', { exact: true }).click()
await page.waitForTimeout(1000) // loading state can be slow
await expect(canvas).toHaveScreenshot('load-state-touched.png')
})

test('restart', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('restart-pristine.png')

await canvas.press('Enter', { delay: 500 })
await expect(canvas).not.toHaveScreenshot('restart-pristine.png')

await page.getByText('restart', { exact: true }).click()

await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('restart-pristine.png')
})

test('pause and resume', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await canvas.press('Enter', { delay: 800 })

await page.getByText('pause', { exact: true }).click()
await expect(canvas).toHaveScreenshot('pause-and-resume.png')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('pause-and-resume.png')

await page.getByText('resume', { exact: true }).click()
await page.waitForTimeout(1000)
await expect(canvas).not.toHaveScreenshot('pause-and-resume.png')
})

test('press', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('press-pristine.png')

// show the game info
await page.getByText('pressA', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-a.png')

// hide the game info
await page.getByText('pressA', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-pristine.png')

// enter the game
await page.getByText('pressStart', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-start.png')
})
})
109 changes: 0 additions & 109 deletions tests/e2e/instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,112 +108,3 @@ test.describe('instance methods', () => {
await expect(canvas).toHaveScreenshot('press-start.png')
})
})

test.describe('instance methods with nightly retroarch', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/tests/e2e/test-page/nightly.html')
})

test('save state', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await page.getByText('saveState', { exact: true }).click()
const event = await page.waitForEvent('console', (consoleMessage) => consoleMessage.type() === 'info')
const [message] = event.args()
expect(message.toString()).toBe('{state: Blob, thumbnail: Blob}')
})

test('load state', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('gbc', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('load-state-pristine.png')

await canvas.press('Enter', { delay: 500 })
await expect(canvas).toHaveScreenshot('load-state-touched.png')

await page.getByText('saveState', { exact: true }).click()
await page.waitForEvent('console', (consoleMessage) => consoleMessage.type() === 'info')

await page.getByText('restart', { exact: true }).click()
await expect(canvas).toHaveScreenshot('load-state-pristine.png')

await page.getByText('loadState', { exact: true }).click()
await page.waitForTimeout(1000) // loading state can be slow
await expect(canvas).toHaveScreenshot('load-state-touched.png')
})

test('restart', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('restart-pristine.png')

await canvas.press('Enter', { delay: 500 })
await expect(canvas).not.toHaveScreenshot('restart-pristine.png')

await page.getByText('restart', { exact: true }).click()

await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('restart-pristine.png')
})

test('pause and resume', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await canvas.press('Enter', { delay: 800 })

await page.getByText('pause', { exact: true }).click()
await expect(canvas).toHaveScreenshot('pause-and-resume.png')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('pause-and-resume.png')

await page.getByText('resume', { exact: true }).click()
await page.waitForTimeout(1000)
await expect(canvas).not.toHaveScreenshot('pause-and-resume.png')
})

test('press', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)

await expect(canvas).toHaveScreenshot('press-pristine.png')

// show the game info
await page.getByText('pressA', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-a.png')

// hide the game info
await page.getByText('pressA', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-pristine.png')

// enter the game
await page.getByText('pressStart', { exact: true }).click()
await page.waitForTimeout(300)
await expect(canvas).toHaveScreenshot('press-start.png')
})
})
1 change: 1 addition & 0 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
testMatch: 'tests/e2e/**/*.spec.ts',
updateSnapshots: 'missing',
snapshotPathTemplate: '{testDir}/snapshots/{testFilePath}/{testName}/{arg}{ext}',
reporter: 'html',
expect: {
toHaveScreenshot: { maxDiffPixels: 100 },
},
Expand Down
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions tests/e2e/static-ra-nightly.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect, test } from '@playwright/test'

test.describe('static methods with nightly retroarch', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/tests/e2e/test-page/nightly.html')
})

test('launch nes', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-nes.png')
})

test('launch megadrive', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-megadrive.png')
})

test('launch gbc', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('gbc', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-gbc.png')
})

test('launch nestopia', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('launchNestopia', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(2000)
await expect(canvas).toHaveScreenshot('launch-nestopia.png')
})

test('launch size', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('launchSize', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(2000)
await expect(canvas).toHaveScreenshot('launch-size.png')
})
})
58 changes: 1 addition & 57 deletions tests/e2e/static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,63 +41,7 @@ test.describe('static methods', () => {

await page.getByText('launchNestopia', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-nestopia.png')
})

test('launch size', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('launchSize', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-size.png')
})
})

test.describe('static methods with nightly retroarch', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/tests/e2e/test-page/nightly.html')
})

test('launch nes', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('nes', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-nes.png')
})

test('launch megadrive', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('megadrive', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-megadrive.png')
})

test('launch gbc', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('gbc', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-gbc.png')
})

test('launch nestopia', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

await page.getByText('launchNestopia', { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(500)
await page.waitForTimeout(2000)
await expect(canvas).toHaveScreenshot('launch-nestopia.png')
})

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/test-page/test-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function launchNestopia() {
}

async function launchSize() {
nostalgist = await Nostalgist.nes({ core: 'nestopia', rom: 'pong1k.nes', size: { width: 100, height: 100 } })
nostalgist = await Nostalgist.nes({ rom: 'pong1k.nes', size: { width: 100, height: 100 } })
}

async function saveState() {
Expand Down

0 comments on commit 21a8a4b

Please sign in to comment.