Skip to content

🎥 Make videos programmatically with React

feat: add a scale testing fixture

clearlysid196ff96aa065
diff --git a/packages/web-renderer/src/test/Root.tsx b/packages/web-renderer/src/test/Root.tsx
index eb73bffd26..b02c674277 100644
--- a/packages/web-renderer/src/test/Root.tsx
+++ b/packages/web-renderer/src/test/Root.tsx
@@ -66,6 +66,7 @@ import {transformWithTranslate} from './fixtures/transforms/transform-with-trans
import {withMargin} from './fixtures/transforms/with-margin';
import {withNegativeMargin} from './fixtures/transforms/with-negative-margin';
import {unwrapped} from './fixtures/unwrapped';
+import {scaleFixture} from './fixtures/scale';
export const Root: React.FC = () => {
return (
@@ -145,6 +146,7 @@ export const Root: React.FC = () => {
<Composition {...manyLayers} />
<Composition {...threeDFlattening} />
</Folder>
+ <Composition {...scaleFixture} />
</>
);
};
diff --git a/packages/web-renderer/src/test/fixtures/scale.tsx b/packages/web-renderer/src/test/fixtures/scale.tsx
new file mode 100644
index 0000000000..dc17747a7a
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/scale.tsx
@@ -0,0 +1,42 @@
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: 'white',
+ }}
+ >
+ <div
+ style={{
+ backgroundColor: 'red',
+ width: 50,
+ height: 50,
+ }}
+ />
+ <div
+ style={{
+ position: 'absolute',
+ top: 10,
+ left: 10,
+ fontSize: 12,
+ fontFamily: 'Arial',
+ color: 'black',
+ }}
+ >
+ Scale Test
+ </div>
+ </AbsoluteFill>
+ );
+};
+
+export const scaleFixture = {
+ component: Component,
+ id: 'scale-test',
+ width: 100,
+ height: 100,
+ fps: 30,
+ durationInFrames: 1,
+} as const;
diff --git a/packages/web-renderer/src/test/scale.test.tsx b/packages/web-renderer/src/test/scale.test.tsx
new file mode 100644
index 0000000000..47f08b1b8e
--- /dev/null
+++ b/packages/web-renderer/src/test/scale.test.tsx
@@ -0,0 +1,77 @@
+import {expect, test} from 'vitest';
+import {renderStillOnWeb} from '../render-still-on-web';
+import '../symbol-dispose';
+import {scaleFixture} from './fixtures/scale';
+import {testImage} from './utils';
+
+test('scale=1 should render at original dimensions', async () => {
+ const {blob} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ scale: 1,
+ });
+
+ await testImage({blob, testId: 'scale-1x'});
+});
+
+test('scale=2 should render at 2x dimensions', async () => {
+ const {blob} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ scale: 2,
+ });
+
+ await testImage({blob, testId: 'scale-2x'});
+});
+
+test('scale should increase output blob size', async () => {
+ const {blob: blob1x} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ scale: 1,
+ });
+
+ const {blob: blob2x} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ scale: 2,
+ });
+
+ // scale=2 produces 4x pixels (2x width * 2x height)
+ // PNG compression varies but 2x blob should be noticeably larger
+ expect(blob2x.size).toBeGreaterThan(blob1x.size * 1.5);
+});
+
+test('scale should default to 1 when not specified', async () => {
+ const {blob: blobDefault} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ });
+
+ const {blob: blobExplicit} = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: scaleFixture,
+ frame: 0,
+ inputProps: {},
+ imageFormat: 'png',
+ scale: 1,
+ });
+
+ // Should produce same size when scale defaults to 1
+ expect(blobDefault.size).toBe(blobExplicit.size);
+});