Skip to content

Commit c25b4a8

Browse files
committed
Playwright setup
1 parent 4ce86d0 commit c25b4a8

File tree

8 files changed

+273
-3
lines changed

8 files changed

+273
-3
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
e2e:
11+
runs-on: ubuntu-latest
12+
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Install Playwright Browsers
28+
run: npx playwright install --with-deps
29+
30+
- name: Build project
31+
run: npm run build
32+
33+
- name: Start dev server
34+
run: |
35+
npm run start:example &
36+
npx wait-on http://localhost:3000
37+
timeout-minutes: 2
38+
39+
- name: Run Playwright tests
40+
run: npx playwright test
41+
42+
- name: Upload test results
43+
if: always()
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: playwright-test-results
47+
path: test-results
48+
49+
# - name: Upload HTML report
50+
# if: always()
51+
# uses: actions/upload-artifact@v3
52+
# with:
53+
# name: playwright-html-report
54+
# path: playwright-report

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist
33
lib
4+
test-results

config/playwright.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
export default defineConfig({
4+
testDir: '../tests',
5+
outputDir: '../test-results',
6+
webServer: {
7+
command: 'npm run build && npm run start:example',
8+
port: 3000,
9+
timeout: 60 * 1000,
10+
reuseExistingServer: !process.env.CI
11+
},
12+
use: {
13+
baseURL: 'http://localhost:3000'
14+
},
15+
projects: [
16+
{
17+
name: 'Chrome Desktop',
18+
use: {
19+
channel: 'chrome',
20+
viewport: { width: 1280, height: 800 }
21+
}
22+
},
23+
{
24+
name: 'Chrome Mobile (Pixel 7)',
25+
use: {
26+
...devices['Pixel 7'],
27+
channel: 'chrome'
28+
}
29+
},
30+
{
31+
name: 'Firefox Desktop',
32+
use: {
33+
browserName: 'firefox',
34+
viewport: { width: 1280, height: 800 }
35+
}
36+
},
37+
{
38+
name: 'Safari Desktop (WebKit)',
39+
use: {
40+
browserName: 'webkit',
41+
viewport: { width: 1280, height: 800 }
42+
}
43+
},
44+
{
45+
name: 'Safari Mobile (iPhone 14)',
46+
use: {
47+
...devices['iPhone 14'],
48+
browserName: 'webkit'
49+
}
50+
}
51+
]
52+
})

