Skip to content
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

test: add video e2e tests #529

Merged
merged 8 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/get-verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
const blockBrokers: Array<(components: any) => BlockBroker> = []

if (config.enableGatewayProviders) {
blockBrokers.push(trustlessGateway())
blockBrokers.push(trustlessGateway({ allowLocal: true }))
}

const hashers = [blake3]
Expand Down
14 changes: 14 additions & 0 deletions test-e2e/byte-range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ test.describe('byte-ranges', () => {
expect(byteSize).toBe(872)
expect(bytes).toStrictEqual(tailBytes)
})

test('video file first set of bytes match kubo gateway', async ({ page }) => {
const { bytes, byteSize, statusCode } = await doRangeRequest({ page, range: 'bytes=0-100', path: '/ipfs/bafybeie4vcqkutumw7s26ob2bwqwqi44m6lrssjmiirlhrzhs2akdqmkw4' })

// also fetch from KUBO_GATEWAY to compare
const response = await fetch(`${process.env.KUBO_GATEWAY}/ipfs/bafybeie4vcqkutumw7s26ob2bwqwqi44m6lrssjmiirlhrzhs2akdqmkw4`, { headers: { range: 'bytes=0-100' } })

const buffer = await response.arrayBuffer()
const kuboByteSize = buffer.byteLength
const kuboBytes = Array.from(new Uint8Array(buffer))
expect(statusCode).toBe(response.status)
expect(byteSize).toBe(kuboByteSize)
expect(bytes).toStrictEqual(kuboBytes)
})
})
Binary file not shown.
48 changes: 48 additions & 0 deletions test-e2e/video.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { testPathRouting as test, expect } from './fixtures/config-test-fixtures.js'
import { setConfig } from './fixtures/set-sw-config.js'
import { waitForServiceWorker } from './fixtures/wait-for-service-worker'
import type { ConfigDbWithoutPrivateFields } from '../src/lib/config-db.js'

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`
test.describe('video', () => {
const testConfig: Partial<ConfigDbWithoutPrivateFields> = {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
gateways: [process.env.KUBO_GATEWAY!],
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
routers: [process.env.KUBO_GATEWAY!],
debug: '*,*:trace',
enableWss: true,
enableWebTransport: false,
enableRecursiveGateways: true,
enableGatewayProviders: false
}

/**
* We want to load the video fixture and ensure it starts playing.
*/
test('starts playing automatically', async ({ page, protocol, rootDomain }) => {
await page.goto(`${protocol}//${rootDomain}`)
await setConfig({ page, config: testConfig })
await waitForServiceWorker(page)
const response = await page.goto(`${protocol}//${rootDomain}/ipfs/${cid}`, { waitUntil: 'commit' })
const start = performance.now()

expect(response?.status()).toBe(200)

// expect a video player
await page.waitForSelector('video')
const video = await page.$('video')
if (video == null) {
throw new Error('video element not found')
}

// continuously check if the video is playing
await page.waitForFunction((video) => {
return video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2
}, video)
const end = performance.now()

const timeToPlay = end - start
expect(timeToPlay).toBeLessThan(10000)
})
})
Loading