-
Notifications
You must be signed in to change notification settings - Fork 125
chore: Run automated tests on example pages #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3182fa9
Added playwright config for examples tests
spuppo-mux cc10365
Added CI step
spuppo-mux 51c7510
Fix gh workflow calls
spuppo-mux 9220f01
Merge branch 'main' into chore/test-example-pages
spuppo-mux bef4f77
chore: Test custom elements are defined on examples (#1)
spuppo-mux 955723d
chore: Test Example Pages - Interaction Tests (#6)
spuppo-mux 1fd28ca
chore: Test Example Pages - Specific features and Playback Tests (#3)
spuppo-mux 63d0903
Switch nonDefinedThemes counter to a cdn health check
spuppo-mux 4df4114
Remove accidental only
spuppo-mux 347f984
chore: Test Example Pages - Improve CI (#4)
spuppo-mux 9108a6c
chore: Test Example Pages - Run react examples (#5)
spuppo-mux 19cf102
Fixed KNOWN_ERRORS path
spuppo-mux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { defineConfig, devices } from 'playwright/test'; | ||
|
|
||
| const PORT = 4567; | ||
|
|
||
| export default defineConfig({ | ||
| testDir: './examples', | ||
| retries: 2, | ||
|
|
||
| webServer: { | ||
| command: `npm run serve:test -- -p ${PORT}`, | ||
| url: `http://localhost:${PORT}`, | ||
| reuseExistingServer: !process.env.CI, | ||
| }, | ||
|
|
||
| use: { | ||
| baseURL: `http://localhost:${PORT}`, | ||
| screenshot: "only-on-failure", | ||
| video: "off", | ||
| trace: "retain-on-failure", | ||
| }, | ||
|
|
||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| }, | ||
| ], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { test, expect } from 'playwright/test'; | ||
|
|
||
| test('examples index page loads', async ({ page }) => { | ||
| await page.goto('/examples/vanilla/'); | ||
| await expect(page).toHaveTitle('Media Chrome Examples'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { readdirSync, statSync } from 'fs'; | ||
| import { join, relative, dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import type { Page } from 'playwright/test'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| export const EXAMPLES_DIR = join(__dirname, '../../../examples/vanilla'); | ||
|
|
||
| export function findHtmlFiles(dir: string, base = dir): string[] { | ||
| const files: string[] = []; | ||
| for (const entry of readdirSync(dir)) { | ||
| const fullPath = join(dir, entry); | ||
| if (statSync(fullPath).isDirectory()) { | ||
| files.push(...findHtmlFiles(fullPath, base)); | ||
| } else if (entry.endsWith('.html')) { | ||
| files.push(relative(base, fullPath)); | ||
| } | ||
| } | ||
| return files.sort(); | ||
| } | ||
|
|
||
| /** | ||
| * Replaces the first native <video> or <audio> element's source with a | ||
| * synthetic stream (canvas or AudioContext) so tests run without network | ||
| * requests and without a mediaErrorCode in the store. | ||
| * | ||
| * The store blocks all state-change requests when mediaErrorCode is non-null, | ||
| * which happens when the external video URL fails to load in CI. | ||
| */ | ||
| export async function injectSyntheticStream(page: Page): Promise<void> { | ||
| await page.evaluate(async () => { | ||
| const mediaEl = document.querySelector( | ||
| 'video, audio' | ||
| ) as HTMLVideoElement | HTMLAudioElement | null; | ||
|
|
||
| if (!mediaEl || mediaEl.tagName.includes('-')) return; | ||
|
|
||
| if (mediaEl.tagName === 'AUDIO') { | ||
| const ctx = new AudioContext(); | ||
| const osc = ctx.createOscillator(); | ||
| const dst = ctx.createMediaStreamDestination(); | ||
| osc.frequency.value = 0; // silent | ||
| osc.connect(dst); | ||
| osc.start(); | ||
| mediaEl.srcObject = dst.stream; | ||
| } else { | ||
| const canvas = document.createElement('canvas'); | ||
| canvas.width = 2; | ||
| canvas.height = 2; | ||
| canvas.getContext('2d')!.fillRect(0, 0, 2, 2); | ||
| (mediaEl as HTMLVideoElement).srcObject = canvas.captureStream(); | ||
| } | ||
|
|
||
| await new Promise<void>((resolve) => { | ||
| if (mediaEl.readyState >= 1) { resolve(); return; } | ||
| mediaEl.addEventListener('loadedmetadata', () => resolve(), { once: true }); | ||
| setTimeout(resolve, 2000); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Pages excluded from play testing: | ||
| * - No media elements (index, memory-leak-tester, media-chrome-menu) | ||
| * - Not a real page (iframe embeds another example) | ||
| * - Intentionally shows error states (media-error-dialog) | ||
| */ | ||
| export const SKIP_PLAY_TEST = new Set([ | ||
| 'index.html', | ||
| 'memory-leak-tester.html', | ||
| 'iframe.html', | ||
| 'control-elements/media-chrome-menu.html', | ||
| 'control-elements/media-error-dialog.html', | ||
| ]); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * Interaction tests — scope: targeted examples | ||
| * | ||
| * Verifies that controls are actually wired up and respond | ||
| * correctly to user input. Tests are written against specific | ||
| * pages where the behaviour is unambiguous. | ||
| * | ||
| * Avoids full media-playback assertions (too flaky in CI). Instead it | ||
| * validates event dispatch, state attribute changes, and DOM geometry. | ||
| */ | ||
| import { test, expect } from 'playwright/test'; | ||
| import { injectSyntheticStream } from './helpers.js'; | ||
|
|
||
| test.describe('standalone-controls.html', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/examples/vanilla/standalone-controls.html', { | ||
| waitUntil: 'load', | ||
| }); | ||
| }); | ||
|
|
||
| test('media-play-button dispatches play request when clicked', async ({ | ||
| page, | ||
| }) => { | ||
| await page.evaluate(() => { | ||
| (window as any).__playRequestFired = false; | ||
| document.addEventListener( | ||
| 'mediaplayrequest', | ||
| () => { (window as any).__playRequestFired = true; }, | ||
| { once: true, capture: true } | ||
| ); | ||
| }); | ||
|
|
||
| await page.locator('media-play-button').first().click(); | ||
|
|
||
| const fired = await page.evaluate(() => (window as any).__playRequestFired); | ||
| expect(fired, 'mediaplayrequest event was not dispatched').toBe(true); | ||
| }); | ||
|
|
||
| test('media-mute-button toggles mute state', async ({ page }) => { | ||
| await injectSyntheticStream(page); | ||
|
|
||
| const muteBtn = page.locator('media-mute-button').first(); | ||
|
|
||
| await expect(muteBtn).not.toHaveAttribute('mediavolumelevel', 'off'); | ||
| await muteBtn.click(); | ||
| await expect(muteBtn).toHaveAttribute('mediavolumelevel', 'off'); | ||
| await muteBtn.click(); | ||
| await expect(muteBtn).not.toHaveAttribute('mediavolumelevel', 'off'); | ||
| }); | ||
|
|
||
| test('media-time-range is rendered with measurable width', async ({ | ||
| page, | ||
| }) => { | ||
| const timeRange = page.locator('media-time-range').first(); | ||
| const box = await timeRange.boundingBox(); | ||
|
|
||
| expect(box, 'media-time-range is not visible').not.toBeNull(); | ||
| expect(box!.width, 'media-time-range has zero width').toBeGreaterThan(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Smoke tests — scope: all example pages | ||
| * | ||
| * Checks that every page: | ||
| * 1. Loads without uncaught JS errors | ||
| * 2. Has all media-* custom elements properly registered | ||
| * | ||
| * This is the fastest / widest safety net. A failure here means a broken | ||
| * import or missing component registration — the most common regression type. | ||
| */ | ||
| import { test, expect } from 'playwright/test'; | ||
| import { findHtmlFiles, EXAMPLES_DIR } from './helpers.js'; | ||
|
|
||
| const htmlFiles = findHtmlFiles(EXAMPLES_DIR); | ||
|
|
||
| for (const relPath of htmlFiles) { | ||
| test(`vanilla/${relPath} - custom elements registered`, async ({ page }) => { | ||
| const pageErrors: string[] = []; | ||
| page.on('pageerror', (error) => pageErrors.push(error.message)); | ||
|
|
||
| await page.goto(`/examples/vanilla/${relPath}`, { waitUntil: 'load' }); | ||
|
|
||
| // Under parallel server load, module scripts can finish fetching slightly after | ||
| // `waitUntil: 'load'`. Wait up to 5s for every media-* element to be defined | ||
| // before asserting, so the check is not racy. | ||
| const undefinedElements = await page.evaluate(async () => { | ||
| const tagNames = new Set( | ||
| [...document.querySelectorAll('*')] | ||
| .map((el) => el.tagName.toLowerCase()) | ||
| .filter((tag) => tag.startsWith('media-')) | ||
| ); | ||
| await Promise.race([ | ||
| Promise.all([...tagNames].map((tag) => customElements.whenDefined(tag))), | ||
| new Promise<void>((resolve) => setTimeout(resolve, 5000)), | ||
| ]); | ||
| return [...tagNames].filter((tag) => !customElements.get(tag)); | ||
| }); | ||
|
|
||
| expect( | ||
| undefinedElements, | ||
| `Unregistered custom elements: ${undefinedElements.join(', ')}` | ||
| ).toHaveLength(0); | ||
|
|
||
| expect(pageErrors, `Page errors: ${pageErrors.join('; ')}`).toHaveLength(0); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2020", | ||
| "module": "es2020", | ||
| "moduleResolution": "bundler", | ||
| "types": ["node"], | ||
| "lib": ["es2020", "DOM", "DOM.Iterable"], | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["./**/*"] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.