🎥 Make videos programmatically with React
separate tests for same tests with different input and group them together & add missing test cases
Calvin Falter81fd79601a0e
diff --git a/packages/core/src/config/image-format.ts b/packages/core/src/config/image-format.tsindex d6b2ddb2a6..e6a5e98d4b 100644--- a/packages/core/src/config/image-format.ts+++ b/packages/core/src/config/image-format.ts@@ -7,7 +7,7 @@ export type ImageFormat = typeof validOptions[number];let currentImageFormat: ImageFormat | undefined = undefined;export const setImageFormat = (format: ImageFormat) => {- if (typeof format === undefined) {+ if (typeof format === 'undefined') {currentImageFormat = undefined;return;}diff --git a/packages/core/src/test/codec.test.ts b/packages/core/src/test/codec.test.tsindex ed7e22e122..5e0c24eb5a 100644--- a/packages/core/src/test/codec.test.ts+++ b/packages/core/src/test/codec.test.ts@@ -7,48 +7,66 @@ import {// getFinalOutputCodec-test('Codec tests valid codec input', () => {- const validCodecInput: CodecOrUndefined[] = ['h264', 'h265', 'vp8', 'vp9'];+describe('Codec tests valid codec input', () => {+ const validCodecInput: CodecOrUndefined[] = [+ 'h264',+ 'h265',+ 'vp8',+ 'vp9',+ 'mp3',+ 'aac',+ 'wav',+ ];validCodecInput.forEach((entry) =>- expect(- getFinalOutputCodec({codec: entry, emitWarning: false, fileExtension: ''})- ).toEqual(entry)+ test(`codec ${entry}`, () =>+ expect(+ getFinalOutputCodec({+ codec: entry,+ emitWarning: false,+ fileExtension: '',+ })+ ).toEqual(entry)));});-test('Codec tests undefined codec input with known extension', () => {- expect(- getFinalOutputCodec({- codec: undefined,- emitWarning: false,- fileExtension: 'webm',- })- ).toEqual('vp8');- expect(- getFinalOutputCodec({- codec: undefined,- emitWarning: false,- fileExtension: 'hevc',- })- ).toEqual('h265');+describe('Codec tests undefined codec input with known extension', () => {+ const codecExtensionCombination: [string, string][] = [+ ['vp8', 'webm'],+ ['h265', 'hevc'],+ ['mp3', 'mp3'],+ ['wav', 'wav'],+ ['aac', 'aac'],+ ['aac', 'm4a'],+ ];+ codecExtensionCombination.forEach((entry) =>+ test(`${entry[1]} should be recognized as ${entry[0]}`, () =>+ expect(+ getFinalOutputCodec({+ codec: undefined,+ emitWarning: false,+ fileExtension: entry[1],+ })+ ).toEqual(entry[0]))+ );});-test('Codec tests undefined codec input with unknown extension', () => {+describe('Codec tests undefined codec input with unknown extension', () => {const unknownExtensions = ['', 'abc'];- unknownExtensions.forEach((entry) => {- expect(- getFinalOutputCodec({- codec: undefined,- emitWarning: false,- fileExtension: entry,- })- ).toEqual('h264');- });+ unknownExtensions.forEach((entry) =>+ test(`testing with "${entry}" as extension`, () =>+ expect(+ getFinalOutputCodec({+ codec: undefined,+ emitWarning: false,+ fileExtension: entry,+ })+ ).toEqual('h264'))+ );});// setCodec-test('Codec tests setOutputFormat', () => {+describe('Codec tests setOutputFormat', () => {const validCodecInputs: CodecOrUndefined[] = ['h264','h265',@@ -56,8 +74,10 @@ test('Codec tests setOutputFormat', () => {'vp9',undefined,];- validCodecInputs.forEach((entry) => {- setCodec(entry);- expect(getOutputCodecOrUndefined()).toEqual(entry);- });+ validCodecInputs.forEach((entry) =>+ test(`testing with ${entry}`, () => {+ setCodec(entry);+ expect(getOutputCodecOrUndefined()).toEqual(entry);+ })+ );});diff --git a/packages/core/src/test/crf.test.ts b/packages/core/src/test/crf.test.tsindex ae779a90d9..c826109134 100644--- a/packages/core/src/test/crf.test.ts+++ b/packages/core/src/test/crf.test.ts@@ -8,7 +8,7 @@ import {} from '../config/crf';import {expectToThrow} from './expect-to-throw';-test('crf tests getDefaultCrfForCodec valid input', () => {+describe('crf tests getDefaultCrfForCodec valid input', () => {// input codec, outputconst validCodecIOs: [Codec, number][] = [['h264', 18],@@ -17,23 +17,25 @@ test('crf tests getDefaultCrfForCodec valid input', () => {['vp9', 28],] as [Codec, number][];validCodecIOs.forEach((entry) =>- expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1])+ test(`default for ${entry[0]} should be ${entry[1]}`, () =>+ expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1])));});-test('crf tests getDefaultCrfForCodec invalid input', () => {+describe('crf tests getDefaultCrfForCodec invalid input', () => {// input codecconst invalidCodecs = ['abc', '', 3, undefined];invalidCodecs.forEach((entry) =>- expectToThrow(- // @ts-expect-error- () => getDefaultCrfForCodec(entry),- new RegExp(`Got unexpected codec "${entry}"`)- )+ test(`testing with ${entry}`, () =>+ expectToThrow(+ // @ts-expect-error+ () => getDefaultCrfForCodec(entry),+ new RegExp(`Got unexpected codec "${entry}"`)+ )));});-test('crf tests getValidCrfRanges valid input', () => {+describe('crf tests getValidCrfRanges valid input', () => {// input crf, input codec, valid rangeconst validInputs: [Codec, [number, number]][] = [['h264', [0, 51]],@@ -42,23 +44,25 @@ test('crf tests getValidCrfRanges valid input', () => {['vp9', [0, 63]],] as [Codec, [number, number]][];validInputs.forEach((entry) =>- expect(getValidCrfRanges(entry[0])).toEqual(entry[1])+ test(`valid range for ${entry[0]} should be [${entry[1]}]`, () =>+ expect(getValidCrfRanges(entry[0])).toEqual(entry[1])));});-test('crf tests getValidCrfRanges invalid input', () => {+describe('crf tests getValidCrfRanges invalid input', () => {// input codecconst invalidInputs = ['abc', '', 3, undefined];invalidInputs.forEach((entry) =>- expectToThrow(- // @ts-expect-error- () => getValidCrfRanges(entry),- new RegExp(`Got unexpected codec "${entry}"`)- )+ test(`testing with "${entry}"`, () =>+ expectToThrow(+ // @ts-expect-error+ () => getValidCrfRanges(entry),+ new RegExp(`Got unexpected codec "${entry}"`)+ )));});-test('validateSelectedCrfAndCodecCombination valid input', () => {+describe('validateSelectedCrfAndCodecCombination valid input', () => {// input crf, input codecconst validInputs: [number, Codec][] = [[20, 'h264'],@@ -75,13 +79,14 @@ test('validateSelectedCrfAndCodecCombination valid input', () => {[63, 'vp9'],] as [number, Codec][];validInputs.forEach((entry) =>- expect(() =>- validateSelectedCrfAndCodecCombination(entry[0], entry[1])- ).not.toThrow()+ test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>+ expect(() =>+ validateSelectedCrfAndCodecCombination(entry[0], entry[1])+ ).not.toThrow()));});-test('validateSelectedCrfAndCodecCombination invalid input', () => {+describe('validateSelectedCrfAndCodecCombination invalid input', () => {// input crf, input codec, valid rangeconst invalidInputs: [number, Codec, [number, number]][] = [[80, 'h264', [0, 51]],@@ -98,16 +103,17 @@ test('validateSelectedCrfAndCodecCombination invalid input', () => {[64, 'vp9', [0, 63]],] as [number, Codec, [number, number]][];invalidInputs.forEach((entry) =>- expectToThrow(- () => validateSelectedCrfAndCodecCombination(entry[0], entry[1]),- new RegExp(- `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`- )- )+ test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>+ expectToThrow(+ () => validateSelectedCrfAndCodecCombination(entry[0], entry[1]),+ new RegExp(+ `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`+ )+ )));});-test('get crf valid input', () => {+describe('get crf valid input', () => {// input crf, input codec, output crfconst validInputs: [number | undefined, Codec, number][] = [[20, 'h264', 20],@@ -119,10 +125,12 @@ test('get crf valid input', () => {[20, 'vp9', 20],[undefined, 'vp9', 28],] as [number | undefined, Codec, number][];- validInputs.forEach((entry) => {- setCrf(entry[0]);- expect(getActualCrf(entry[1])).toEqual(entry[2]);- });+ validInputs.forEach((entry) =>+ test(`test with crf ${entry[0]} and codec ${entry[1]}`, () => {+ setCrf(entry[0]);+ expect(getActualCrf(entry[1])).toEqual(entry[2]);+ })+ );});test('get crf invalid input', () => {diff --git a/packages/core/src/test/image-format.test.ts b/packages/core/src/test/image-format.test.tsindex 0efb312204..770d46a8e3 100644--- a/packages/core/src/test/image-format.test.ts+++ b/packages/core/src/test/image-format.test.ts@@ -1,9 +1,27 @@import {+ getUserPreferredImageFormat,+ ImageFormat,setImageFormat,validateSelectedPixelFormatAndImageFormatCombination,} from '../config/image-format';import {expectToThrow} from './expect-to-throw';+describe('SetImageFormat with valid inputs', () => {+ const formatInputs: (ImageFormat | undefined)[] = [+ 'png',+ 'jpeg',+ 'none',+ undefined,+ ];+ formatInputs.forEach((entry) =>+ test(`testing with format "${entry}"`, () => {+ // @ts-expect-error+ setImageFormat(entry);+ expect(getUserPreferredImageFormat()).toEqual(entry);+ })+ );+});+test('SetImageFormat should throw if image format is not valid', () => {expectToThrow(() =>@@ -48,3 +66,8 @@ test('Valid combination with pixel and image format ("jpeg") should not throw',validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'jpeg')).not.toThrow();});+test('"none" as image format should not throw', () => {+ expect(() =>+ validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'none')+ ).not.toThrow();+});