package-lock.json

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
"build:example": "rm -rf ./examples/dist/ && webpack --mode=production --config=./examples/webpack.config.js",
7171
"clean": "rm -rf ./dist/ ./examples/dist/",
7272
"dev:types": "tsc --noEmit --watch",
73+
"e2e": "playwright test --config ./config/playwright.config.ts",
74+
"e2e:ui": "playwright test --ui --config ./config/playwright.config.ts",
7375
"pre:publish": "npm run build && npm run build:example && npm run test",
7476
"start": "rm -rf ./dist/ && rollup --config ./config/rollup.config.js --environment ENV:development --watch --sourcemap",
7577
"start:example": "rm -rf ./examples/dist/ && webpack serve --mode=development --config=./examples/webpack.config.js",
@@ -80,6 +82,7 @@
8082
},
8183
"devDependencies": {
8284
"@biomejs/biome": "^1.9.4",
85+
"@playwright/test": "^1.51.1",
8386
"@rollup/plugin-alias": "^5.1.1",
8487
"@rollup/plugin-buble": "^1.0.3",
8588
"@rollup/plugin-node-resolve": "^15.3.0",

src/components/control-bar/control-bar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ export default class ControlBar {
222222
*/
223223
isOrientationApiAvailable() {
224224
return (
225-
window.screen.orientation &&
226-
// @ts-ignore
227-
!window.screen.mozOrientation
225+
typeof window.screen.orientation !== 'undefined' &&
226+
typeof window.screen.orientation.lock === 'function' &&
227+
typeof window.screen.orientation.unlock === 'function'
228228
)
229229
}
230230

tests/common.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
const providers = ['html5', 'youtube', 'vimeo', 'dailymotion']
4+
5+
providers.forEach((provider) => {
6+
test.describe(`${provider} Player`, () => {
7+
test.beforeEach(async ({ page }) => {
8+
await page.goto(`http://localhost:3000/${provider}`)
9+
})
10+
11+
test('should initialize the player', async ({ page }) => {
12+
const player = await page.$('.v-vlite')
13+
expect(player).not.toBeNull()
14+
15+
const playButton = await page.$('.v-bigPlay')
16+
expect(playButton).not.toBeNull()
17+
})
18+
})
19+
})
20+
21+
test.describe('Audio Player', () => {
22+
test.beforeEach(async ({ page }) => {
23+
await page.goto('http://localhost:3000/audio')
24+
})
25+
26+
test('should initialize the player', async ({ page }) => {
27+
const player = await page.$('.v-vlite')
28+
expect(player).not.toBeNull()
29+
30+
const playButton = await page.$('.v-playPauseButton')
31+
expect(playButton).not.toBeNull()
32+
})
33+
})

tests/player.spec.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test.describe('HTML5 Player Tests', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('http://localhost:3000/html5')
6+
})
7+
8+
test('Test player is initialized', async ({ page }) => {
9+
const player = await page.$('.v-vlite')
10+
expect(player).not.toBeNull()
11+
12+
const playButton = await page.$('.v-bigPlay')
13+
expect(playButton).not.toBeNull()
14+
})
15+
16+
test('Test big play button starts playback', async ({ page }) => {
17+
await page.click('.v-bigPlay')
18+
19+
const isPlaying = await page.evaluate(() => {
20+
const video = document.querySelector('#player')
21+
return !video.paused
22+
})
23+
expect(isPlaying).toBe(true)
24+
})
25+
26+
test('Test pause video on overlay click', async ({ page }) => {
27+
await page.click('.v-bigPlay')
28+
await page.click('.v-overlay')
29+
30+
const isPaused = await page.evaluate(() => {
31+
const video = document.querySelector('video')
32+
return video.paused
33+
})
34+
expect(isPaused).toBe(true)
35+
})
36+
37+
test('Test mute on volume button click', async ({ page }) => {
38+
await page.click('.v-bigPlay')
39+
await page.click('.v-volumeButton')
40+
41+
const muted = await page.evaluate(() => {
42+
const video = document.querySelector('video')
43+
return video.muted
44+
})
45+
expect(muted).toBe(true)
46+
})
47+
48+
test('Test enter fullscreen button works', async ({ page, browserName }, testInfo) => {
49+
const isSafariMobile = browserName === 'webkit' && testInfo.project.name.includes('iPhone')
50+
if (isSafariMobile) {
51+
test.skip(true, 'Fullscreen is not reliably supported on iOS Safari in automated tests')
52+
}
53+
54+
await page.click('.v-bigPlay')
55+
await page.click('.v-fullscreenButton')
56+
57+
const isFullscreen = await page.evaluate(() => {
58+
return document.fullscreenElement !== null
59+
})
60+
expect(isFullscreen).toBe(true)
61+
})
62+
63+
test('Test exit fullscreen button works', async ({ page, browserName }, testInfo) => {
64+
const isSafariMobile = browserName === 'webkit' && testInfo.project.name.includes('iPhone')
65+
if (isSafariMobile) {
66+
test.skip(true, 'Fullscreen is not reliably supported on iOS Safari in automated tests')
67+
}
68+
69+
await page.click('.v-bigPlay')
70+
await page.click('.v-fullscreenButton')
71+
await page.click('.v-fullscreenButton')
72+
73+
const isFullscreen = await page.evaluate(() => {
74+
return document.fullscreenElement !== null
75+
})
76+
expect(isFullscreen).toBe(false)
77+
})
78+
})

0 commit comments

Comments
 (0)