🎥 Make videos programmatically with React
add an end-to-end test
Jonny Burgerbc391fe75698
diff --git a/.gitignore b/.gitignoreindex f310e3c747..b92513cc84 100644--- a/.gitignore+++ b/.gitignore@@ -28,6 +28,7 @@ packages/cloudrun/container/cloudbuild.jsonpackages/example/public/offthreadvideoregression.git+packages/example/test-resultspackages/example/buildpackages/example-without-zod/buildpackages/docs/outdiff --git a/bun.lock b/bun.lockindex 6ce94f6ade..0e335216f6 100644--- a/bun.lock+++ b/bun.lock@@ -702,6 +702,7 @@"zod": "catalog:",},"devDependencies": {+ "@playwright/test": "1.55.1","@types/dom-webcodecs": "catalog:","eslint": "catalog:","sharp": "catalog:",diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mtsnew file mode 100644index 0000000000..18729ff1f2--- /dev/null+++ b/packages/example/e2e/studio.test.mts@@ -0,0 +1,176 @@+import {spawn, type ChildProcess} from 'child_process';+import fs from 'fs';+import path from 'path';+import {expect, test} from '@playwright/test';++let studioProcess: ChildProcess | undefined;++const STUDIO_PORT = 3123;+const STUDIO_URL = `http://localhost:${STUDIO_PORT}`;++const exampleDir = path.resolve(+ // @ts-expect-error+ new URL('.', import.meta.url).pathname,+ '..',+);++const remotionBin = path.join(exampleDir, 'node_modules', '.bin', 'remotion');++const rootFile = path.join(exampleDir, 'src', 'Root.tsx');++async function waitForServer(+ url: string,+ timeoutMs: number = 30_000,+): Promise<void> {+ const start = Date.now();+ while (Date.now() - start < timeoutMs) {+ try {+ const res = await fetch(url);+ if (res.ok) {+ return;+ }+ } catch {+ // Server not ready yet+ }++ await new Promise((resolve) => setTimeout(resolve, 500));+ }++ throw new Error(`Server at ${url} did not start within ${timeoutMs}ms`);+}++async function navigateToSchemaTest(page: import('@playwright/test').Page) {+ await page.goto(STUDIO_URL);+ // Expand the "Schema" folder in the sidebar+ const schemaFolder = page.getByTitle('Schema');+ await schemaFolder.click({timeout: 15_000});+ // Click on the schema-test composition inside the folder+ const schemaTestLink = page.getByText('schema-test', {exact: true}).first();+ await schemaTestLink.click({timeout: 10_000});+ await expect(page).toHaveURL(/schema-test/, {timeout: 10_000});+}++const studioStdoutLogs: string[] = [];+let originalRootContent: string;++test.beforeAll(async () => {+ originalRootContent = fs.readFileSync(rootFile, 'utf-8');++ studioProcess = spawn(+ remotionBin,+ ['studio', '--port', String(STUDIO_PORT), '--props', 'src/my-props.json'],+ {+ cwd: exampleDir,+ stdio: 'pipe',+ env: {+ ...process.env,+ BROWSER: 'none',+ },+ },+ );++ studioProcess.stderr?.on('data', (data: Buffer) => {+ const msg = data.toString();+ if (!msg.includes('ExperimentalWarning')) {+ console.error('[studio stderr]', msg.trim());+ }+ });++ studioProcess.stdout?.on('data', (data: Buffer) => {+ const msg = data.toString();+ studioStdoutLogs.push(msg);+ console.log('[studio stdout]', msg.trim());+ });++ await waitForServer(STUDIO_URL);+});++test.afterAll(async () => {+ if (studioProcess) {+ studioProcess.kill('SIGTERM');+ studioProcess = undefined;+ }++ // Restore original file content+ fs.writeFileSync(rootFile, originalRootContent);+});++test.describe('Remotion Studio', () => {+ test('should load the studio', async ({page}) => {+ await page.goto(STUDIO_URL);+ await expect(page).toHaveTitle(/Remotion/i, {timeout: 15_000});+ });++ test('should show the composition list', async ({page}) => {+ await page.goto(STUDIO_URL);+ // The Schema folder should be visible in the sidebar+ await expect(page.getByRole('button', {name: 'Schema'})).toBeVisible({+ timeout: 15_000,+ });+ });++ test('should navigate to schema-test composition', async ({page}) => {+ await navigateToSchemaTest(page);+ });++ test('should edit a prop and update source code', async ({page}) => {+ // Expand the right sidebar+ await page.goto(STUDIO_URL);+ await page.evaluate(() => {+ window.localStorage.setItem(+ 'remotion.sidebarRightCollapsing',+ 'expanded',+ );+ });+ await page.reload();++ await navigateToSchemaTest(page);++ // Wait for the props editor to load - use the text input, not the nullable checkbox+ const titleInput = page+ .locator(+ 'input[name="title"][type="text"], input[name="title"]:not([type="checkbox"])',+ )+ .first();+ await expect(titleInput).toBeVisible({timeout: 15_000});++ // Verify the new value is not already in the file+ const newTitle = 'e2e-test-title';+ const beforeContent = fs.readFileSync(rootFile, 'utf-8');+ expect(beforeContent).not.toContain(newTitle);++ await titleInput.fill(newTitle);++ // Blur the input to trigger save to file+ await titleInput.blur();++ // Wait for the file to be updated+ await expect+ .poll(+ () => {+ const content = fs.readFileSync(rootFile, 'utf-8');+ return content.includes(newTitle);+ },+ {+ message: `Expected Root.tsx to contain "${newTitle}" after prop edit`,+ timeout: 10_000,+ },+ )+ .toBe(true);++ // Verify the old value is no longer in the file+ const updatedContent = fs.readFileSync(rootFile, 'utf-8');+ expect(updatedContent).not.toContain("title: 'sdasds'");+ expect(updatedContent).toContain(newTitle);++ // Verify exactly 1 "Updated default props" log was emitted+ // Strip ANSI escape codes for matching+ const stripAnsi = (s: string) =>+ s.replace(/\x1b\[[0-9;]*m/g, '').replace(/\]8;;[^\x1b]*\x1b\\/g, '');+ const updateLogs = studioStdoutLogs.filter((log) => {+ const clean = stripAnsi(log);+ return clean.includes('Updated default props for "schema-test"');+ });+ expect(updateLogs).toHaveLength(1);+ });+});diff --git a/packages/example/package.json b/packages/example/package.jsonindex ad8f725efe..a0f2bc32ee 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -21,6 +21,7 @@"clean": "rm -rf build && rm -rf out","lint": "eslint src","test": "tsc && bun test src --timeout 60000",+ "test:e2e": "playwright test","render": "remotion render react-svg","bundle": "remotion bundle","render-js": "remotion render src/entry.jsx framer",@@ -105,6 +106,7 @@"zod": "catalog:"},"devDependencies": {+ "@playwright/test": "1.55.1","sharp": "catalog:","@types/dom-webcodecs": "catalog:","eslint": "catalog:"diff --git a/packages/example/playwright.config.ts b/packages/example/playwright.config.tsnew file mode 100644index 0000000000..72fc706457--- /dev/null+++ b/packages/example/playwright.config.ts@@ -0,0 +1,22 @@+import {defineConfig, devices} from '@playwright/test';++export default defineConfig({+ testDir: './e2e',+ timeout: 60_000,+ expect: {+ timeout: 10_000,+ },+ fullyParallel: false,+ workers: 1,+ retries: 0,+ use: {+ baseURL: 'http://localhost:3123',+ trace: 'on-first-retry',+ },+ projects: [+ {+ name: 'chromium',+ use: {...devices['Desktop Chrome']},+ },+ ],+});diff --git a/packages/example/src/e2e/studio.test.mts b/packages/example/src/e2e/studio.test.mtsnew file mode 100644index 0000000000..c84dbfe242--- /dev/null+++ b/packages/example/src/e2e/studio.test.mts@@ -0,0 +1,160 @@+import {spawn, type ChildProcess} from 'child_process';+import fs from 'fs';+import path from 'path';+import {expect, test} from '@playwright/test';++let studioProcess: ChildProcess | undefined;++const STUDIO_PORT = 3123;+const STUDIO_URL = `http://localhost:${STUDIO_PORT}`;++const exampleDir = path.resolve(+ // @ts-expect-error+ new URL('.', import.meta.url).pathname,+ '..',+);++const remotionBin = path.join(exampleDir, 'node_modules', '.bin', 'remotion');++const rootFile = path.join(exampleDir, 'src', 'Root.tsx');++async function waitForServer(+ url: string,+ timeoutMs: number = 30_000,+): Promise<void> {+ const start = Date.now();+ while (Date.now() - start < timeoutMs) {+ try {+ const res = await fetch(url);+ if (res.ok) {+ return;+ }+ } catch {+ // Server not ready yet+ }++ await new Promise((resolve) => setTimeout(resolve, 500));+ }++ throw new Error(`Server at ${url} did not start within ${timeoutMs}ms`);+}++async function navigateToSchemaTest(page: import('@playwright/test').Page) {+ await page.goto(STUDIO_URL);+ // Expand the "Schema" folder in the sidebar+ const schemaFolder = page.getByTitle('Schema');+ await schemaFolder.click({timeout: 15_000});+ // Click on the schema-test composition inside the folder+ const schemaTestLink = page.getByText('schema-test', {exact: true}).first();+ await schemaTestLink.click({timeout: 10_000});+ await expect(page).toHaveURL(/schema-test/, {timeout: 10_000});+}++let originalRootContent: string;++test.beforeAll(async () => {+ originalRootContent = fs.readFileSync(rootFile, 'utf-8');++ studioProcess = spawn(+ remotionBin,+ ['studio', '--port', String(STUDIO_PORT), '--props', 'src/my-props.json'],+ {+ cwd: exampleDir,+ stdio: 'pipe',+ env: {+ ...process.env,+ BROWSER: 'none',+ },+ },+ );++ studioProcess.stderr?.on('data', (data: Buffer) => {+ const msg = data.toString();+ if (!msg.includes('ExperimentalWarning')) {+ console.error('[studio stderr]', msg);+ }+ });++ studioProcess.stdout?.on('data', (data: Buffer) => {+ console.log('[studio stdout]', data.toString());+ });++ await waitForServer(STUDIO_URL);+});++test.afterAll(async () => {+ if (studioProcess) {+ studioProcess.kill('SIGTERM');+ studioProcess = undefined;+ }++ // Restore original file content+ fs.writeFileSync(rootFile, originalRootContent);+});++test.describe('Remotion Studio', () => {+ test('should load the studio', async ({page}) => {+ await page.goto(STUDIO_URL);+ await expect(page).toHaveTitle(/Remotion/i, {timeout: 15_000});+ });++ test('should show the composition list', async ({page}) => {+ await page.goto(STUDIO_URL);+ // The Schema folder should be visible in the sidebar+ await expect(page.getByRole('button', {name: 'Schema'})).toBeVisible({+ timeout: 15_000,+ });+ });++ test('should navigate to schema-test composition', async ({page}) => {+ await navigateToSchemaTest(page);+ });++ test('should edit a prop and update source code', async ({page}) => {+ // Expand the right sidebar+ await page.goto(STUDIO_URL);+ await page.evaluate(() => {+ window.localStorage.setItem(+ 'remotion.sidebarRightCollapsing',+ 'expanded',+ );+ });+ await page.reload();++ await navigateToSchemaTest(page);++ // Wait for the props editor to load - use the text input, not the nullable checkbox+ const titleInput = page+ .locator(+ 'input[name="title"][type="text"], input[name="title"]:not([type="checkbox"])',+ )+ .first();+ await expect(titleInput).toBeVisible({timeout: 15_000});++ // Clear and type a new value+ const newTitle = 'e2e-test-title';+ await titleInput.fill(newTitle);++ // Blur the input to trigger save to file+ await titleInput.blur();++ // Wait for the file to be updated+ await expect+ .poll(+ () => {+ const content = fs.readFileSync(rootFile, 'utf-8');+ return content.includes(newTitle);+ },+ {+ message: `Expected Root.tsx to contain "${newTitle}" after prop edit`,+ timeout: 10_000,+ },+ )+ .toBe(true);++ // Verify the old value is no longer in the file+ const updatedContent = fs.readFileSync(rootFile, 'utf-8');+ expect(updatedContent).not.toContain("title: 'sdasds'");+ expect(updatedContent).toContain(newTitle);+ });+});