Skip to content

Commit

Permalink
test: remove duplicated test code
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Mar 4, 2024
1 parent 64fba1a commit b91213c
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 462 deletions.
119 changes: 119 additions & 0 deletions tests/e2e/instance-ra-common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { expect, test } from '@playwright/test'

export function tests() {
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')
})

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

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

await page.getByText('screenshot', { exact: true }).click()
await expect(screenshot).toHaveScreenshot('screenshot.png')
})
}
121 changes: 4 additions & 117 deletions tests/e2e/instance-ra-esm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,10 @@
import { expect, test } from '@playwright/test'
import { test } from '@playwright/test'
import { tests } from './instance-ra-common'

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

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')
})

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

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

await page.getByText('screenshot', { exact: true }).click()
await expect(screenshot).toHaveScreenshot('screenshot.png')
})
tests()
})
121 changes: 4 additions & 117 deletions tests/e2e/instance-ra-legacy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,10 @@
import { expect, test } from '@playwright/test'
import { test } from '@playwright/test'
import { tests } from './instance-ra-common'

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

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')
})

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

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

await page.getByText('screenshot', { exact: true }).click()
await expect(screenshot).toHaveScreenshot('screenshot.png')
})
tests()
})
Loading

0 comments on commit b91213c

Please sign in to comment.