Skip to content

Commit 67ffa48

Browse files
committed
Update tests
1 parent 690a989 commit 67ffa48

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

playwright.config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import detect from 'is-port-reachable'
2-
3-
const reuseExistingServer = await detect(5173, { host: 'localhost' })
4-
51
/** @type {import('@playwright/test').PlaywrightTestConfig} */
62
const config = {
3+
testDir: 'tests',
4+
testMatch: '**/*.js',
75
webServer: {
86
command: 'npm run dev',
97
port: 5173,
10-
reuseExistingServer
11-
},
12-
testDir: 'tests'
8+
reuseExistingServer: true
9+
}
1310
}
1411

1512
export default config

tests/test.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { expect, test } from '@playwright/test'
22

3-
test('default variants are generated', async ({ page }) => {
4-
await page.goto('/test')
5-
const data = JSON.parse((await page.getByTestId('basic').textContent()) || '')
6-
expect(data.length).toBe(10)
7-
expect(data.filter((i) => i.format === 'jpg').length).toBe(3)
8-
expect(data.filter((i) => i.format === 'avif').length).toBe(3)
9-
expect(data.filter((i) => i.format === 'webp').length).toBe(4)
10-
expect(data.filter((i) => i.width === 480).length).toBe(3)
11-
expect(data.filter((i) => i.width === 1024).length).toBe(3)
12-
expect(data.filter((i) => i.width === 1920).length).toBe(3)
13-
const { base64 } = data.find((i) => i.format === 'webp' && i.width === 16)
14-
expect(base64).toContain('data:image/webp;base64')
3+
test('basic - variants are generated', async ({ page }) => {
4+
await page.goto('/')
5+
const sources = page.locator('.test-basic picture source')
6+
await expect(sources).toHaveCount(3)
7+
const img = page.locator('.test-basic img')
8+
expect(await img.getAttribute('style')).toContain('data:image/webp;base64')
159
})
1610

17-
test('no lqip', async ({ page }) => {
18-
await page.goto('/test')
19-
const data = JSON.parse((await page.getByTestId('nolqip').textContent()) || '')
20-
expect(data.length).toBe(9)
21-
expect(data.find((/** @type {{ base64: any; }} */ i) => i.base64)).toBe(undefined)
11+
test('dominant colour lqip', async ({ page }) => {
12+
await page.goto('/')
13+
const img = page.locator('.test-1px')
14+
expect(await img.getAttribute('style')).toContain('rgb(')
2215
})
2316

24-
test('width override', async ({ page }) => {
25-
await page.goto('/test')
26-
const data = JSON.parse((await page.getByTestId('width').textContent()) || '')
27-
expect(data.length).toBe(7)
28-
expect(data.filter((i) => i.width === 480).length).toBe(3)
29-
expect(data.filter((i) => i.width === 1024).length).toBe(3)
17+
test('single image does not render picture', async ({ page }) => {
18+
await page.goto('/')
19+
expect(await page.locator('.test-single picture').count()).toBe(0)
3020
})
3121

32-
test('returns a path by default', async ({ page }) => {
33-
await page.goto('/test')
34-
const data = JSON.parse((await page.getByTestId('default').textContent()) || '')
35-
expect(data).toBe(`/src/routes/cat01.jpg`)
22+
test('lqip can be disabled', async ({ page }) => {
23+
await page.goto('/')
24+
expect(await page.locator('.test-single img').getAttribute('style')).toBeNull
3625
})
26+
27+
test('falls back to standard imagetools without run directive', async ({ page }) => {
28+
await page.goto('/')
29+
expect(await page.locator('.test-fallback').innerText()).toContain('@imagetools')
30+
})
31+
32+
/*
33+
test('', async ({ page }) => {
34+
await page.goto('/')
35+
})
36+
*/

0 commit comments

Comments
 (0)