🎥 Make videos programmatically with React
let's start with some tests
JonnyBurger6e9c5c9731d0
diff --git a/packages/studio-server/src/test/update-sequence-props.test.ts b/packages/studio-server/src/test/update-sequence-props.test.tsindex 3754b5a103..cb71f08c12 100644--- a/packages/studio-server/src/test/update-sequence-props.test.ts+++ b/packages/studio-server/src/test/update-sequence-props.test.ts@@ -2,6 +2,7 @@ import {expect, test} from 'bun:test';import path from 'node:path';import type {Expression} from '@babel/types';import {parseAst} from '../codemods/parse-ast';+import {updateSequenceProps} from '../codemods/update-sequence-props';import {extractStaticValue,isStaticValue,@@ -84,3 +85,133 @@ test('canUpdateSequenceProps should flag computed props', () => {codeValue: undefined,});});++const lightLeakInput = `import {LightLeak} from '@remotion/light-leaks';+import React from 'react';+import {AbsoluteFill} from 'remotion';++export const LightLeakExample: React.FC = () => {+ return (+ <AbsoluteFill style={{backgroundColor: 'black'}}>+ <LightLeak durationInFrames={60} seed={1 + 2} hueShift={30} />+ <LightLeak durationInFrames={60} seed={3} hueShift={30} />+ </AbsoluteFill>+ );+};+`;++test('updateSequenceProps should update a number value', () => {+ const {output, oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 8,+ key: 'hueShift',+ value: 90,+ enumPaths: [],+ defaultValue: null,+ });++ expect(oldValueString).toBe('30');+ expect(output).toContain('hueShift={90}');+ // Second LightLeak on line 9 should be unchanged+ expect(output.split('\n')[8]).toContain('hueShift={30}');+});++test('updateSequenceProps should update durationInFrames', () => {+ const {output, oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 9,+ key: 'durationInFrames',+ value: 120,+ enumPaths: [],+ defaultValue: null,+ });++ expect(oldValueString).toBe('60');+ expect(output.split('\n')[8]).toContain('durationInFrames={120}');+ // First LightLeak on line 8 should be unchanged+ expect(output.split('\n')[7]).toContain('durationInFrames={60}');+});++test('updateSequenceProps should add a new attribute', () => {+ const {output, oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 9,+ key: 'speed',+ value: 2,+ enumPaths: [],+ defaultValue: null,+ });++ expect(oldValueString).toBe('');+ expect(output.split('\n')[8]).toContain('speed={2}');+});++test('updateSequenceProps should remove attribute when value equals default', () => {+ const {output, oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 9,+ key: 'hueShift',+ value: 0,+ enumPaths: [],+ defaultValue: 0,+ });++ expect(oldValueString).toBe('30');+ expect(output.split('\n')[8]).not.toContain('hueShift');+ // First LightLeak should still have hueShift+ expect(output.split('\n')[7]).toContain('hueShift={30}');+});++test('updateSequenceProps should set boolean true as shorthand', () => {+ const {output} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 8,+ key: 'loop',+ value: true,+ enumPaths: [],+ defaultValue: false,+ });++ // true booleans become shorthand: `loop` not `loop={true}`+ expect(output.split('\n')[7]).toContain('loop');+ expect(output.split('\n')[7]).not.toContain('loop={true}');+});++test('updateSequenceProps should report oldValueString for computed expressions', () => {+ const {oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 8,+ key: 'seed',+ value: 5,+ enumPaths: [],+ defaultValue: null,+ });++ expect(oldValueString).toBe('1 + 2');+});++test('updateSequenceProps should report default as oldValueString for missing attribute', () => {+ const {oldValueString} = updateSequenceProps({+ input: lightLeakInput,+ targetLine: 8,+ key: 'speed',+ value: 2,+ enumPaths: [],+ defaultValue: 1,+ });++ expect(oldValueString).toBe('1');+});++test('updateSequenceProps should throw for non-existent line', () => {+ expect(() =>+ updateSequenceProps({+ input: lightLeakInput,+ targetLine: 999,+ key: 'hueShift',+ value: 90,+ enumPaths: [],+ defaultValue: null,+ }),+ ).toThrow('Could not find a JSX element at the specified line to update');+});