Skip to content

🎥 Make videos programmatically with React

e2e for updating values

Jonny Burgera28b3e8bd758
diff --git a/packages/example/e2e/constants.mts b/packages/example/e2e/constants.mts
index 8980fcd02a..3e705008a2 100644
--- a/packages/example/e2e/constants.mts
+++ b/packages/example/e2e/constants.mts
@@ -11,6 +11,12 @@ export const exampleDir = path.resolve(
);
export const rootFile = path.join(exampleDir, 'src', 'Root.tsx');
+export const visualControlsFile = path.join(
+ exampleDir,
+ 'src',
+ 'VisualControls',
+ 'index.tsx',
+);
export const newVideoFile = path.join(exampleDir, 'src', 'NewVideo.tsx');
export const remotionBin = path.join(
exampleDir,
@@ -27,6 +33,10 @@ export const ORIGINAL_CONTENT_FILE = path.join(
os.tmpdir(),
'remotion-e2e-original-root.tsx',
);
+export const ORIGINAL_VISUAL_CONTROLS_FILE = path.join(
+ os.tmpdir(),
+ 'remotion-e2e-original-visual-controls.tsx',
+);
export const PID_FILE = path.join(os.tmpdir(), 'remotion-e2e-studio.pid');
export const EXPANDED_SIDEBAR_STATE = path.join(
os.tmpdir(),
diff --git a/packages/example/e2e/global-setup.mts b/packages/example/e2e/global-setup.mts
index 793ee5618b..44617c3824 100644
--- a/packages/example/e2e/global-setup.mts
+++ b/packages/example/e2e/global-setup.mts
@@ -4,12 +4,14 @@ import {
EXPANDED_SIDEBAR_STATE,
LOGS_FILE,
ORIGINAL_CONTENT_FILE,
+ ORIGINAL_VISUAL_CONTROLS_FILE,
PID_FILE,
STUDIO_PORT,
STUDIO_URL,
exampleDir,
remotionBin,
rootFile,
+ visualControlsFile,
} from './constants.mts';
async function waitForServer(
@@ -35,6 +37,10 @@ async function waitForServer(
export default async function globalSetup(): Promise<void> {
fs.writeFileSync(ORIGINAL_CONTENT_FILE, fs.readFileSync(rootFile, 'utf-8'));
+ fs.writeFileSync(
+ ORIGINAL_VISUAL_CONTROLS_FILE,
+ fs.readFileSync(visualControlsFile, 'utf-8'),
+ );
fs.writeFileSync(LOGS_FILE, '');
fs.writeFileSync(
EXPANDED_SIDEBAR_STATE,
diff --git a/packages/example/e2e/global-teardown.mts b/packages/example/e2e/global-teardown.mts
index 87f8e60de7..10f5a3b892 100644
--- a/packages/example/e2e/global-teardown.mts
+++ b/packages/example/e2e/global-teardown.mts
@@ -1,5 +1,11 @@
import fs from 'fs';
-import {ORIGINAL_CONTENT_FILE, PID_FILE, rootFile} from './constants.mts';
+import {
+ ORIGINAL_CONTENT_FILE,
+ ORIGINAL_VISUAL_CONTROLS_FILE,
+ PID_FILE,
+ rootFile,
+ visualControlsFile,
+} from './constants.mts';
export default async function globalTeardown(): Promise<void> {
if (fs.existsSync(PID_FILE)) {
@@ -20,4 +26,12 @@ export default async function globalTeardown(): Promise<void> {
);
fs.unlinkSync(ORIGINAL_CONTENT_FILE);
}
+
+ if (fs.existsSync(ORIGINAL_VISUAL_CONTROLS_FILE)) {
+ fs.writeFileSync(
+ visualControlsFile,
+ fs.readFileSync(ORIGINAL_VISUAL_CONTROLS_FILE, 'utf-8'),
+ );
+ fs.unlinkSync(ORIGINAL_VISUAL_CONTROLS_FILE);
+ }
}
diff --git a/packages/example/e2e/helpers.mts b/packages/example/e2e/helpers.mts
index 479479c6e6..3be4ab3235 100644
--- a/packages/example/e2e/helpers.mts
+++ b/packages/example/e2e/helpers.mts
@@ -12,6 +12,17 @@ export async function navigateToSchemaTest(page: Page): Promise<void> {
await expect(page).toHaveURL(/schema-test/, {timeout: 10_000});
}
+export async function navigateToVisualControls(page: Page): Promise<void> {
+ await page.goto(STUDIO_URL);
+ const folder = page.getByTitle('visual-controls');
+ await folder.click({timeout: 15_000});
+ const compositionLink = page
+ .getByText('visual-controls', {exact: true})
+ .first();
+ await compositionLink.click({timeout: 10_000});
+ await expect(page).toHaveURL(/visual-controls/, {timeout: 10_000});
+}
+
export const stripAnsi = (s: string) =>
// eslint-disable-next-line no-control-regex
s.replace(/\x1b\[[0-9;]*m/g, '').replace(/\]8;;[^\x1b]*\x1b\\/g, '');
diff --git a/packages/example/e2e/visual-controls.test.mts b/packages/example/e2e/visual-controls.test.mts
new file mode 100644
index 0000000000..4c8bc4715c
--- /dev/null
+++ b/packages/example/e2e/visual-controls.test.mts
@@ -0,0 +1,62 @@
+import fs from 'fs';
+import {expect, test} from '@playwright/test';
+import {EXPANDED_SIDEBAR_STATE, visualControlsFile} from './constants.mts';
+import {navigateToVisualControls} from './helpers.mts';
+
+test.use({storageState: EXPANDED_SIDEBAR_STATE});
+
+test.describe('visual controls', () => {
+ let originalContent: string;
+
+ test.beforeEach(() => {
+ originalContent = fs.readFileSync(visualControlsFile, 'utf-8');
+ });
+
+ test.afterEach(() => {
+ fs.writeFileSync(visualControlsFile, originalContent);
+ });
+
+ test('should edit rotation and update source file', async ({page}) => {
+ await navigateToVisualControls(page);
+
+ // Click the Controls tab on the right panel
+ const controlsTab = page.getByText('Controls', {exact: true});
+ await expect(controlsTab).toBeVisible({timeout: 15_000});
+ await controlsTab.click();
+
+ // Find the rotation control's fieldset via the data-json-path label
+ const rotationFieldset = page
+ .locator('[data-json-path="rotation"]')
+ .locator('..');
+ await expect(rotationFieldset).toBeVisible({timeout: 10_000});
+
+ // Click the dragger button to activate the number input
+ const dragger = rotationFieldset.locator(
+ 'button.__remotion_input_dragger',
+ );
+ await expect(dragger).toBeVisible({timeout: 5_000});
+ await dragger.click();
+
+ // Fill the now-visible input with a new value
+ const input = rotationFieldset.locator('input');
+ await expect(input).toBeVisible({timeout: 5_000});
+
+ const newRotation = '42';
+ await input.fill(newRotation);
+ await input.press('Enter');
+
+ // Wait for the source file to be updated on disk
+ await expect
+ .poll(
+ () => {
+ const content = fs.readFileSync(visualControlsFile, 'utf-8');
+ return content.includes(`'rotation', ${newRotation}`);
+ },
+ {
+ message: `Expected VisualControls/index.tsx to contain rotation value ${newRotation}`,
+ timeout: 10_000,
+ },
+ )
+ .toBe(true);
+ });
+});