Skip to content

πŸŽ₯ Make videos programmatically with React

Internal: Replace Track audio E2E with component integration test

JonnyBurger69c6c88b143c
diff --git a/packages/example/e2e/track-audio-intrinsic-duration.test.mts b/packages/example/e2e/track-audio-intrinsic-duration.test.mts
deleted file mode 100644
index 86722efa1d..0000000000
--- a/packages/example/e2e/track-audio-intrinsic-duration.test.mts
+++ /dev/null
@@ -1,103 +0,0 @@
-import fs from 'node:fs';
-import path from 'node:path';
-import {expect, test} from '@playwright/test';
-import {STUDIO_URL, exampleDir} from './constants.mts';
-import {startStudio, stopStudio} from './studio-server.mts';
-
-test('Track waits for audio metadata, displays intrinsic lengths, and rejects real overlaps', async ({
- page,
-}) => {
- test.setTimeout(90_000);
- const fixture = path.join(
- exampleDir,
- 'src',
- 'TrackAudioIntrinsicDurationE2e.tsx',
- );
- const original = fs.readFileSync(fixture, 'utf8');
-
- // A real 0.2-second PCM WAV: six frames at 30 fps. Keep metadata parsing
- // and all Remotion code real, controlling only the external HTTP response.
- const wav = Buffer.alloc(44 + 1600 * 2);
- wav.write('RIFF', 0);
- wav.writeUInt32LE(wav.length - 8, 4);
- wav.write('WAVEfmt ', 8);
- wav.writeUInt32LE(16, 16);
- wav.writeUInt16LE(1, 20);
- wav.writeUInt16LE(1, 22);
- wav.writeUInt32LE(8000, 24);
- wav.writeUInt32LE(16000, 28);
- wav.writeUInt16LE(2, 32);
- wav.writeUInt16LE(16, 34);
- wav.write('data', 36);
- wav.writeUInt32LE(wav.length - 44, 40);
-
- let releaseMetadata: () => void = () => undefined;
- const metadataReady = new Promise<void>((resolve) => {
- releaseMetadata = resolve;
- });
- let requested = false;
- await page.route('https://example.com/track-duration.wav', async (route) => {
- requested = true;
- await metadataReady;
- await route.fulfill({
- contentType: 'audio/wav',
- headers: {'Access-Control-Allow-Origin': '*'},
- body: wav,
- });
- });
-
- const first = page.getByRole('group', {name: 'First sound', exact: true});
- const second = page.getByRole('group', {name: 'Second sound', exact: true});
- const overlapError = page
- .getByText(/^<Track name="Sound effects"> contains overlapping items:/)
- .first();
-
- try {
- await startStudio();
- await page.goto(`${STUDIO_URL}/track-audio-intrinsic-duration`);
- await expect(page.getByText('Audio metadata fixture')).toBeVisible();
- await expect.poll(() => requested).toBe(true);
- await expect(
- page.getByRole('group', {name: 'Sound effects', exact: true}),
- ).toBeVisible();
- await expect(first).toHaveCount(0);
- await expect(second).toHaveCount(0);
- await expect(overlapError).toHaveCount(0);
-
- releaseMetadata();
- await expect(first).toBeVisible();
- await expect(second).toBeVisible();
- const firstBounds = await first.boundingBox();
- const secondBounds = await second.boundingBox();
- if (firstBounds === null || secondBounds === null) {
- throw new Error('Expected both audio bars after metadata loaded');
- }
-
- const pixelsPerFrame = (secondBounds.x - firstBounds.x) / 30;
- expect(firstBounds.width / pixelsPerFrame).toBeCloseTo(6, 1);
- expect(secondBounds.width / pixelsPerFrame).toBeCloseTo(6, 1);
- expect(firstBounds.y).toBe(secondBounds.y);
- expect(firstBounds.x + firstBounds.width).toBeLessThan(secondBounds.x);
- await expect(overlapError).toHaveCount(0);
-
- fs.writeFileSync(
- fixture,
- original.replace('secondFrom = 30', 'secondFrom = 3'),
- );
- await expect(overlapError).toContainText(
- '"First sound" (frames 0–6) and "Second sound" (frames 3–9) overlap by 3 frames',
- );
-
- fs.writeFileSync(fixture, original);
- await expect(overlapError).toHaveCount(0);
- await expect(second).toBeVisible();
- await expect
- .poll(async () => (await second.boundingBox())?.x)
- .toBeCloseTo(secondBounds.x, 1);
- } finally {
- releaseMetadata();
- await page.close();
- await stopStudio();
- fs.writeFileSync(fixture, original);
- }
-});
diff --git a/packages/example/src/E2eTestRoot.tsx b/packages/example/src/E2eTestRoot.tsx
index b144576ab7..d95cfdfdd3 100644
--- a/packages/example/src/E2eTestRoot.tsx
+++ b/packages/example/src/E2eTestRoot.tsx
@@ -23,7 +23,6 @@ import {SchemaTest, schemaTestSchema} from './SchemaTest';
import {SequencePlaybackRateE2e} from './SequencePlaybackRateE2e';
import {SourceSubscriptionChurn} from './SourceSubscriptionChurn';
import {TimelineNegativeFromResize} from './TimelineNegativeFromResize';
-import {TrackAudioIntrinsicDurationE2e} from './TrackAudioIntrinsicDurationE2e';
import {VisualControls} from './VisualControls';
import {VisualMode3D} from './VisualMode3D';
import {AffineFrameClock} from './VisualModeTests/AffineFrameClock';
@@ -35,14 +34,6 @@ import {SequenceShiftRepro} from './VisualModeTests/SequenceShiftRepro';
export const E2eTestRoot: React.FC = () => {
return (
<>
- <Composition
- id="track-audio-intrinsic-duration"
- component={TrackAudioIntrinsicDurationE2e}
- durationInFrames={90}
- fps={30}
- width={1280}
- height={720}
- />
<Composition
id="hidden-clip-drag-preview"
component={HiddenClipDragPreview}
diff --git a/packages/example/src/TrackAudioIntrinsicDurationE2e.tsx b/packages/example/src/TrackAudioIntrinsicDurationE2e.tsx
deleted file mode 100644
index f6a174e446..0000000000
--- a/packages/example/src/TrackAudioIntrinsicDurationE2e.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import {Audio} from '@remotion/media';
-import {Track} from 'remotion';
-
-export const TrackAudioIntrinsicDurationE2e = () => {
- const secondFrom = 30;
- return (
- <>
- <div>Audio metadata fixture</div>
- <Track name="Sound effects">
- <Audio
- name="First sound"
- src="https://example.com/track-duration.wav"
- />
- <Audio
- name="Second sound"
- src="https://example.com/track-duration.wav"
- from={secondFrom}
- />
- </Track>
- </>
- );
-};
diff --git a/packages/studio/src/test/track-audio-intrinsic-duration.test.tsx b/packages/studio/src/test/track-audio-intrinsic-duration.test.tsx
new file mode 100644
index 0000000000..df52718b07
--- /dev/null
+++ b/packages/studio/src/test/track-audio-intrinsic-duration.test.tsx
@@ -0,0 +1,142 @@
+import {expect, test} from 'bun:test';
+import {Audio} from '@remotion/media';
+import {Player, PlayerInternals} from '@remotion/player';
+import {CanvasInternals} from '@remotion/sdk';
+import {act, cleanup, render, waitFor} from '@testing-library/react';
+import {useMemo, useState} from 'react';
+import {Internals, Track, type TSequence} from 'remotion';
+import {TimelineTrackOverlapValidation} from '../components/Timeline/TimelineTrackOverlapValidation';
+import {getRuntimeErrors} from '../error-overlay/runtime-error-store';
+import {getCachedMediaMetadata} from '../helpers/use-media-metadata';
+
+test('Track validates intrinsic audio durations after shared metadata resolves', async () => {
+ const originalFetch = globalThis.fetch;
+ const originalIsPlayer = Object.getOwnPropertyDescriptor(
+ window,
+ 'remotion_isPlayer',
+ );
+ const src = 'https://example.com/track-audio-integration.wav';
+ // Real 0.2-second PCM WAV; metadata parsing is not mocked.
+ const wav = Buffer.alloc(44 + 1600 * 2);
+ wav.write('RIFF', 0);
+ wav.writeUInt32LE(wav.length - 8, 4);
+ wav.write('WAVEfmt ', 8);
+ wav.writeUInt32LE(16, 16);
+ wav.writeUInt16LE(1, 20);
+ wav.writeUInt16LE(1, 22);
+ wav.writeUInt32LE(8000, 24);
+ wav.writeUInt32LE(16000, 28);
+ wav.writeUInt16LE(2, 32);
+ wav.writeUInt16LE(16, 34);
+ wav.write('data', 36);
+ wav.writeUInt32LE(wav.length - 44, 40);
+ let releaseMetadata: () => void = () => undefined;
+ const pendingMetadata = new Promise<void>((resolve) => {
+ releaseMetadata = resolve;
+ });
+ let requests = 0;
+ globalThis.fetch = (async (input, init) => {
+ if (String(input) !== src) {
+ return originalFetch(input, init);
+ }
+
+ requests++;
+ await pendingMetadata;
+ const range = new Headers(init?.headers).get('Range');
+ const match = range?.match(/^bytes=(\d+)-(\d*)$/);
+ const start = match ? Number(match[1]) : 0;
+ const end = match?.[2]
+ ? Math.min(Number(match[2]), wav.length - 1)
+ : wav.length - 1;
+ return new Response(new Uint8Array(wav.subarray(start, end + 1)).buffer, {
+ status: match ? 206 : 200,
+ headers: {
+ 'Content-Type': 'audio/wav',
+ 'Accept-Ranges': 'bytes',
+ 'Content-Length': String(end - start + 1),
+ ...(match
+ ? {'Content-Range': `bytes ${start}-${end}/${wav.length}`}
+ : {}),
+ },
+ });
+ }) as typeof fetch;
+
+ const Composition = ({secondFrom}: {readonly secondFrom: number}) => (
+ <Internals.EnableInteractivityProvider>
+ <Track name="Sound effects">
+ <Audio name="First sound" src={src} />
+ <Audio name="Second sound" src={src} from={secondFrom} />
+ </Track>
+ </Internals.EnableInteractivityProvider>
+ );
+ const calculate = CanvasInternals.createTimelineCalculator();
+ let registered: TSequence[] = [];
+ const Harness = ({secondFrom}: {readonly secondFrom: number}) => {
+ const [sequences, setSequences] = useState<TSequence[]>([]);
+ registered = sequences;
+ const timeline = useMemo(
+ () => calculate({sequences, overrideIdsToNodePaths: {}}).tracks,
+ [sequences],
+ );
+ return (
+ <>
+ <PlayerInternals.TimelineSequenceObserverContext.Provider
+ value={setSequences}
+ >
+ <Player
+ acknowledgeRemotionLicense
+ component={Composition}
+ inputProps={{secondFrom}}
+ durationInFrames={90}
+ fps={30}
+ compositionWidth={320}
+ compositionHeight={180}
+ initiallyMuted
+ numberOfSharedAudioTags={0}
+ />
+ </PlayerInternals.TimelineSequenceObserverContext.Provider>
+ <TimelineTrackOverlapValidation
+ timeline={timeline}
+ durationInFrames={90}
+ fps={30}
+ />
+ </>
+ );
+ };
+
+ try {
+ const rendered = render(<Harness secondFrom={30} />);
+ await waitFor(() => {
+ expect(
+ registered.filter((sequence) => sequence.type === 'audio'),
+ ).toHaveLength(2);
+ expect(requests).toBeGreaterThan(0);
+ });
+ expect(getRuntimeErrors()).toEqual([]);
+ act(() => releaseMetadata());
+ await waitFor(() => {
+ expect(getCachedMediaMetadata(src)?.duration).toBe(0.2);
+ });
+ expect(getRuntimeErrors()).toEqual([]);
+
+ rendered.rerender(<Harness secondFrom={3} />);
+ await waitFor(() => {
+ expect(getRuntimeErrors().map(({error}) => error.message)).toEqual([
+ expect.stringContaining(
+ '"First sound" (frames 0–6) and "Second sound" (frames 3–9) overlap by 3 frames',
+ ),
+ ]);
+ });
+ rendered.rerender(<Harness secondFrom={30} />);
+ await waitFor(() => expect(getRuntimeErrors()).toEqual([]));
+ } finally {
+ releaseMetadata();
+ cleanup();
+ globalThis.fetch = originalFetch;
+ if (originalIsPlayer) {
+ Object.defineProperty(window, 'remotion_isPlayer', originalIsPlayer);
+ } else {
+ Reflect.deleteProperty(window, 'remotion_isPlayer');
+ }
+ }
+});