Skip to content

🎥 Make videos programmatically with React

added further test cases

Tobias Boner68ab5b10eb39
diff --git a/packages/core/src/config/image-format.ts b/packages/core/src/config/image-format.ts
index 8ace1bf422..15b4f52b63 100644
--- a/packages/core/src/config/image-format.ts
+++ b/packages/core/src/config/image-format.ts
@@ -25,6 +25,11 @@ export const validateSelectedPixelFormatAndImageFormatCombination = (
pixelFormat: PixelFormat,
imageFormat: ImageFormat
) => {
+ if (!validOptions.includes(imageFormat)) {
+ throw new TypeError(
+ `Value ${imageFormat} is not valid as an image format.`
+ );
+ }
if (pixelFormat !== 'yuva420p') {
return;
}
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index 3c57e96f54..2aa5410300 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -25,8 +25,7 @@ test('It should throw if multiple components have the same id', () => {
/The "width/
);
});
-
-test('It should throw if multiple components have the same id', () => {
+test('It should throw if height is a negative number', () => {
expectToThrow(
() =>
render(
@@ -44,3 +43,292 @@ test('It should throw if multiple components have the same id', () => {
/The "height" of a composition must be positive, but got -100./
);
});
+test('It should throw if height=0 is boundary off-point', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={0}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "height" of a composition must be positive, but got 0./
+ );
+});
+test('It should not throw if height is a positive number', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should not throw if height=1 is boundary on-point', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={1}
+ width={100}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should throw if height is not a number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ // @ts-expect-error
+ height={'100'}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "height" of a composition must be a number, but you passed a string/
+ );
+});
+
+test('It should throw if width is a negative number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ width={-100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "width" of a composition must be positive, but got -100./
+ );
+});
+test('It should throw if width=0 is boundary off-point', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ width={0}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "width" of a composition must be positive, but got 0./
+ );
+});
+test('It should not throw if width is a positive number', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should not throw if width=1 is boundary on-point', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ width={1}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should throw if width is not a number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={30}
+ height={100}
+ // @ts-expect-error
+ width={'100'}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "width" of a composition must be a number, but you passed a string/
+ );
+});
+
+test('It should throw if durationInFrames of a composition is a negative number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={-100}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "durationInFrames" of a composition must be positive, but got -100./
+ );
+});
+test('It should throw if durationInFrames=0 of a composition is boundary off-point', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={0}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "durationInFrames" of a composition must be positive, but got 0./
+ );
+});
+test('It should not throw if durationInFrames=1 of a composition is boundary on-point', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={1}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should throw if durationInFrames of a composition is not a number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ // @ts-expect-error
+ durationInFrames={'100'}
+ fps={30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "durationInFrames" of a composition must be a number, but you passed a string/
+ );
+});
+
+test('It should throw if fps is of a composition is negative', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={-30}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "fps" of a composition must be positive, but got -30./
+ );
+});
+test('It should throw if fps=0 of a composition is boundary off-point', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={0}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "fps" of a composition must be positive, but got 0./
+ );
+});
+test('It should not throw if fps=1 of a composition is boundary on-point', () => {
+ expect(() =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={1}
+ height={100}
+ width={100}
+ id="id"
+ />
+ )
+ ).not.toThrow();
+});
+test('It should throw if fps of a composition is not a number', () => {
+ expectToThrow(
+ () =>
+ render(
+ <RemotionRoot>
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ // @ts-expect-error
+ fps={'30'}
+ height={100}
+ width={100}
+ id="id"
+ />
+ </RemotionRoot>
+ ),
+ /The "fps" of a composition must be a number, but you passed a string/
+ );
+});
diff --git a/packages/core/src/test/image-format.test.ts b/packages/core/src/test/image-format.test.ts
new file mode 100644
index 0000000000..35e2b7f67c
--- /dev/null
+++ b/packages/core/src/test/image-format.test.ts
@@ -0,0 +1,49 @@
+import {
+ setImageFormat,
+ validateSelectedPixelFormatAndImageFormatCombination,
+} from '../config/image-format';
+import {expectToThrow} from './expect-to-throw';
+
+test('It should throw if image format is not valid', () => {
+ expectToThrow(
+ () =>
+ setImageFormat(
+ // @ts-expect-error
+ 'invalidImageFormat'
+ ),
+ /Value invalidImageFormat is not valid as an image format./
+ );
+});
+test('It should throw if image format is not valid', () => {
+ expectToThrow(
+ () =>
+ validateSelectedPixelFormatAndImageFormatCombination(
+ 'yuv420p',
+ // @ts-expect-error
+ 'invalidImageFormat'
+ ),
+ /Value invalidImageFormat is not valid as an image format./
+ );
+});
+test('It should throw if pixel and image format combination is not valid', () => {
+ expectToThrow(
+ () =>
+ validateSelectedPixelFormatAndImageFormatCombination('yuva420p', 'jpeg'),
+ /Pixel format was set to 'yuva420p' but the image format is not PNG. To render transparent videos, you need to set PNG as the image format./
+ );
+});
+test('It should not throw if pixel and image format combination is valid', () => {
+ expect(() =>
+ validateSelectedPixelFormatAndImageFormatCombination('yuva420p', 'png')
+ ).not.toThrow();
+});
+test('It should not throw if pixel and image format combination is valid', () => {
+ expect(() =>
+ validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'png')
+ ).not.toThrow();
+});
+test('It should not throw if pixel and image format combination is valid', () => {
+ expect(() =>
+ validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'jpeg')
+ ).not.toThrow();
+});
diff --git a/packages/core/src/test/sequence-validation.test.tsx b/packages/core/src/test/sequence-validation.test.tsx
index 40dc4871c3..961dcad0ab 100644
--- a/packages/core/src/test/sequence-validation.test.tsx
+++ b/packages/core/src/test/sequence-validation.test.tsx
@@ -21,10 +21,12 @@ test('It should allow null as children', () => {
).not.toThrow();
});
-test('It should not allow no children at all', () => {
- expectToThrow(
- // @ts-expect-error
- () => render(<Sequence from={0} />),
- /You passed to durationInFrames an argument of type undefined, but it must be a number./
- );
+test('It should allow undefined as children', () => {
+ expect(() =>
+ render(
+ <Sequence durationInFrames={100} from={0}>
+ {undefined}
+ </Sequence>
+ )
+ ).not.toThrow();
});