Skip to content

🎥 Make videos programmatically with React

make @remotion/config package

Jonny Burger544cf3e12cf5
diff --git a/packages/config/package.json b/packages/config/package.json
new file mode 100644
index 0000000000..9a9b186134
--- /dev/null
+++ b/packages/config/package.json
@@ -0,0 +1,46 @@
+{
+ "name": "@remotion/config",
+ "version": "3.1.4",
+ "description": "Schema for remotion.config.ts",
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "sideEffects": false,
+ "scripts": {
+ "lint": "eslint src --ext ts,tsx",
+ "test": "vitest --run",
+ "build": "tsc -d",
+ "watch": "tsc -w"
+ },
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion"
+ },
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "author": "",
+ "license": "SEE LICENSE IN LICENSE.md",
+ "peerDependencies": {},
+ "devDependencies": {
+ "@jonny/eslint-config": "3.0.266",
+ "@types/node": "^16.7.5",
+ "@types/webpack-env": "^1.16.0",
+ "@vitejs/plugin-react": "^2.0.0",
+ "eslint": "8.13.0",
+ "prettier": "^2.0.5",
+ "prettier-plugin-organize-imports": "^2.3.4",
+ "typescript": "^4.7.0",
+ "vitest": "^0.18.0",
+ "webpack": "5.72.0"
+ },
+ "keywords": [
+ "remotion",
+ "ffmpeg",
+ "video",
+ "react",
+ "puppeteer",
+ "player"
+ ],
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/core/src/config/browser-executable.ts b/packages/config/src/config/browser-executable.ts
similarity index 100%
rename from packages/core/src/config/browser-executable.ts
rename to packages/config/src/config/browser-executable.ts
diff --git a/packages/core/src/config/browser.ts b/packages/config/src/config/browser.ts
similarity index 100%
rename from packages/core/src/config/browser.ts
rename to packages/config/src/config/browser.ts
diff --git a/packages/core/src/config/chromium-flags.ts b/packages/config/src/config/chromium-flags.ts
similarity index 71%
rename from packages/core/src/config/chromium-flags.ts
rename to packages/config/src/config/chromium-flags.ts
index 7e230321bd..21c6859271 100644
--- a/packages/core/src/config/chromium-flags.ts
+++ b/packages/config/src/config/chromium-flags.ts
@@ -1,8 +1,5 @@
-import type {
- OpenGlRenderer} from '../validation/validate-opengl-renderer';
-import {
- validateOpenGlRenderer,
-} from '../validation/validate-opengl-renderer';
+import type { OpenGlRenderer } from "../validation/validate-opengl-renderer";
+import { validateOpenGlRenderer } from "../validation/validate-opengl-renderer";
export const DEFAULT_OPENGL_RENDERER: OpenGlRenderer | null = null;
@@ -13,21 +10,21 @@ let headlessMode = true;
export const getChromiumDisableWebSecurity = () => chromiumDisableWebSecurity;
export const setChromiumDisableWebSecurity = (should: boolean) => {
- chromiumDisableWebSecurity = should;
+ chromiumDisableWebSecurity = should;
};
export const getIgnoreCertificateErrors = () => ignoreCertificateErrors;
export const setChromiumIgnoreCertificateErrors = (should: boolean) => {
- ignoreCertificateErrors = should;
+ ignoreCertificateErrors = should;
};
export const getChromiumOpenGlRenderer = () => openGlRenderer;
export const setChromiumOpenGlRenderer = (renderer: OpenGlRenderer) => {
- validateOpenGlRenderer(renderer);
- openGlRenderer = renderer;
+ validateOpenGlRenderer(renderer);
+ openGlRenderer = renderer;
};
export const getChromiumHeadlessMode = () => headlessMode;
export const setChromiumHeadlessMode = (should: boolean) => {
- headlessMode = should;
+ headlessMode = should;
};
diff --git a/packages/core/src/config/codec.ts b/packages/config/src/config/codec.ts
similarity index 100%
rename from packages/core/src/config/codec.ts
rename to packages/config/src/config/codec.ts
diff --git a/packages/core/src/config/concurrency.ts b/packages/config/src/config/concurrency.ts
similarity index 100%
rename from packages/core/src/config/concurrency.ts
rename to packages/config/src/config/concurrency.ts
diff --git a/packages/core/src/config/crf.ts b/packages/config/src/config/crf.ts
similarity index 100%
rename from packages/core/src/config/crf.ts
rename to packages/config/src/config/crf.ts
diff --git a/packages/core/src/config/env-file.ts b/packages/config/src/config/env-file.ts
similarity index 100%
rename from packages/core/src/config/env-file.ts
rename to packages/config/src/config/env-file.ts
diff --git a/packages/core/src/config/every-nth-frame.ts b/packages/config/src/config/every-nth-frame.ts
similarity index 100%
rename from packages/core/src/config/every-nth-frame.ts
rename to packages/config/src/config/every-nth-frame.ts
diff --git a/packages/core/src/config/ffmpeg-executable.ts b/packages/config/src/config/ffmpeg-executable.ts
similarity index 100%
rename from packages/core/src/config/ffmpeg-executable.ts
rename to packages/config/src/config/ffmpeg-executable.ts
diff --git a/packages/core/src/config/frame-range.ts b/packages/config/src/config/frame-range.ts
similarity index 100%
rename from packages/core/src/config/frame-range.ts
rename to packages/config/src/config/frame-range.ts
diff --git a/packages/core/src/config/image-format.ts b/packages/config/src/config/image-format.ts
similarity index 100%
rename from packages/core/src/config/image-format.ts
rename to packages/config/src/config/image-format.ts
diff --git a/packages/core/src/config/image-sequence.ts b/packages/config/src/config/image-sequence.ts
similarity index 100%
rename from packages/core/src/config/image-sequence.ts
rename to packages/config/src/config/image-sequence.ts
diff --git a/packages/core/src/config/index.ts b/packages/config/src/config/index.ts
similarity index 100%
rename from packages/core/src/config/index.ts
rename to packages/config/src/config/index.ts
diff --git a/packages/core/src/config/log.ts b/packages/config/src/config/log.ts
similarity index 100%
rename from packages/core/src/config/log.ts
rename to packages/config/src/config/log.ts
diff --git a/packages/core/src/config/max-timeline-tracks.ts b/packages/config/src/config/max-timeline-tracks.ts
similarity index 100%
rename from packages/core/src/config/max-timeline-tracks.ts
rename to packages/config/src/config/max-timeline-tracks.ts
diff --git a/packages/core/src/config/number-of-gif-loops.ts b/packages/config/src/config/number-of-gif-loops.ts
similarity index 100%
rename from packages/core/src/config/number-of-gif-loops.ts
rename to packages/config/src/config/number-of-gif-loops.ts
diff --git a/packages/core/src/config/output-location.ts b/packages/config/src/config/output-location.ts
similarity index 100%
rename from packages/core/src/config/output-location.ts
rename to packages/config/src/config/output-location.ts
diff --git a/packages/core/src/config/override-webpack.ts b/packages/config/src/config/override-webpack.ts
similarity index 100%
rename from packages/core/src/config/override-webpack.ts
rename to packages/config/src/config/override-webpack.ts
diff --git a/packages/core/src/config/overwrite.ts b/packages/config/src/config/overwrite.ts
similarity index 100%
rename from packages/core/src/config/overwrite.ts
rename to packages/config/src/config/overwrite.ts
diff --git a/packages/core/src/config/pixel-format.ts b/packages/config/src/config/pixel-format.ts
similarity index 100%
rename from packages/core/src/config/pixel-format.ts
rename to packages/config/src/config/pixel-format.ts
diff --git a/packages/core/src/config/preview-server.ts b/packages/config/src/config/preview-server.ts
similarity index 100%
rename from packages/core/src/config/preview-server.ts
rename to packages/config/src/config/preview-server.ts
diff --git a/packages/core/src/config/prores-profile.ts b/packages/config/src/config/prores-profile.ts
similarity index 100%
rename from packages/core/src/config/prores-profile.ts
rename to packages/config/src/config/prores-profile.ts
diff --git a/packages/core/src/config/quality.ts b/packages/config/src/config/quality.ts
similarity index 100%
rename from packages/core/src/config/quality.ts
rename to packages/config/src/config/quality.ts
diff --git a/packages/core/src/config/scale.ts b/packages/config/src/config/scale.ts
similarity index 100%
rename from packages/core/src/config/scale.ts
rename to packages/config/src/config/scale.ts
diff --git a/packages/core/src/config/still-frame.ts b/packages/config/src/config/still-frame.ts
similarity index 100%
rename from packages/core/src/config/still-frame.ts
rename to packages/config/src/config/still-frame.ts
diff --git a/packages/core/src/config/timeout.ts b/packages/config/src/config/timeout.ts
similarity index 100%
rename from packages/core/src/config/timeout.ts
rename to packages/config/src/config/timeout.ts
diff --git a/packages/core/src/config/webpack-caching.ts b/packages/config/src/config/webpack-caching.ts
similarity index 100%
rename from packages/core/src/config/webpack-caching.ts
rename to packages/config/src/config/webpack-caching.ts
diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/core/src/is-audio-codec.ts b/packages/config/src/is-audio-codec.ts
similarity index 100%
rename from packages/core/src/is-audio-codec.ts
rename to packages/config/src/is-audio-codec.ts
diff --git a/packages/config/src/test/codec.test.ts b/packages/config/src/test/codec.test.ts
new file mode 100644
index 0000000000..ad5e70b410
--- /dev/null
+++ b/packages/config/src/test/codec.test.ts
@@ -0,0 +1,101 @@
+import { describe, expect, test } from "vitest";
+import type { CodecOrUndefined } from "../config/codec";
+import {
+ getFinalOutputCodec,
+ getOutputCodecOrUndefined,
+ setCodec,
+} from "../config/codec";
+import { expectToThrow } from "./expect-to-throw";
+
+// getFinalOutputCodec
+
+describe("Codec tests valid codec input", () => {
+ const validCodecInput: CodecOrUndefined[] = [
+ "h264",
+ "h265",
+ "vp8",
+ "vp9",
+ "mp3",
+ "aac",
+ "wav",
+ "h264-mkv",
+ ];
+ validCodecInput.forEach((entry) =>
+ test(`codec ${entry}`, () =>
+ expect(
+ getFinalOutputCodec({
+ codec: entry,
+ emitWarning: false,
+ fileExtension: "",
+ })
+ ).toEqual(entry))
+ );
+});
+
+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"],
+ ];
+ const inputCodecs: CodecOrUndefined[] = ["h264", undefined];
+ inputCodecs.forEach((codec) =>
+ codecExtensionCombination.forEach((entry) =>
+ test(
+ codec
+ ? `should not look for extension ${entry[1]}`
+ : `${entry[1]} should be recognized as ${entry[0]}`,
+ () =>
+ expect(
+ getFinalOutputCodec({
+ codec,
+ emitWarning: false,
+ fileExtension: entry[1],
+ })
+ ).toEqual(codec ?? entry[0])
+ )
+ )
+ );
+});
+
+describe("Codec tests undefined codec input with unknown extension", () => {
+ const unknownExtensions = ["", "abc"];
+ unknownExtensions.forEach((entry) =>
+ test(`testing with "${entry}" as extension`, () =>
+ expect(
+ getFinalOutputCodec({
+ codec: undefined,
+ emitWarning: false,
+ fileExtension: entry,
+ })
+ ).toEqual("h264"))
+ );
+});
+
+// setCodec
+
+describe("Codec tests setOutputFormat", () => {
+ const validCodecInputs: CodecOrUndefined[] = [
+ "h264",
+ "h265",
+ "vp8",
+ "vp9",
+ undefined,
+ ];
+ validCodecInputs.forEach((entry) =>
+ test(`testing with ${entry}`, () => {
+ setCodec(entry);
+ expect(getOutputCodecOrUndefined()).toEqual(entry);
+ })
+ );
+ test("setCodec with invalid coded", () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => setCodec("invalid"),
+ /Codec must be one of the following:/
+ );
+ });
+});
diff --git a/packages/config/src/test/crf.test.ts b/packages/config/src/test/crf.test.ts
new file mode 100644
index 0000000000..0912d30e48
--- /dev/null
+++ b/packages/config/src/test/crf.test.ts
@@ -0,0 +1,174 @@
+import { describe, expect, test } from "vitest";
+import type { Codec } from "../config";
+import {
+ getActualCrf,
+ getDefaultCrfForCodec,
+ getValidCrfRanges,
+ setCrf,
+ validateSelectedCrfAndCodecCombination,
+} from "../config/crf";
+import { expectToThrow } from "./expect-to-throw";
+
+describe("crf tests getDefaultCrfForCodec valid input", () => {
+ // input codec, output
+ const validCodecIOs: [Codec, number][] = [
+ ["h264", 18],
+ ["h265", 23],
+ ["vp8", 9],
+ ["vp9", 28],
+ ["mp3", 0],
+ ["aac", 0],
+ ["wav", 0],
+ ] as [Codec, number][];
+ validCodecIOs.forEach((entry) =>
+ test(`default for ${entry[0]} should be ${entry[1]}`, () =>
+ expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1]))
+ );
+});
+
+describe("crf tests getDefaultCrfForCodec invalid input", () => {
+ // input codec
+ const invalidCodecs = ["abc", "", 3, undefined];
+ invalidCodecs.forEach((entry) =>
+ test(`testing with ${entry}`, () =>
+ expectToThrow(
+ // @ts-expect-error
+ () => getDefaultCrfForCodec(entry),
+ new RegExp(`Got unexpected codec "${entry}"`)
+ ))
+ );
+});
+
+describe("crf tests getValidCrfRanges valid input", () => {
+ // input crf, input codec, valid range
+ const validInputs: [Codec, [number, number]][] = [
+ ["h264", [1, 51]],
+ ["h265", [0, 51]],
+ ["vp8", [4, 63]],
+ ["vp9", [0, 63]],
+ ["mp3", [0, 0]],
+ ["aac", [0, 0]],
+ ["wav", [0, 0]],
+ ] as [Codec, [number, number]][];
+ validInputs.forEach((entry) =>
+ test(`valid range for ${entry[0]} should be [${entry[1]}]`, () =>
+ expect(getValidCrfRanges(entry[0])).toEqual(entry[1]))
+ );
+});
+
+describe("crf tests getValidCrfRanges invalid input", () => {
+ // input codec
+ const invalidInputs = ["abc", "", 3, undefined];
+ invalidInputs.forEach((entry) =>
+ test(`testing with "${entry}"`, () =>
+ expectToThrow(
+ // @ts-expect-error
+ () => getValidCrfRanges(entry),
+ new RegExp(`Got unexpected codec "${entry}"`)
+ ))
+ );
+});
+
+describe("validateSelectedCrfAndCodecCombination valid input", () => {
+ // input crf, input codec
+ const validInputs: [number, Codec][] = [
+ [20, "h264"],
+ [1, "h264"],
+ [51, "h264"],
+ [20, "h265"],
+ [0, "h265"],
+ [51, "h265"],
+ [20, "vp8"],
+ [4, "vp8"],
+ [63, "vp8"],
+ [20, "vp9"],
+ [0, "vp9"],
+ [63, "vp9"],
+ ] as [number, Codec][];
+ validInputs.forEach((entry) =>
+ test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
+ expect(() =>
+ validateSelectedCrfAndCodecCombination(entry[0], entry[1])
+ ).not.toThrow())
+ );
+});
+
+describe("validateSelectedCrfAndCodecCombination invalid input", () => {
+ // input crf, input codec, valid range
+ const invalidInputs: [number, Codec, [number, number]][] = [
+ [80, "h264", [1, 51]],
+ [-1, "h264", [1, 51]],
+ [52, "h264", [1, 51]],
+ [80, "h265", [0, 51]],
+ [-1, "h265", [0, 51]],
+ [52, "h265", [0, 51]],
+ [80, "vp8", [4, 63]],
+ [3, "vp8", [4, 63]],
+ [64, "vp8", [4, 63]],
+ [80, "vp9", [0, 63]],
+ [-1, "vp9", [0, 63]],
+ [64, "vp9", [0, 63]],
+ ] as [number, Codec, [number, number]][];
+ invalidInputs.forEach((entry) =>
+ 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]}`
+ )
+ ))
+ );
+});
+
+describe("get crf valid input", () => {
+ // input crf, input codec, output crf
+ const validInputs: [number | undefined, Codec, number][] = [
+ [20, "h264", 20],
+ [undefined, "h264", 18],
+ [20, "h265", 20],
+ [undefined, "h265", 23],
+ [20, "vp8", 20],
+ [undefined, "vp8", 9],
+ [20, "vp9", 20],
+ [undefined, "vp9", 28],
+ ] as [number | undefined, Codec, number][];
+ validInputs.forEach((entry) =>
+ test(`test with crf ${entry[0]} and codec ${entry[1]}`, () => {
+ setCrf(entry[0]);
+ expect(getActualCrf(entry[1])).toEqual(entry[2]);
+ })
+ );
+});
+
+describe("get crf invalid input", () => {
+ // input crf, input codec, valid range
+ const invalidInputs: [number, Codec, [number, number]][] = [
+ [80, "h264", [1, 51]],
+ [80, "h265", [0, 51]],
+ [80, "vp8", [4, 63]],
+ [80, "vp9", [0, 63]],
+ ] as [number, Codec, [number, number]][];
+ invalidInputs.forEach((entry) =>
+ test(`test for ${entry[1]}`, () => {
+ setCrf(entry[0]);
+ expectToThrow(
+ () => getActualCrf(entry[1]),
+ new RegExp(
+ `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
+ )
+ );
+ })
+ );
+});
+
+describe("set crf invalid input", () => {
+ const invalidInputs = [null, "abc"];
+ invalidInputs.forEach((entry) =>
+ test(`test for ${entry}`, () =>
+ expectToThrow(
+ // @ts-expect-error
+ () => setCrf(entry),
+ /The CRF must be a number or undefined/
+ ))
+ );
+});
diff --git a/packages/config/src/test/expect-to-throw.ts b/packages/config/src/test/expect-to-throw.ts
new file mode 100644
index 0000000000..6d40912130
--- /dev/null
+++ b/packages/config/src/test/expect-to-throw.ts
@@ -0,0 +1,14 @@
+import { expect, vitest } from "vitest";
+
+export const expectToThrow = (func: Function, err: RegExp) => {
+ // Even though the error is caught, it still gets printed to the console
+ // so we mock that out to avoid the wall of red text.
+ vitest.spyOn(console, "error");
+ // @ts-expect-error
+ console.error.mockImplementation(() => undefined);
+
+ expect(func).toThrow(err);
+
+ // @ts-expect-error
+ console.error.mockRestore();
+};
diff --git a/packages/config/src/test/image-sequence.test.ts b/packages/config/src/test/image-sequence.test.ts
new file mode 100644
index 0000000000..d6a0ebe77a
--- /dev/null
+++ b/packages/config/src/test/image-sequence.test.ts
@@ -0,0 +1,37 @@
+import { afterEach, beforeAll, expect, test } from "vitest";
+import {
+ getShouldOutputImageSequence,
+ setImageSequence,
+} from "../config/image-sequence";
+import { expectToThrow } from "./expect-to-throw";
+
+const invalidImageSequence: String = "invalidImageSequence";
+let defaultImageSequence: boolean;
+
+beforeAll(() => {
+ defaultImageSequence = getShouldOutputImageSequence(null);
+});
+afterEach(() => {
+ setImageSequence(defaultImageSequence);
+});
+test("setImageSequence should throw if image sequence is not a boolean value", () => {
+ expectToThrow(
+ () =>
+ // @ts-expect-error
+ setImageSequence(invalidImageSequence),
+ /setImageSequence accepts a Boolean Value/
+ );
+});
+test("setImageSequence should NOT throw if image sequence is a boolean value", () => {
+ expect(() => setImageSequence(true)).not.toThrow();
+});
+test("getShouldOutputImageSequence should return false by default", () => {
+ expect(getShouldOutputImageSequence(null)).toEqual(false);
+});
+test("getShouldOutputImageSequence should return true if a single frame number is passed", () => {
+ expect(getShouldOutputImageSequence(1)).toEqual(true);
+});
+test("getShouldOutputImageSequence should return true", () => {
+ setImageSequence(true);
+ expect(getShouldOutputImageSequence(null)).toEqual(true);
+});
diff --git a/packages/config/src/test/log.test.ts b/packages/config/src/test/log.test.ts
new file mode 100644
index 0000000000..7fd273936f
--- /dev/null
+++ b/packages/config/src/test/log.test.ts
@@ -0,0 +1,65 @@
+import { describe, expect, test } from "vitest";
+import type { LogLevel } from "../config/log";
+import {
+ getLogLevel,
+ isEqualOrBelowLogLevel,
+ isValidLogLevel,
+ setLogLevel,
+} from "../config/log";
+describe("test loglevel getter and setter", () => {
+ test("default log level", () => {
+ expect(getLogLevel()).toEqual("info");
+ });
+ test.each<LogLevel>(["verbose", "warn", "error", "info"])(
+ "test for %s",
+ (loglevel) => {
+ setLogLevel(loglevel);
+ expect(getLogLevel()).toEqual(loglevel);
+ }
+ );
+});
+
+describe("loglevel validity", () => {
+ test.each<string>(["abc", "aalsadj", ""])(
+ "is %s an invalid level",
+ (level) => {
+ expect(isValidLogLevel(level)).toEqual(false);
+ }
+ );
+ test.each<string | LogLevel>(["verbose", "info", "warn", "error"])(
+ "is %s a valid level",
+ (level) => {
+ expect(isValidLogLevel(level)).toEqual(true);
+ }
+ );
+});
+
+describe("loglevel comparison", () => {
+ test.each<[LogLevel, LogLevel]>([
+ ["verbose", "verbose"],
+ ["verbose", "info"],
+ ["verbose", "warn"],
+ ["verbose", "error"],
+ ["info", "info"],
+ ["info", "warn"],
+ ["info", "error"],
+ ["warn", "warn"],
+ ["warn", "error"],
+ ["error", "error"],
+ ])("%s is equal or below %s", (level1, level2) => {
+ setLogLevel(level1);
+ expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(true);
+ });
+
+ test.each<[LogLevel, LogLevel]>([
+ ["info", "verbose"],
+ ["warn", "verbose"],
+ ["error", "verbose"],
+ ["warn", "info"],
+ ["error", "info"],
+ ["error", "warn"],
+ ])("%s is not equal or below %s", (level1, level2) => {
+ setLogLevel(level1);
+ expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(false);
+ });
+});
diff --git a/packages/config/src/test/overwrite.test.ts b/packages/config/src/test/overwrite.test.ts
new file mode 100644
index 0000000000..8fe2375ff7
--- /dev/null
+++ b/packages/config/src/test/overwrite.test.ts
@@ -0,0 +1,31 @@
+import { afterEach, beforeAll, expect, test } from "vitest";
+import { getShouldOverwrite, setOverwriteOutput } from "../config/overwrite";
+import { expectToThrow } from "./expect-to-throw";
+
+const invalidOverwrite = 555;
+let defaultOverwriteValue: boolean;
+
+beforeAll(() => {
+ defaultOverwriteValue = getShouldOverwrite();
+});
+afterEach(() => {
+ setOverwriteOutput(defaultOverwriteValue);
+});
+
+test("setOverwriteOutput should throw if overwrite is not a boolean value", () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => setOverwriteOutput(invalidOverwrite),
+ /overwriteExisting must be a boolean but got number [(]555[)]/
+ );
+});
+test("setOverwriteOutput should NOT throw if image format is a boolean value", () => {
+ expect(() => setOverwriteOutput(true)).not.toThrow();
+});
+test("getShouldOverwrite should return true by default", () => {
+ expect(getShouldOverwrite()).toEqual(true);
+});
+test("setOverwriteOutput should return a boolean value", () => {
+ setOverwriteOutput(false);
+ expect(getShouldOverwrite()).toEqual(false);
+});
diff --git a/packages/core/src/test/pixel-format.test.ts b/packages/config/src/test/pixel-format.test.ts
similarity index 100%
rename from packages/core/src/test/pixel-format.test.ts
rename to packages/config/src/test/pixel-format.test.ts
diff --git a/packages/core/src/test/preview-server.test.ts b/packages/config/src/test/preview-server.test.ts
similarity index 100%
rename from packages/core/src/test/preview-server.test.ts
rename to packages/config/src/test/preview-server.test.ts
diff --git a/packages/core/src/test/pro-res-profile.test.ts b/packages/config/src/test/pro-res-profile.test.ts
similarity index 100%
rename from packages/core/src/test/pro-res-profile.test.ts
rename to packages/config/src/test/pro-res-profile.test.ts
diff --git a/packages/core/src/test/quality.test.ts b/packages/config/src/test/quality.test.ts
similarity index 100%
rename from packages/core/src/test/quality.test.ts
rename to packages/config/src/test/quality.test.ts
diff --git a/packages/config/src/test/range.test.tsx b/packages/config/src/test/range.test.tsx
new file mode 100644
index 0000000000..3634125134
--- /dev/null
+++ b/packages/config/src/test/range.test.tsx
@@ -0,0 +1,102 @@
+import { describe, expect, test } from "vitest";
+import {
+ getRange,
+ setFrameRange,
+ setFrameRangeFromCli,
+} from "../config/frame-range";
+import { expectToThrow } from "./expect-to-throw";
+
+describe("Frame range should throw exception with invalid inputs", () => {
+ const testValues: [number | [number, number] | null, RegExp][] = [
+ [-1, /non-negative/],
+ [1.111, /Frame must be an integer, but got a float \(1.111\)/],
+ [Infinity, /finite number, got Infinity/],
+ // @ts-expect-error
+ [[0, 2, 4], /Frame range must be a tuple, got an array with length 3/],
+ // @ts-expect-error
+ [[], /Frame range must be a tuple, got an array with length 0/],
+ [
+ // @ts-expect-error
+ ["0", 2],
+ /Each value of frame range must be a number, but got string \("0"\)/,
+ ],
+ [
+ [0.111, 2],
+ /Each value of frame range must be an integer, but got a float \(0.111\)/,
+ ],
+ [
+ [0, Infinity],
+ /Each value of frame range must be finite, but got Infinity/,
+ ],
+ [[-1, 0], /Each value of frame range must be non-negative, but got -1/],
+ [
+ [10, 0],
+ /The second value of frame range must be not smaller than the first one, but got 10-0/,
+ ],
+ [
+ // @ts-expect-error
+ "10",
+ /Frame range must be a number or a tuple of numbers, but got object of type string/,
+ ],
+ ];
+
+ testValues.forEach((entry) =>
+ test(`test with input ${JSON.stringify(entry[0])}`, () =>
+ expectToThrow(() => setFrameRange(entry[0]), entry[1]))
+ );
+});
+describe("Frame range tests with valid inputs", () => {
+ const testValues: (number | [number, number] | null)[] = [
+ null,
+ [10, 20],
+ [10, 10],
+ 10,
+ 0,
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry}`, () => {
+ setFrameRange(entry);
+ expect(getRange()).toEqual(entry);
+ })
+ );
+});
+
+describe("Frame range CLI should throw exception with invalid inputs", () => {
+ const testValues: [string, RegExp][] = [
+ [
+ "1-2-3",
+ /--frames flag must be a number or 2 numbers separated by '-', instead got 3 numbers/,
+ ],
+ [
+ "2-1",
+ /The second number of the --frames flag number should be greater or equal than first number/,
+ ],
+ [
+ "one-two",
+ /--frames flag must be a single number, or 2 numbers separated by `-`/,
+ ],
+ [" ", /Frame range must be a tuple, got an array with length 1/],
+ ["", /Frame range must be a tuple, got an array with length 1/],
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry[0]}`, () =>
+ expectToThrow(() => setFrameRangeFromCli(entry[0]), entry[1]))
+ );
+});
+describe("Frame range CLI tests with valid inputs", () => {
+ setFrameRange(null);
+
+ const testValues: [number | string, number | [number, number]][] = [
+ [0, 0],
+ [10, 10],
+ ["1-10", [1, 10]],
+ ["10-10", [10, 10]],
+ ["-", [0, 0]],
+ ];
+ testValues.forEach((entry) =>
+ test(`test with input ${entry[0]}`, () => {
+ setFrameRangeFromCli(entry[0]);
+ expect(getRange()).toEqual(entry[1]);
+ })
+ );
+});
diff --git a/packages/config/src/test/validate-image-format.test.ts b/packages/config/src/test/validate-image-format.test.ts
new file mode 100644
index 0000000000..4a6dfc8e4d
--- /dev/null
+++ b/packages/config/src/test/validate-image-format.test.ts
@@ -0,0 +1,10 @@
+import { expect, test } from "vitest";
+import { validateNonNullImageFormat } from "../validation/validate-image-format";
+
+test('"none" is not a valid image format', () => {
+ expect(() => validateNonNullImageFormat("jpeg")).not.toThrow();
+ expect(() => validateNonNullImageFormat("png")).not.toThrow();
+ expect(() => validateNonNullImageFormat("none")).toThrow(
+ /Image format should be either "png" or "jpeg"/
+ );
+});
diff --git a/packages/config/src/test/webpack-caching.test.ts b/packages/config/src/test/webpack-caching.test.ts
new file mode 100644
index 0000000000..83075e7944
--- /dev/null
+++ b/packages/config/src/test/webpack-caching.test.ts
@@ -0,0 +1,29 @@
+import { expect, test } from "vitest";
+import {
+ DEFAULT_WEBPACK_CACHE_ENABLED,
+ getWebpackCaching,
+ setWebpackCaching,
+} from "../config/webpack-caching";
+import { expectToThrow } from "./expect-to-throw";
+
+test("getWebpackCaching - default value", () => {
+ expect(getWebpackCaching()).toEqual(DEFAULT_WEBPACK_CACHE_ENABLED);
+});
+
+test("webpack caching - setter - valid input", () => {
+ const valuesToTest = [true, false];
+ valuesToTest.forEach((entry) => {
+ setWebpackCaching(entry);
+ expect(getWebpackCaching()).toEqual(entry);
+ });
+});
+
+test("webpack caching - setter - invalid input", () => {
+ const valuesToTest = [undefined, "true", "false"];
+ valuesToTest.forEach((entry) => {
+ expectToThrow(() => {
+ // @ts-expect-error
+ setWebpackCaching(entry);
+ }, /Caching flag must be a boolean./);
+ });
+});
diff --git a/packages/config/src/validation/validate-image-format.ts b/packages/config/src/validation/validate-image-format.ts
new file mode 100644
index 0000000000..470c4f0a56
--- /dev/null
+++ b/packages/config/src/validation/validate-image-format.ts
@@ -0,0 +1,7 @@
+import type { ImageFormat } from "../config";
+
+export const validateNonNullImageFormat = (imageFormat: ImageFormat) => {
+ if (imageFormat !== "jpeg" && imageFormat !== "png") {
+ throw new TypeError('Image format should be either "png" or "jpeg"');
+ }
+};
diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json
new file mode 100644
index 0000000000..87e393968d
--- /dev/null
+++ b/packages/config/tsconfig.json
@@ -0,0 +1,12 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "composite": true,
+ "rootDir": "./src",
+ "outDir": "./dist",
+ "skipLibCheck": true,
+ "jsx": "react-jsx",
+ "noUnusedLocals": true
+ },
+ "include": ["./src"]
+}
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 46f97ef22a..eefd498eb3 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -93,7 +93,7 @@ export const Composition = <T,>({
'of the <Composition/> component'
);
- validateFps(fps, 'as a prop of the <Composition/> component', null);
+ validateFps(fps, 'as a prop of the <Composition/> component', false);
registerComposition<T>({
durationInFrames,
fps,
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 0999c48c13..0123f5a758 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -44,7 +44,6 @@ export * from './AbsoluteFill';
export * from './audio';
export * from './Composition';
export {SmallTCompMetadata, TAsset, TCompMetadata} from './CompositionManager';
-export * from './config';
export {getInputProps} from './config/input-props';
export * from './delay-render';
export * from './easing';
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index a8c4e1e330..819c61b5d9 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -17,82 +17,12 @@ import type {
} from './CompositionManager';
import {CompositionManager, compositionsRef} from './CompositionManager';
import * as AssetCompression from './compress-assets';
-import {DEFAULT_BROWSER, getBrowser} from './config/browser';
-import {getBrowserExecutable} from './config/browser-executable';
-import {
- DEFAULT_OPENGL_RENDERER,
- getChromiumDisableWebSecurity,
- getChromiumHeadlessMode,
- getChromiumOpenGlRenderer,
- getIgnoreCertificateErrors,
-} from './config/chromium-flags';
-import {
- DEFAULT_CODEC,
- getFinalOutputCodec,
- getOutputCodecOrUndefined,
-} from './config/codec';
-import {getConcurrency} from './config/concurrency';
-import {
- getActualCrf,
- getDefaultCrfForCodec,
- validateSelectedCrfAndCodecCombination,
-} from './config/crf';
-import {getDotEnvLocation} from './config/env-file';
-import {getAndValidateEveryNthFrame} from './config/every-nth-frame';
-import {
- getCustomFfmpegExecutable,
- getCustomFfprobeExecutable,
-} from './config/ffmpeg-executable';
-import {
- getRange,
- setFrameRangeFromCli,
- validateFrameRange,
-} from './config/frame-range';
-import {
- getUserPreferredImageFormat,
- validateSelectedPixelFormatAndImageFormatCombination,
-} from './config/image-format';
-import {getShouldOutputImageSequence} from './config/image-sequence';
-import * as Logging from './config/log';
-import {getMaxTimelineTracks} from './config/max-timeline-tracks';
-import {getAndValidateNumberOfGifLoops} from './config/number-of-gif-loops';
-import {getOutputLocation} from './config/output-location';
-import type {WebpackOverrideFn} from './config/override-webpack';
-import {
- defaultOverrideFunction,
- getWebpackOverrideFn,
-} from './config/override-webpack';
-import {DEFAULT_OVERWRITE, getShouldOverwrite} from './config/overwrite';
-import {
- DEFAULT_PIXEL_FORMAT,
- getPixelFormat,
- validateSelectedPixelFormatAndCodecCombination,
-} from './config/pixel-format';
-import {getServerPort} from './config/preview-server';
-import type {ProResProfile} from './config/prores-profile';
-import {
- getProResProfile,
- setProResProfile,
- validateSelectedCodecAndProResCombination,
-} from './config/prores-profile';
-import {getQuality} from './config/quality';
-import {getScale} from './config/scale';
-import {getStillFrame, setStillFrame} from './config/still-frame';
-import {
- getCurrentPuppeteerTimeout,
- setPuppeteerTimeout,
-} from './config/timeout';
-import {
- DEFAULT_WEBPACK_CACHE_ENABLED,
- getWebpackCaching,
-} from './config/webpack-caching';
import * as CSSUtils from './default-css';
import {DELAY_RENDER_CALLSTACK_TOKEN} from './delay-render';
import {FEATURE_FLAG_FIREFOX_SUPPORT} from './feature-flags';
import type {RemotionEnvironment} from './get-environment';
import {getRemotionEnvironment} from './get-environment';
import {getPreviewDomElement} from './get-preview-dom-element';
-import {isAudioCodec} from './is-audio-codec';
import * as perf from './perf';
import {portalNode} from './portal-node';
import {getRoot, waitForRoot} from './register-root';
@@ -123,7 +53,6 @@ import {validateDimension} from './validation/validate-dimensions';
import {validateDurationInFrames} from './validation/validate-duration-in-frames';
import {validateFps} from './validation/validate-fps';
import {validateFrame} from './validation/validate-frame';
-import {validateNonNullImageFormat} from './validation/validate-image-format';
import {validateOffthreadVideoImageFormat} from './validation/validate-offthreadvideo-image-format';
import type {OpenGlRenderer} from './validation/validate-opengl-renderer';
import {validateOpenGlRenderer} from './validation/validate-opengl-renderer';
@@ -154,83 +83,33 @@ export const Internals = {
RemotionRoot,
useVideo,
getRoot,
- getBrowserExecutable,
- getCustomFfmpegExecutable,
- getCustomFfprobeExecutable,
- getPixelFormat,
- getConcurrency,
- getOutputLocation,
- getRange,
- getShouldOverwrite,
- getOutputCodecOrUndefined,
- getWebpackOverrideFn,
- getQuality,
- getAndValidateEveryNthFrame,
- getAndValidateNumberOfGifLoops,
- getScale,
- getShouldOutputImageSequence,
- validateSelectedCrfAndCodecCombination,
- getFinalOutputCodec,
useMediaVolumeState,
useMediaMutedState,
- DEFAULT_CODEC,
- DEFAULT_PIXEL_FORMAT,
FEATURE_FLAG_FIREFOX_SUPPORT,
- DEFAULT_WEBPACK_CACHE_ENABLED,
- getBrowser,
- DEFAULT_BROWSER,
- getDefaultCrfForCodec,
- getActualCrf,
- setFrameRangeFromCli,
- getUserPreferredImageFormat,
- validateSelectedPixelFormatAndImageFormatCombination,
- validateSelectedPixelFormatAndCodecCombination,
- validateFrameRange,
- validateNonNullImageFormat,
- getWebpackCaching,
useLazyComponent,
truthy,
- isAudioCodec,
- Logging,
SequenceContext,
useRemotionContexts,
RemotionContextProvider,
CSSUtils,
setupEnvVariables,
ENV_VARIABLES_ENV_NAME,
- getDotEnvLocation,
- getServerPort,
MediaVolumeContext,
SetMediaVolumeContext,
validateDurationInFrames,
validateFps,
validateDimension,
getRemotionEnvironment,
- getProResProfile,
- setProResProfile,
- validateSelectedCodecAndProResCombination,
- getMaxTimelineTracks,
SharedAudioContext,
SharedAudioContextProvider,
validateQuality,
validateFrame,
- setStillFrame,
- getStillFrame,
invalidCompositionErrorMessage,
isCompositionIdValid,
- DEFAULT_OVERWRITE,
AssetCompression,
- defaultOverrideFunction,
DEFAULT_PUPPETEER_TIMEOUT,
setupPuppeteerTimeout,
- setPuppeteerTimeout,
- getCurrentPuppeteerTimeout,
- getChromiumDisableWebSecurity,
- getIgnoreCertificateErrors,
validateOpenGlRenderer,
- getChromiumOpenGlRenderer,
- getChromiumHeadlessMode,
- DEFAULT_OPENGL_RENDERER,
getPreviewDomElement,
compositionsRef,
DELAY_RENDER_CALLSTACK_TOKEN,
@@ -242,12 +121,21 @@ export const Internals = {
CanUseRemotionHooks,
};
+import type {Configuration} from 'webpack';
+
+type WebpackConfiguration = Configuration;
+
+type WebpackOverrideFn = (
+ currentConfiguration: WebpackConfiguration
+) => WebpackConfiguration;
+
export type {
TComposition,
Timeline,
TCompMetadata,
TSequence,
WebpackOverrideFn,
+ WebpackConfiguration,
TAsset,
RenderAssetInfo,
TimelineContextValue,
@@ -259,6 +147,5 @@ export type {
MediaVolumeContextValue,
SetMediaVolumeContextValue,
RemotionEnvironment,
- ProResProfile,
OpenGlRenderer,
};
diff --git a/packages/core/src/spring/measure-spring.ts b/packages/core/src/spring/measure-spring.ts
index bb50c0cdb7..9ebd4a5b09 100644
--- a/packages/core/src/spring/measure-spring.ts
+++ b/packages/core/src/spring/measure-spring.ts
@@ -41,7 +41,7 @@ export function measureSpring({
throw new TypeError('Threshold is below 0');
}
- validateFps(fps, 'to the measureSpring() function', null);
+ validateFps(fps, 'to the measureSpring() function', false);
const range = Math.abs(from - to);
let frame = 0;
diff --git a/packages/core/src/test/codec.test.ts b/packages/core/src/test/codec.test.ts
deleted file mode 100644
index 2b4417d22b..0000000000
--- a/packages/core/src/test/codec.test.ts
+++ /dev/null
@@ -1,101 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import type {CodecOrUndefined} from '../config/codec';
-import {
- getFinalOutputCodec,
- getOutputCodecOrUndefined,
- setCodec,
-} from '../config/codec';
-import {expectToThrow} from './expect-to-throw';
-
-// getFinalOutputCodec
-
-describe('Codec tests valid codec input', () => {
- const validCodecInput: CodecOrUndefined[] = [
- 'h264',
- 'h265',
- 'vp8',
- 'vp9',
- 'mp3',
- 'aac',
- 'wav',
- 'h264-mkv',
- ];
- validCodecInput.forEach((entry) =>
- test(`codec ${entry}`, () =>
- expect(
- getFinalOutputCodec({
- codec: entry,
- emitWarning: false,
- fileExtension: '',
- })
- ).toEqual(entry))
- );
-});
-
-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'],
- ];
- const inputCodecs: CodecOrUndefined[] = ['h264', undefined];
- inputCodecs.forEach((codec) =>
- codecExtensionCombination.forEach((entry) =>
- test(
- codec
- ? `should not look for extension ${entry[1]}`
- : `${entry[1]} should be recognized as ${entry[0]}`,
- () =>
- expect(
- getFinalOutputCodec({
- codec,
- emitWarning: false,
- fileExtension: entry[1],
- })
- ).toEqual(codec ?? entry[0])
- )
- )
- );
-});
-
-describe('Codec tests undefined codec input with unknown extension', () => {
- const unknownExtensions = ['', 'abc'];
- unknownExtensions.forEach((entry) =>
- test(`testing with "${entry}" as extension`, () =>
- expect(
- getFinalOutputCodec({
- codec: undefined,
- emitWarning: false,
- fileExtension: entry,
- })
- ).toEqual('h264'))
- );
-});
-
-// setCodec
-
-describe('Codec tests setOutputFormat', () => {
- const validCodecInputs: CodecOrUndefined[] = [
- 'h264',
- 'h265',
- 'vp8',
- 'vp9',
- undefined,
- ];
- validCodecInputs.forEach((entry) =>
- test(`testing with ${entry}`, () => {
- setCodec(entry);
- expect(getOutputCodecOrUndefined()).toEqual(entry);
- })
- );
- test('setCodec with invalid coded', () => {
- expectToThrow(
- // @ts-expect-error
- () => setCodec('invalid'),
- /Codec must be one of the following:/
- );
- });
-});
diff --git a/packages/core/src/test/crf.test.ts b/packages/core/src/test/crf.test.ts
deleted file mode 100644
index 4ca38eeb42..0000000000
--- a/packages/core/src/test/crf.test.ts
+++ /dev/null
@@ -1,174 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import type {Codec} from '../config';
-import {
- getActualCrf,
- getDefaultCrfForCodec,
- getValidCrfRanges,
- setCrf,
- validateSelectedCrfAndCodecCombination,
-} from '../config/crf';
-import {expectToThrow} from './expect-to-throw';
-
-describe('crf tests getDefaultCrfForCodec valid input', () => {
- // input codec, output
- const validCodecIOs: [Codec, number][] = [
- ['h264', 18],
- ['h265', 23],
- ['vp8', 9],
- ['vp9', 28],
- ['mp3', 0],
- ['aac', 0],
- ['wav', 0],
- ] as [Codec, number][];
- validCodecIOs.forEach((entry) =>
- test(`default for ${entry[0]} should be ${entry[1]}`, () =>
- expect(getDefaultCrfForCodec(entry[0])).toEqual(entry[1]))
- );
-});
-
-describe('crf tests getDefaultCrfForCodec invalid input', () => {
- // input codec
- const invalidCodecs = ['abc', '', 3, undefined];
- invalidCodecs.forEach((entry) =>
- test(`testing with ${entry}`, () =>
- expectToThrow(
- // @ts-expect-error
- () => getDefaultCrfForCodec(entry),
- new RegExp(`Got unexpected codec "${entry}"`)
- ))
- );
-});
-
-describe('crf tests getValidCrfRanges valid input', () => {
- // input crf, input codec, valid range
- const validInputs: [Codec, [number, number]][] = [
- ['h264', [1, 51]],
- ['h265', [0, 51]],
- ['vp8', [4, 63]],
- ['vp9', [0, 63]],
- ['mp3', [0, 0]],
- ['aac', [0, 0]],
- ['wav', [0, 0]],
- ] as [Codec, [number, number]][];
- validInputs.forEach((entry) =>
- test(`valid range for ${entry[0]} should be [${entry[1]}]`, () =>
- expect(getValidCrfRanges(entry[0])).toEqual(entry[1]))
- );
-});
-
-describe('crf tests getValidCrfRanges invalid input', () => {
- // input codec
- const invalidInputs = ['abc', '', 3, undefined];
- invalidInputs.forEach((entry) =>
- test(`testing with "${entry}"`, () =>
- expectToThrow(
- // @ts-expect-error
- () => getValidCrfRanges(entry),
- new RegExp(`Got unexpected codec "${entry}"`)
- ))
- );
-});
-
-describe('validateSelectedCrfAndCodecCombination valid input', () => {
- // input crf, input codec
- const validInputs: [number, Codec][] = [
- [20, 'h264'],
- [1, 'h264'],
- [51, 'h264'],
- [20, 'h265'],
- [0, 'h265'],
- [51, 'h265'],
- [20, 'vp8'],
- [4, 'vp8'],
- [63, 'vp8'],
- [20, 'vp9'],
- [0, 'vp9'],
- [63, 'vp9'],
- ] as [number, Codec][];
- validInputs.forEach((entry) =>
- test(`validate with crf ${entry[0]} and codec ${entry[1]}`, () =>
- expect(() =>
- validateSelectedCrfAndCodecCombination(entry[0], entry[1])
- ).not.toThrow())
- );
-});
-
-describe('validateSelectedCrfAndCodecCombination invalid input', () => {
- // input crf, input codec, valid range
- const invalidInputs: [number, Codec, [number, number]][] = [
- [80, 'h264', [1, 51]],
- [-1, 'h264', [1, 51]],
- [52, 'h264', [1, 51]],
- [80, 'h265', [0, 51]],
- [-1, 'h265', [0, 51]],
- [52, 'h265', [0, 51]],
- [80, 'vp8', [4, 63]],
- [3, 'vp8', [4, 63]],
- [64, 'vp8', [4, 63]],
- [80, 'vp9', [0, 63]],
- [-1, 'vp9', [0, 63]],
- [64, 'vp9', [0, 63]],
- ] as [number, Codec, [number, number]][];
- invalidInputs.forEach((entry) =>
- 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]}`
- )
- ))
- );
-});
-
-describe('get crf valid input', () => {
- // input crf, input codec, output crf
- const validInputs: [number | undefined, Codec, number][] = [
- [20, 'h264', 20],
- [undefined, 'h264', 18],
- [20, 'h265', 20],
- [undefined, 'h265', 23],
- [20, 'vp8', 20],
- [undefined, 'vp8', 9],
- [20, 'vp9', 20],
- [undefined, 'vp9', 28],
- ] as [number | undefined, Codec, number][];
- validInputs.forEach((entry) =>
- test(`test with crf ${entry[0]} and codec ${entry[1]}`, () => {
- setCrf(entry[0]);
- expect(getActualCrf(entry[1])).toEqual(entry[2]);
- })
- );
-});
-
-describe('get crf invalid input', () => {
- // input crf, input codec, valid range
- const invalidInputs: [number, Codec, [number, number]][] = [
- [80, 'h264', [1, 51]],
- [80, 'h265', [0, 51]],
- [80, 'vp8', [4, 63]],
- [80, 'vp9', [0, 63]],
- ] as [number, Codec, [number, number]][];
- invalidInputs.forEach((entry) =>
- test(`test for ${entry[1]}`, () => {
- setCrf(entry[0]);
- expectToThrow(
- () => getActualCrf(entry[1]),
- new RegExp(
- `CRF must be between ${entry[2][0]} and ${entry[2][1]} for codec ${entry[1]}. Passed: ${entry[0]}`
- )
- );
- })
- );
-});
-
-describe('set crf invalid input', () => {
- const invalidInputs = [null, 'abc'];
- invalidInputs.forEach((entry) =>
- test(`test for ${entry}`, () =>
- expectToThrow(
- // @ts-expect-error
- () => setCrf(entry),
- /The CRF must be a number or undefined/
- ))
- );
-});
diff --git a/packages/core/src/test/image-format.test.ts b/packages/core/src/test/image-format.test.ts
deleted file mode 100644
index 1ce3458e5e..0000000000
--- a/packages/core/src/test/image-format.test.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import type {ImageFormat} from '../config/image-format';
-import {
- getUserPreferredImageFormat,
- 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(
- () =>
- setImageFormat(
- // @ts-expect-error
- 'invalidImageFormat'
- ),
- /Value invalidImageFormat is not valid as an image format./
- );
-});
-test('validateSelectedPixelFormatAndImageFormatCombination 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('Special case - invalid combination with pixel ("yuva420p") and image format ("jpeg") should throw', () => {
- 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('Special case - valid combination with pixel ("yuva420p") and image format ("png") should not throw', () => {
- expect(
- validateSelectedPixelFormatAndImageFormatCombination('yuva420p', 'png')
- ).toEqual('valid');
-});
-
-test('Valid combination with pixel and image format ("png") should not throw', () => {
- expect(
- validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'png')
- ).toEqual('valid');
-});
-test('Valid combination with pixel and image format ("jpeg") should not throw', () => {
- expect(
- validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'jpeg')
- ).toEqual('valid');
-});
-test('"none" as image format should not throw', () => {
- expect(
- validateSelectedPixelFormatAndImageFormatCombination('yuv420p', 'none')
- ).toEqual('none');
-});
diff --git a/packages/core/src/test/image-sequence.test.ts b/packages/core/src/test/image-sequence.test.ts
deleted file mode 100644
index 4c6b2c9dfd..0000000000
--- a/packages/core/src/test/image-sequence.test.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import {afterEach, beforeAll, expect, test} from 'vitest';
-import {
- getShouldOutputImageSequence,
- setImageSequence,
-} from '../config/image-sequence';
-import {expectToThrow} from './expect-to-throw';
-
-const invalidImageSequence: String = 'invalidImageSequence';
-let defaultImageSequence: boolean;
-
-beforeAll(() => {
- defaultImageSequence = getShouldOutputImageSequence(null);
-});
-afterEach(() => {
- setImageSequence(defaultImageSequence);
-});
-test('setImageSequence should throw if image sequence is not a boolean value', () => {
- expectToThrow(
- () =>
- // @ts-expect-error
- setImageSequence(invalidImageSequence),
- /setImageSequence accepts a Boolean Value/
- );
-});
-test('setImageSequence should NOT throw if image sequence is a boolean value', () => {
- expect(() => setImageSequence(true)).not.toThrow();
-});
-test('getShouldOutputImageSequence should return false by default', () => {
- expect(getShouldOutputImageSequence(null)).toEqual(false);
-});
-test('getShouldOutputImageSequence should return true if a single frame number is passed', () => {
- expect(getShouldOutputImageSequence(1)).toEqual(true);
-});
-test('getShouldOutputImageSequence should return true', () => {
- setImageSequence(true);
- expect(getShouldOutputImageSequence(null)).toEqual(true);
-});
diff --git a/packages/core/src/test/log.test.ts b/packages/core/src/test/log.test.ts
deleted file mode 100644
index 8fb2f8583d..0000000000
--- a/packages/core/src/test/log.test.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import type {LogLevel} from '../config/log';
-import {
- getLogLevel,
- isEqualOrBelowLogLevel,
- isValidLogLevel,
- setLogLevel,
-} from '../config/log';
-describe('test loglevel getter and setter', () => {
- test('default log level', () => {
- expect(getLogLevel()).toEqual('info');
- });
- test.each<LogLevel>(['verbose', 'warn', 'error', 'info'])(
- 'test for %s',
- (loglevel) => {
- setLogLevel(loglevel);
- expect(getLogLevel()).toEqual(loglevel);
- }
- );
-});
-
-describe('loglevel validity', () => {
- test.each<string>(['abc', 'aalsadj', ''])(
- 'is %s an invalid level',
- (level) => {
- expect(isValidLogLevel(level)).toEqual(false);
- }
- );
- test.each<string | LogLevel>(['verbose', 'info', 'warn', 'error'])(
- 'is %s a valid level',
- (level) => {
- expect(isValidLogLevel(level)).toEqual(true);
- }
- );
-});
-
-describe('loglevel comparison', () => {
- test.each<[LogLevel, LogLevel]>([
- ['verbose', 'verbose'],
- ['verbose', 'info'],
- ['verbose', 'warn'],
- ['verbose', 'error'],
- ['info', 'info'],
- ['info', 'warn'],
- ['info', 'error'],
- ['warn', 'warn'],
- ['warn', 'error'],
- ['error', 'error'],
- ])('%s is equal or below %s', (level1, level2) => {
- setLogLevel(level1);
- expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(true);
- });
-
- test.each<[LogLevel, LogLevel]>([
- ['info', 'verbose'],
- ['warn', 'verbose'],
- ['error', 'verbose'],
- ['warn', 'info'],
- ['error', 'info'],
- ['error', 'warn'],
- ])('%s is not equal or below %s', (level1, level2) => {
- setLogLevel(level1);
- expect(isEqualOrBelowLogLevel(getLogLevel(), level2)).toEqual(false);
- });
-});
diff --git a/packages/core/src/test/overwrite.test.ts b/packages/core/src/test/overwrite.test.ts
deleted file mode 100644
index 9d284f57e9..0000000000
--- a/packages/core/src/test/overwrite.test.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import {afterEach, beforeAll, expect, test} from 'vitest';
-import {getShouldOverwrite, setOverwriteOutput} from '../config/overwrite';
-import {expectToThrow} from './expect-to-throw';
-
-const invalidOverwrite = 555;
-let defaultOverwriteValue: boolean;
-
-beforeAll(() => {
- defaultOverwriteValue = getShouldOverwrite();
-});
-afterEach(() => {
- setOverwriteOutput(defaultOverwriteValue);
-});
-
-test('setOverwriteOutput should throw if overwrite is not a boolean value', () => {
- expectToThrow(
- // @ts-expect-error
- () => setOverwriteOutput(invalidOverwrite),
- /overwriteExisting must be a boolean but got number [(]555[)]/
- );
-});
-test('setOverwriteOutput should NOT throw if image format is a boolean value', () => {
- expect(() => setOverwriteOutput(true)).not.toThrow();
-});
-test('getShouldOverwrite should return true by default', () => {
- expect(getShouldOverwrite()).toEqual(true);
-});
-test('setOverwriteOutput should return a boolean value', () => {
- setOverwriteOutput(false);
- expect(getShouldOverwrite()).toEqual(false);
-});
diff --git a/packages/core/src/test/range.test.tsx b/packages/core/src/test/range.test.tsx
deleted file mode 100644
index 7bc08c385f..0000000000
--- a/packages/core/src/test/range.test.tsx
+++ /dev/null
@@ -1,99 +0,0 @@
-import {describe, expect, test} from 'vitest';
-import {setFrameRange, setFrameRangeFromCli} from '../config/frame-range';
-import {Internals} from '../internals';
-import {expectToThrow} from './expect-to-throw';
-
-describe('Frame range should throw exception with invalid inputs', () => {
- const testValues: [number | [number, number] | null, RegExp][] = [
- [-1, /non-negative/],
- [1.111, /Frame must be an integer, but got a float \(1.111\)/],
- [Infinity, /finite number, got Infinity/],
- // @ts-expect-error
- [[0, 2, 4], /Frame range must be a tuple, got an array with length 3/],
- // @ts-expect-error
- [[], /Frame range must be a tuple, got an array with length 0/],
- [
- // @ts-expect-error
- ['0', 2],
- /Each value of frame range must be a number, but got string \("0"\)/,
- ],
- [
- [0.111, 2],
- /Each value of frame range must be an integer, but got a float \(0.111\)/,
- ],
- [
- [0, Infinity],
- /Each value of frame range must be finite, but got Infinity/,
- ],
- [[-1, 0], /Each value of frame range must be non-negative, but got -1/],
- [
- [10, 0],
- /The second value of frame range must be not smaller than the first one, but got 10-0/,
- ],
- [
- // @ts-expect-error
- '10',
- /Frame range must be a number or a tuple of numbers, but got object of type string/,
- ],
- ];
-
- testValues.forEach((entry) =>
- test(`test with input ${JSON.stringify(entry[0])}`, () =>
- expectToThrow(() => setFrameRange(entry[0]), entry[1]))
- );
-});
-describe('Frame range tests with valid inputs', () => {
- const testValues: (number | [number, number] | null)[] = [
- null,
- [10, 20],
- [10, 10],
- 10,
- 0,
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry}`, () => {
- setFrameRange(entry);
- expect(Internals.getRange()).toEqual(entry);
- })
- );
-});
-
-describe('Frame range CLI should throw exception with invalid inputs', () => {
- const testValues: [string, RegExp][] = [
- [
- '1-2-3',
- /--frames flag must be a number or 2 numbers separated by '-', instead got 3 numbers/,
- ],
- [
- '2-1',
- /The second number of the --frames flag number should be greater or equal than first number/,
- ],
- [
- 'one-two',
- /--frames flag must be a single number, or 2 numbers separated by `-`/,
- ],
- [' ', /Frame range must be a tuple, got an array with length 1/],
- ['', /Frame range must be a tuple, got an array with length 1/],
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry[0]}`, () =>
- expectToThrow(() => setFrameRangeFromCli(entry[0]), entry[1]))
- );
-});
-describe('Frame range CLI tests with valid inputs', () => {
- setFrameRange(null);
-
- const testValues: [number | string, number | [number, number]][] = [
- [0, 0],
- [10, 10],
- ['1-10', [1, 10]],
- ['10-10', [10, 10]],
- ['-', [0, 0]],
- ];
- testValues.forEach((entry) =>
- test(`test with input ${entry[0]}`, () => {
- setFrameRangeFromCli(entry[0]);
- expect(Internals.getRange()).toEqual(entry[1]);
- })
- );
-});
diff --git a/packages/core/src/test/validate-image-format.test.ts b/packages/core/src/test/validate-image-format.test.ts
deleted file mode 100644
index 27292829bf..0000000000
--- a/packages/core/src/test/validate-image-format.test.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import {expect, test} from 'vitest';
-import {validateNonNullImageFormat} from '../validation/validate-image-format';
-
-test('"none" is not a valid image format', () => {
- expect(() => validateNonNullImageFormat('jpeg')).not.toThrow();
- expect(() => validateNonNullImageFormat('png')).not.toThrow();
- expect(() => validateNonNullImageFormat('none')).toThrow(
- /Image format should be either "png" or "jpeg"/
- );
-});
diff --git a/packages/core/src/test/webpack-caching.test.ts b/packages/core/src/test/webpack-caching.test.ts
deleted file mode 100644
index 3fc6b781ab..0000000000
--- a/packages/core/src/test/webpack-caching.test.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-import {expect, test} from 'vitest';
-import {
- DEFAULT_WEBPACK_CACHE_ENABLED,
- getWebpackCaching,
- setWebpackCaching,
-} from '../config/webpack-caching';
-import {expectToThrow} from './expect-to-throw';
-
-test('getWebpackCaching - default value', () => {
- expect(getWebpackCaching()).toEqual(DEFAULT_WEBPACK_CACHE_ENABLED);
-});
-
-test('webpack caching - setter - valid input', () => {
- const valuesToTest = [true, false];
- valuesToTest.forEach((entry) => {
- setWebpackCaching(entry);
- expect(getWebpackCaching()).toEqual(entry);
- });
-});
-
-test('webpack caching - setter - invalid input', () => {
- const valuesToTest = [undefined, 'true', 'false'];
- valuesToTest.forEach((entry) => {
- expectToThrow(() => {
- // @ts-expect-error
- setWebpackCaching(entry);
- }, /Caching flag must be a boolean./);
- });
-});
diff --git a/packages/core/src/validation/validate-fps.ts b/packages/core/src/validation/validate-fps.ts
index 6d05ad97f5..172f2277ed 100644
--- a/packages/core/src/validation/validate-fps.ts
+++ b/packages/core/src/validation/validate-fps.ts
@@ -1,10 +1,4 @@
-import type {Codec} from '../config';
-
-export const validateFps = (
- fps: number,
- location: string,
- codec: Codec | null
-) => {
+export const validateFps = (fps: number, location: string, isGif: boolean) => {
if (typeof fps !== 'number') {
throw new Error(
`"fps" must be a number, but you passed a value of type ${typeof fps} ${location}`
@@ -25,9 +19,9 @@ export const validateFps = (
throw new TypeError(`"fps" must be positive, but got ${fps} ${location}`);
}
- if (codec === 'gif' && fps > 50) {
+ if (isGif && fps > 50) {
throw new TypeError(
- `The FPS for a GIF canot be higher than 50. Use the --skip-n-frames option to lower the FPS: https://remotion.dev/docs/render-as-gif`
+ `The FPS for a GIF cannot be higher than 50. Use the --skip-n-frames option to lower the FPS: https://remotion.dev/docs/render-as-gif`
);
}
};
diff --git a/packages/core/src/validation/validate-image-format.ts b/packages/core/src/validation/validate-image-format.ts
deleted file mode 100644
index fefd14fcd0..0000000000
--- a/packages/core/src/validation/validate-image-format.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import type {ImageFormat} from '../config';
-
-export const validateNonNullImageFormat = (imageFormat: ImageFormat) => {
- if (imageFormat !== 'jpeg' && imageFormat !== 'png') {
- throw new TypeError('Image format should be either "png" or "jpeg"');
- }
-};
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 2c76bcd4bc..0e85d93433 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -170,7 +170,7 @@ export const PlayerFn = <T,>(
durationInFrames,
'of the <Player/> component'
);
- Internals.validateFps(fps, 'as a prop of the <Player/> component', null);
+ Internals.validateFps(fps, 'as a prop of the <Player/> component', false);
if (typeof controls !== 'boolean' && typeof controls !== 'undefined') {
throw new TypeError(
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b0207f87fd..ee82410fa1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -161,6 +161,30 @@ importers:
react-dom: [email protected]
typescript: 4.7.2
+ packages/config:
+ specifiers:
+ '@jonny/eslint-config': 3.0.266
+ '@types/node': ^16.7.5
+ '@types/webpack-env': ^1.16.0
+ '@vitejs/plugin-react': ^2.0.0
+ eslint: 8.13.0
+ prettier: ^2.0.5
+ prettier-plugin-organize-imports: ^2.3.4
+ typescript: ^4.7.0
+ vitest: ^0.18.0
+ webpack: 5.72.0
+ devDependencies:
+ '@jonny/eslint-config': 3.0.266_6hvhxfirl4y3p6nuemvvvbadcu
+ '@types/node': 16.10.2
+ '@types/webpack-env': 1.16.2
+ '@vitejs/plugin-react': [email protected]
+ eslint: 8.13.0
+ prettier: 2.6.2
+ prettier-plugin-organize-imports: 2.3.4_lbsuufegg2dnc4wh6qgf26kgdy
+ typescript: 4.7.2
+ vitest: 0.18.0
+ webpack: 5.72.0
+
packages/core:
specifiers:
'@jonny/eslint-config': 3.0.266
@@ -325,7 +349,7 @@ importers:
'@types/react': 18.0.1
eslint: 8.13.0
typescript: 4.7.2
- url-loader: [email protected]
+ url-loader: 4.1.1_csgzzuwaerdr4d7s3u52mzcn7m
packages/eslint-config:
specifiers:
@@ -13756,7 +13780,6 @@ packages:
loader-utils: 2.0.0
schema-utils: 3.1.1
webpack: 5.72.0
- dev: false
/filesize/6.1.0:
resolution: {integrity: sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg==}
@@ -22594,23 +22617,6 @@ packages:
mime-types: 2.1.33
schema-utils: 3.1.1
webpack: 5.72.0
- dev: false
-
- /url-loader/[email protected]:
- resolution: {integrity: sha512-3BTV812+AVHHOJQO8O5MkWgZ5aosP7GnROJwvzLS9hWDj00lZ6Z0wNak423Lp9PBZN05N+Jk/N5Si8jRAlGyWA==}
- engines: {node: '>= 10.13.0'}
- peerDependencies:
- file-loader: '*'
- webpack: ^4.0.0 || ^5.0.0
- peerDependenciesMeta:
- file-loader:
- optional: true
- dependencies:
- loader-utils: 2.0.0
- mime-types: 2.1.33
- schema-utils: 3.1.1
- webpack: 5.72.0
- dev: true
/url-parse-lax/3.0.0:
resolution: {integrity: sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=}