|
| 1 | +import { testPathRouting as test, expect } from './fixtures/config-test-fixtures.js' |
| 2 | +import { setConfig } from './fixtures/set-sw-config.js' |
| 3 | +import { waitForServiceWorker } from './fixtures/wait-for-service-worker' |
| 4 | +import type { ConfigDbWithoutPrivateFields } from '../src/lib/config-db.js' |
| 5 | + |
| 6 | +const cid = 'bafybeie4vcqkutumw7s26ob2bwqwqi44m6lrssjmiirlhrzhs2akdqmkw4' // big buck bunny webm trimmed to 15 seconds with `ffmpeg -i bigbuckbunny.webm -ss 00:00 -t 00:15 -c:a copy -c:v copy bigbuckbunny-mini.webm` |
| 7 | +test.describe('video', () => { |
| 8 | + const testConfig: Partial<ConfigDbWithoutPrivateFields> = { |
| 9 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 10 | + gateways: [process.env.KUBO_GATEWAY!], |
| 11 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 12 | + routers: [process.env.KUBO_GATEWAY!], |
| 13 | + debug: '*,*:trace', |
| 14 | + enableWss: true, |
| 15 | + enableWebTransport: false, |
| 16 | + enableRecursiveGateways: true, |
| 17 | + enableGatewayProviders: false |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * We want to load the video fixture and ensure it starts playing. |
| 22 | + */ |
| 23 | + test('starts playing automatically', async ({ page, protocol, rootDomain }) => { |
| 24 | + await page.goto(`${protocol}//${rootDomain}`) |
| 25 | + await setConfig({ page, config: testConfig }) |
| 26 | + await waitForServiceWorker(page) |
| 27 | + const response = await page.goto(`${protocol}//${rootDomain}/ipfs/${cid}`, { waitUntil: 'commit' }) |
| 28 | + const start = performance.now() |
| 29 | + |
| 30 | + expect(response?.status()).toBe(200) |
| 31 | + |
| 32 | + // expect a video player |
| 33 | + await page.waitForSelector('video') |
| 34 | + const video = await page.$('video') |
| 35 | + if (video == null) { |
| 36 | + throw new Error('video element not found') |
| 37 | + } |
| 38 | + |
| 39 | + // continuously check if the video is playing |
| 40 | + await page.waitForFunction((video) => { |
| 41 | + return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2 |
| 42 | + }, video) |
| 43 | + const end = performance.now() |
| 44 | + |
| 45 | + const timeToPlay = end - start |
| 46 | + expect(timeToPlay).toBeLessThan(10000) |
| 47 | + }) |
| 48 | +}) |
0 commit comments