Testing
The injectable fakes, the seam tests, and the e2e smoke harness.
Tests must never hit the production DAI asset key or production GAM (ADR 0007). Automated tests drive ad behavior through the injectable Ads port; real-browser smoke tests use Google's public sample assets only.
The /testing export
The package ships hand-written fakes for both ports:
import { FakeEngine, FakeAds } from "@grahamdigital/livestream-player/testing";FakeEngine
Implements the Engine port with no real playback — no network, no Shaka. It records
interactions (media, src, attached, loaded, and imperative call counts) and
lets the test drive the normalized event contract via emit:
const fake = new FakeEngine();
render(<LivePlayer src="https://x/master.m3u8" engineFactory={() => fake} />);
fake.emit({ type: "ready", isLive: true });
fake.emit({ type: "playing" });
// assert on UI state + fake.callsgateLoad() / releaseLoad() let a test hold a load() in flight to exercise
unmount-during-load races.
FakeAds
Implements the Ads port with no IMA SDK and no ad serving. It records the
DaiStreamRequest, resolves to a configurable streamUrl (or fails open when
failOnStart is set), and lets tests script an ad break — including the CSAI pre-roll
path (prerollStarted, prerollCalls.skipAd).
Test layers
- Vitest seam tests (in the package,
pnpm test) are the primary coverage: each feature slice is tested against the public<LivePlayer>contract with the fakes injected. - Playwright smoke harness (
apps/e2e) is an on-demand, real-browser check of the demo site — live playback in Chrome (real H.264/AAC codecs) and WebKit (the iOS/Safari native-HLS path), plus a DAI ad-break pass against Google's sample asset. Live streams and ads are flaky, so it is not CI-gated; it runs locally / pre-release against this site's demo.