Skip to content

🎥 Make videos programmatically with React

clean all downloadmaps we create in test

Jonny Burger6af99b45c87f
diff --git a/packages/renderer/src/test/compositor.test.ts b/packages/renderer/src/test/compositor.test.ts
index 3e6983450b..f9bcab7671 100644
--- a/packages/renderer/src/test/compositor.test.ts
+++ b/packages/renderer/src/test/compositor.test.ts
@@ -1,5 +1,5 @@
import {expect, test} from 'vitest';
-import {RenderInternals} from '..';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {compose} from '../compositor/compose';
import type {Layer} from '../compositor/payloads';
@@ -10,15 +10,18 @@ test('Should handle the overlay', async () => {
invalid: 'json',
},
];
+ const map = makeDownloadMap();
await compose({
height: 1080,
width: 1080,
layers: layers as unknown as Layer[],
output: 'test.mp4',
- downloadMap: RenderInternals.makeDownloadMap(),
+ downloadMap: map,
imageFormat: 'Png',
});
+ cleanDownloadMap(map);
+
throw new Error('should not reach here');
} catch (err) {
console.log(err);
diff --git a/packages/renderer/src/test/extract-frame-from-video.test.ts b/packages/renderer/src/test/extract-frame-from-video.test.ts
index a8e1462f46..66965ba5c3 100644
--- a/packages/renderer/src/test/extract-frame-from-video.test.ts
+++ b/packages/renderer/src/test/extract-frame-from-video.test.ts
@@ -1,6 +1,6 @@
import path from 'path';
import {expect, test} from 'vitest';
-import {makeDownloadMap} from '../assets/download-map';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {extractFrameFromVideo} from '../extract-frame-from-video';
const src = path.join(
@@ -14,43 +14,53 @@ const src = path.join(
);
test('Should be able to extract a frame from a video', async () => {
+ const downloadMap = makeDownloadMap();
const str = await extractFrameFromVideo({
ffmpegExecutable: null,
ffprobeExecutable: null,
src,
time: 1,
imageFormat: 'jpeg',
- downloadMap: makeDownloadMap(),
+ downloadMap,
remotionRoot: process.cwd(),
});
+ cleanDownloadMap(downloadMap);
+
expect(str.length).toBeGreaterThan(10000);
});
test('Should be able to extract a frame from a video as PNG', async () => {
+ const downloadMap = makeDownloadMap();
+
const str = await extractFrameFromVideo({
ffmpegExecutable: null,
ffprobeExecutable: null,
src,
time: 1,
imageFormat: 'png',
- downloadMap: makeDownloadMap(),
+ downloadMap,
remotionRoot: process.cwd(),
});
+ cleanDownloadMap(downloadMap);
expect(str.length).toBeGreaterThan(10000);
});
test('Should get the last frame if out of range', async () => {
+ const downloadMap = makeDownloadMap();
+
const str = await extractFrameFromVideo({
ffmpegExecutable: null,
ffprobeExecutable: null,
src,
time: 100,
imageFormat: 'jpeg',
- downloadMap: makeDownloadMap(),
+ downloadMap,
remotionRoot: process.cwd(),
});
+ cleanDownloadMap(downloadMap);
+
expect(str.length).toBeGreaterThan(10000);
});
diff --git a/packages/renderer/src/test/get-audio-channels.test.ts b/packages/renderer/src/test/get-audio-channels.test.ts
index d78318eee5..4ba81615cb 100644
--- a/packages/renderer/src/test/get-audio-channels.test.ts
+++ b/packages/renderer/src/test/get-audio-channels.test.ts
@@ -1,7 +1,7 @@
import {existsSync} from 'fs';
import path from 'path';
import {expect, test} from 'vitest';
-import {makeDownloadMap} from '../assets/download-map';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {getAudioChannelsAndDuration} from '../assets/get-audio-channels';
test('Get audio channels for video', async () => {
@@ -23,6 +23,7 @@ test('Get audio channels for video', async () => {
null,
process.cwd()
);
+ cleanDownloadMap(downloadMap);
expect(channels).toEqual({channels: 2, duration: 10});
}, 90000);
@@ -45,6 +46,8 @@ test('Get audio channels for video without music', async () => {
null,
process.cwd()
);
+ cleanDownloadMap(downloadMap);
+
expect(channels.channels).toEqual(0);
expect(channels.duration).toBeCloseTo(3.334, 2);
}, 90000);
@@ -68,12 +71,15 @@ test('Get audio channels for video with music', async () => {
null,
process.cwd()
);
+ cleanDownloadMap(downloadMap);
+
expect(channels).toEqual({channels: 2, duration: 56.529});
}, 90000);
test('Throw error if parsing a non video file', () => {
const downloadMap = makeDownloadMap();
const tsFile = path.join(__dirname, '..', 'ffmpeg-flags.ts');
+ cleanDownloadMap(downloadMap);
expect(existsSync(tsFile)).toEqual(true);
expect(() =>
getAudioChannelsAndDuration(downloadMap, tsFile, null, process.cwd())
diff --git a/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts b/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
index 86561c194b..8391a81c14 100644
--- a/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
+++ b/packages/renderer/src/test/get-last-frame-of-corrupted-video.test.ts
@@ -1,10 +1,11 @@
import path from 'path';
import process from 'process';
import {test} from 'vitest';
-import {makeDownloadMap} from '../assets/download-map';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {getLastFrameOfVideo} from '../extract-frame-from-video';
test('Get last frame of corrupted video', async () => {
+ const downloadMap = makeDownloadMap();
await getLastFrameOfVideo({
ffmpegExecutable: null,
ffprobeExecutable: null,
@@ -21,7 +22,8 @@ test('Get last frame of corrupted video', async () => {
imageFormat: 'png',
specialVCodecForTransparency: 'none',
needsResize: null,
- downloadMap: makeDownloadMap(),
+ downloadMap,
remotionRoot: process.cwd(),
});
+ cleanDownloadMap(downloadMap);
}, 90000);
diff --git a/packages/renderer/src/test/last-frame-video-cache.test.ts b/packages/renderer/src/test/last-frame-video-cache.test.ts
index 42b78a91cd..2f79cb5eae 100644
--- a/packages/renderer/src/test/last-frame-video-cache.test.ts
+++ b/packages/renderer/src/test/last-frame-video-cache.test.ts
@@ -1,7 +1,7 @@
import crypto from 'crypto';
import {expect, test} from 'vitest';
import type {DownloadMap} from '../assets/download-map';
-import {makeDownloadMap} from '../assets/download-map';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import type {LastFrameOptions} from '../last-frame-from-video-cache';
import {
clearLastFileCache,
@@ -65,4 +65,5 @@ test('Last frame video cache', () => {
).toBe(10 * 1024 * 1024);
clearLastFileCache(downloadMap);
+ cleanDownloadMap(downloadMap);
});
diff --git a/packages/renderer/src/test/render-still.test.ts b/packages/renderer/src/test/render-still.test.ts
index 59d3d4a602..1c8e7189f9 100644
--- a/packages/renderer/src/test/render-still.test.ts
+++ b/packages/renderer/src/test/render-still.test.ts
@@ -1,9 +1,10 @@
import {expect, test} from 'vitest';
-import {makeDownloadMap} from '../assets/download-map';
+import {cleanDownloadMap, makeDownloadMap} from '../assets/download-map';
import {renderStill} from '../render-still';
-test('Need to pass valid metadata', () => {
- return expect(() =>
+test('Need to pass valid metadata', async () => {
+ const downloadMap = makeDownloadMap();
+ await expect(() =>
renderStill({
composition: {
width: NaN,
@@ -16,12 +17,14 @@ test('Need to pass valid metadata', () => {
frame: 0,
output: '/file/output.png',
serveUrl: 'https://gleaming-wisp-de5d2a.netlify.app/',
- downloadMap: makeDownloadMap(),
+ downloadMap,
})
).rejects.toThrow(/not be NaN, but is NaN/);
+ cleanDownloadMap(downloadMap);
});
test('Returns buffer in promise result', async () => {
+ const downloadMap = makeDownloadMap();
const {buffer} = await renderStill({
composition: {
width: 1000,
@@ -33,12 +36,14 @@ test('Returns buffer in promise result', async () => {
},
frame: 0,
serveUrl: 'https://gleaming-wisp-de5d2a.netlify.app/',
- downloadMap: makeDownloadMap(),
+ downloadMap,
});
- return expect(buffer?.length).toBeGreaterThan(1000);
+ expect(buffer?.length).toBeGreaterThan(1000);
+ cleanDownloadMap(downloadMap);
});
test('Need to pass valid metadata', () => {
+ const downloadMap = makeDownloadMap();
return expect(() =>
renderStill({
composition: {
@@ -52,7 +57,7 @@ test('Need to pass valid metadata', () => {
frame: 200,
output: '/file/output.png',
serveUrl: 'https://gleaming-wisp-de5d2a.netlify.app/',
- downloadMap: makeDownloadMap(),
+ downloadMap,
})
).rejects.toThrow(
/Cannot use frame 200: Duration of composition is 30, therefore the highest frame that can be rendered is 29/