Skip to content

Commit d72a0a7

Browse files
authored
test: add video e2e tests (#529)
* chore: update package-lock.json * fix: config UI is up to date with IDB * chore: apply self suggestions from code review * chore: fix build and lint * test: add video e2e tests * chore: actually commit the video test file * chore: fix test name and comment
1 parent 2d8dbd9 commit d72a0a7

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/lib/get-verified-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
4545
const blockBrokers: Array<(components: any) => BlockBroker> = []
4646

4747
if (config.enableGatewayProviders) {
48-
blockBrokers.push(trustlessGateway())
48+
blockBrokers.push(trustlessGateway({ allowLocal: true }))
4949
}
5050

5151
const hashers = [blake3]

test-e2e/byte-range.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ test.describe('byte-ranges', () => {
3030
expect(byteSize).toBe(872)
3131
expect(bytes).toStrictEqual(tailBytes)
3232
})
33+
34+
test('video file first set of bytes match kubo gateway', async ({ page }) => {
35+
const { bytes, byteSize, statusCode } = await doRangeRequest({ page, range: 'bytes=0-100', path: '/ipfs/bafybeie4vcqkutumw7s26ob2bwqwqi44m6lrssjmiirlhrzhs2akdqmkw4' })
36+
37+
// also fetch from KUBO_GATEWAY to compare
38+
const response = await fetch(`${process.env.KUBO_GATEWAY}/ipfs/bafybeie4vcqkutumw7s26ob2bwqwqi44m6lrssjmiirlhrzhs2akdqmkw4`, { headers: { range: 'bytes=0-100' } })
39+
40+
const buffer = await response.arrayBuffer()
41+
const kuboByteSize = buffer.byteLength
42+
const kuboBytes = Array.from(new Uint8Array(buffer))
43+
expect(statusCode).toBe(response.status)
44+
expect(byteSize).toBe(kuboByteSize)
45+
expect(bytes).toStrictEqual(kuboBytes)
46+
})
3347
})
4.35 MB
Binary file not shown.

test-e2e/video.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)