Skip to content

🎥 Make videos programmatically with React

Add tests for getShouldRenderAudio function

copilot-swe-agent[bot]62db704c537f
diff --git a/packages/renderer/src/test/render-has-audio.test.ts b/packages/renderer/src/test/render-has-audio.test.ts
new file mode 100644
index 0000000000..5470ddccb1
--- /dev/null
+++ b/packages/renderer/src/test/render-has-audio.test.ts
@@ -0,0 +1,151 @@
+import {expect, test} from 'bun:test';
+import {makeDownloadMap} from '../assets/download-map';
+import {getShouldRenderAudio} from '../render-has-audio';
+
+test('getShouldRenderAudio - should return no when muted is true', () => {
+ const downloadMap = makeDownloadMap();
+ const assetsInfo = {
+ assets: [],
+ chunkLengthInSeconds: 1,
+ downloadMap,
+ firstFrameIndex: 0,
+ forSeamlessAacConcatenation: false,
+ imageSequenceName: '/tmp/test-%d.png',
+ trimLeftOffset: 0,
+ trimRightOffset: 0,
+ };
+
+ const result = getShouldRenderAudio({
+ assetsInfo,
+ codec: 'h264',
+ enforceAudioTrack: false,
+ muted: true,
+ });
+
+ expect(result).toBe('no');
+});
+
+test('getShouldRenderAudio - should return no when codec does not support audio', () => {
+ const downloadMap = makeDownloadMap();
+ const assetsInfo = {
+ assets: [],
+ chunkLengthInSeconds: 1,
+ downloadMap,
+ firstFrameIndex: 0,
+ forSeamlessAacConcatenation: false,
+ imageSequenceName: '/tmp/test-%d.png',
+ trimLeftOffset: 0,
+ trimRightOffset: 0,
+ };
+
+ const result = getShouldRenderAudio({
+ assetsInfo,
+ codec: 'gif',
+ enforceAudioTrack: false,
+ muted: false,
+ });
+
+ expect(result).toBe('no');
+});
+
+test('getShouldRenderAudio - should return yes when enforceAudioTrack is true', () => {
+ const downloadMap = makeDownloadMap();
+ const assetsInfo = {
+ assets: [],
+ chunkLengthInSeconds: 1,
+ downloadMap,
+ firstFrameIndex: 0,
+ forSeamlessAacConcatenation: false,
+ imageSequenceName: '/tmp/test-%d.png',
+ trimLeftOffset: 0,
+ trimRightOffset: 0,
+ };
+
+ const result = getShouldRenderAudio({
+ assetsInfo,
+ codec: 'h264',
+ enforceAudioTrack: true,
+ muted: false,
+ });
+
+ expect(result).toBe('yes');
+});
+
+test('getShouldRenderAudio - should return maybe when assetsInfo is null', () => {
+ const result = getShouldRenderAudio({
+ assetsInfo: null,
+ codec: 'h264',
+ enforceAudioTrack: false,
+ muted: false,
+ });
+
+ expect(result).toBe('maybe');
+});
+
+test('getShouldRenderAudio - should return no when there are no frames', () => {
+ const downloadMap = makeDownloadMap();
+ const assetsInfo = {
+ assets: [],
+ chunkLengthInSeconds: 1,
+ downloadMap,
+ firstFrameIndex: 0,
+ forSeamlessAacConcatenation: false,
+ imageSequenceName: '/tmp/test-%d.png',
+ trimLeftOffset: 0,
+ trimRightOffset: 0,
+ };
+
+ const result = getShouldRenderAudio({
+ assetsInfo,
+ codec: 'h264',
+ enforceAudioTrack: false,
+ muted: false,
+ });
+
+ expect(result).toBe('no');
+});
+
+test('getShouldRenderAudio - should return yes when there are audio assets', () => {
+ const downloadMap = makeDownloadMap();
+ const assetsInfo = {
+ assets: [
+ {
+ frame: 0,
+ audioAndVideoAssets: [
+ {
+ type: 'audio' as const,
+ src: 'test.mp3',
+ id: 'test',
+ frame: 0,
+ volume: 1,
+ mediaFrame: 0,
+ playbackRate: 1,
+ allowAmplificationDuringRender: false,
+ toneFrequency: 1,
+ audioStartFrame: 0,
+ trimLeft: 0,
+ audioStreamIndex: 0,
+ },
+ ],
+ artifactAssets: [],
+ inlineAudioAssets: [],
+ },
+ ],
+ chunkLengthInSeconds: 1,
+ downloadMap,
+ firstFrameIndex: 0,
+ forSeamlessAacConcatenation: false,
+ imageSequenceName: '/tmp/test-%d.png',
+ trimLeftOffset: 0,
+ trimRightOffset: 0,
+ };
+
+ const result = getShouldRenderAudio({
+ assetsInfo,
+ codec: 'h264',
+ enforceAudioTrack: false,
+ muted: false,
+ });
+
+ expect(result).toBe('yes');
+});