Skip to content

🎥 Make videos programmatically with React

test utils

Jonny Burger02a67901eb60
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.json
index 8d2f2c0ec6..eadf3c9d3f 100644
--- a/packages/cloudrun/package.json
+++ b/packages/cloudrun/package.json
@@ -35,7 +35,7 @@
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.2.2",
"ts-node": "^10.8.0",
- "vitest": "0.24.3"
+ "vitest": "0.31.1"
},
"exports": {
"./package.json": "./package.json",
diff --git a/packages/docs/docs/transitions/transitionseries.md b/packages/docs/docs/transitions/transitionseries.md
index bcdbf20bc2..8e7b842d1a 100644
--- a/packages/docs/docs/transitions/transitionseries.md
+++ b/packages/docs/docs/transitions/transitionseries.md
@@ -6,6 +6,8 @@ title: "<TransitionSeries>"
_available from v4.0.21_
+The `<TransitionSeries>` component behaves the same as the [`<Series>`](/docs/series) component, but allows for `<TransitionSeries.Transition>` components to be rendered between `<TransitionSeries.Sequence>` components.
+
```tsx twoslash title="MyComp.tsx"
import { AbsoluteFill } from "remotion";
const Fill = ({ color }: { color: string }) => (
diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json
new file mode 100644
index 0000000000..e8bfd7b3ae
--- /dev/null
+++ b/packages/test-utils/package.json
@@ -0,0 +1,32 @@
+{
+ "name": "@remotion/test-utils",
+ "version": "4.0.20",
+ "description": "Utilities for using tailwind css in Remotion",
+ "main": "dist",
+ "sideEffects": false,
+ "scripts": {
+ "lint": "eslint src --ext ts,tsx",
+ "watch": "tsc -w"
+ },
+ "author": "Jonny Burger <[email protected]>",
+ "contributors": [],
+ "license": "MIT",
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion"
+ },
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "devDependencies": {
+ "react": "18.0.0",
+ "react-dom": "18.0.0",
+ "remotion": "workspace:*",
+ "@jonny/eslint-config": "3.0.266",
+ "@types/node": "18.14.6",
+ "@types/react": "18.0.26",
+ "eslint": "8.42.0",
+ "prettier": "^2.7.1",
+ "prettier-plugin-organize-imports": "^3.2.2"
+ },
+ "private": true
+}
diff --git a/packages/test-utils/src/composition-manager-context.ts b/packages/test-utils/src/composition-manager-context.ts
new file mode 100644
index 0000000000..006ec01488
--- /dev/null
+++ b/packages/test-utils/src/composition-manager-context.ts
@@ -0,0 +1,34 @@
+import React, { ComponentType, useContext } from "react";
+import { CompositionManagerContext, Internals } from "remotion";
+
+const Mock: React.FC = () => null;
+
+export const makeMockCompositionManagerContext =
+ (): CompositionManagerContext => {
+ const compositions = useContext(Internals.CompositionManager);
+
+ return {
+ ...compositions,
+ compositions: [
+ {
+ id: "markup",
+ component: React.lazy(() =>
+ Promise.resolve({
+ default: Mock as ComponentType<unknown>,
+ })
+ ),
+ nonce: 0,
+ defaultProps: undefined,
+ folderName: null,
+ parentFolderName: null,
+ schema: null,
+ calculateMetadata: null,
+ durationInFrames: 100,
+ fps: 30,
+ height: 100,
+ width: 100,
+ },
+ ],
+ currentComposition: "markup",
+ };
+ };
diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts
new file mode 100644
index 0000000000..75c498f3f4
--- /dev/null
+++ b/packages/test-utils/src/index.ts
@@ -0,0 +1 @@
+export * from "./composition-manager-context";
diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json
new file mode 100644
index 0000000000..11c422b382
--- /dev/null
+++ b/packages/test-utils/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ "extends": "../tsconfig.settings.json",
+ "compilerOptions": {
+ "composite": true,
+ "rootDir": "./src",
+ "outDir": "dist",
+ "skipLibCheck": true
+ },
+ "include": ["src"],
+ "references": [
+ {
+ "path": "../core"
+ }
+ ]
+}
diff --git a/packages/transitions/.prettierrc.js b/packages/transitions/.prettierrc.js
deleted file mode 100644
index 32eb24f3bf..0000000000
--- a/packages/transitions/.prettierrc.js
+++ /dev/null
@@ -1,14 +0,0 @@
-module.exports = {
- singleQuote: true,
- bracketSpacing: false,
- useTabs: true,
- overrides: [
- {
- files: ['*.yml'],
- options: {
- singleQuote: false,
- },
- },
- ],
- plugins: [require.resolve('prettier-plugin-organize-imports')],
-};
diff --git a/packages/transitions/.prettierrc.mjs b/packages/transitions/.prettierrc.mjs
new file mode 100644
index 0000000000..7129f6a51c
--- /dev/null
+++ b/packages/transitions/.prettierrc.mjs
@@ -0,0 +1,14 @@
+module.exports = {
+ singleQuote: true,
+ bracketSpacing: false,
+ useTabs: true,
+ overrides: [
+ {
+ files: ["*.yml"],
+ options: {
+ singleQuote: false,
+ },
+ },
+ ],
+ plugins: [require.resolve("prettier-plugin-organize-imports")],
+};
diff --git a/packages/transitions/package.json b/packages/transitions/package.json
index 3848f6ed7f..9a3bc76dcf 100644
--- a/packages/transitions/package.json
+++ b/packages/transitions/package.json
@@ -1,80 +1,82 @@
{
- "name": "@remotion/transitions",
- "version": "4.0.20",
- "description": "Transition presets for Remotion",
- "sideEffects": false,
- "type": "module",
- "main": "dist/index.js",
- "types": "dist/index.d.ts",
- "scripts": {
- "lint": "eslint src --ext ts,tsx",
- "watch": "tsc -w",
- "build": "tsc -d"
- },
- "author": "Jonny Burger",
- "contributors": [],
- "license": "MIT",
- "repository": {
- "url": "https://github.com/remotion-dev/remotion"
- },
- "bugs": {
- "url": "https://github.com/remotion-dev/remotion/issues"
- },
- "dependencies": {
- "remotion": "workspace:*"
- },
- "devDependencies": {
- "@jonny/eslint-config": "3.0.273",
- "eslint": "8.42.0",
- "prettier": "^2.0.5",
- "prettier-plugin-organize-imports": "^3.2.2",
- "remotion": "workspace:*",
- "react": "18.0.0",
- "react-dom": "18.0.0",
- "@types/react": "18.0.26",
- "@types/react-dom": "18.0.10"
- },
- "peerDependencies": {
- "react": ">=16.8.0",
- "react-dom": ">=16.8.0"
- },
- "keywords": [
- "remotion",
- "transitions"
- ],
- "publishConfig": {
- "access": "public"
- },
- "exports": {
- ".": {
- "import": "./dist/index.js",
- "types": "./dist/index.d.ts"
- },
- "./fade": {
- "import": "./dist/presentations/fade.js",
- "types": "./dist/presentations/fade.d.ts"
- },
- "./slide": {
- "import": "./dist/presentations/slide.js",
- "types": "./dist/presentations/slide.d.ts"
- },
- "./wipe": {
- "import": "./dist/presentations/wipe.js",
- "types": "./dist/presentations/wipe.d.ts"
- },
- "./package.json": "./package.json"
- },
- "typesVersions": {
- ">=1.0": {
- "wipe": [
- "dist/presentations/wipe.d.ts"
- ],
- "slide": [
- "dist/presentations/slide.d.ts"
- ],
- "fade": [
- "dist/presentations/fade.d.ts"
- ]
- }
- }
+ "name": "@remotion/transitions",
+ "version": "4.0.20",
+ "description": "Transition presets for Remotion",
+ "sideEffects": false,
+ "type": "module",
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
+ "scripts": {
+ "lint": "eslint src --ext ts,tsx",
+ "watch": "tsc -w",
+ "build": "tsc -d"
+ },
+ "author": "Jonny Burger",
+ "contributors": [],
+ "license": "MIT",
+ "repository": {
+ "url": "https://github.com/remotion-dev/remotion"
+ },
+ "bugs": {
+ "url": "https://github.com/remotion-dev/remotion/issues"
+ },
+ "dependencies": {
+ "remotion": "workspace:*"
+ },
+ "devDependencies": {
+ "@jonny/eslint-config": "3.0.273",
+ "eslint": "8.42.0",
+ "prettier": "^2.7.1",
+ "prettier-plugin-organize-imports": "^3.2.2",
+ "remotion": "workspace:*",
+ "react": "18.0.0",
+ "react-dom": "18.0.0",
+ "vitest": "0.31.1",
+ "@types/react": "18.0.26",
+ "@types/react-dom": "18.0.10",
+ "@remotion/test-utils": "workspace:*"
+ },
+ "peerDependencies": {
+ "react": ">=16.8.0",
+ "react-dom": ">=16.8.0"
+ },
+ "keywords": [
+ "remotion",
+ "transitions"
+ ],
+ "publishConfig": {
+ "access": "public"
+ },
+ "exports": {
+ ".": {
+ "import": "./dist/index.js",
+ "types": "./dist/index.d.ts"
+ },
+ "./fade": {
+ "import": "./dist/presentations/fade.js",
+ "types": "./dist/presentations/fade.d.ts"
+ },
+ "./slide": {
+ "import": "./dist/presentations/slide.js",
+ "types": "./dist/presentations/slide.d.ts"
+ },
+ "./wipe": {
+ "import": "./dist/presentations/wipe.js",
+ "types": "./dist/presentations/wipe.d.ts"
+ },
+ "./package.json": "./package.json"
+ },
+ "typesVersions": {
+ ">=1.0": {
+ "wipe": [
+ "dist/presentations/wipe.d.ts"
+ ],
+ "slide": [
+ "dist/presentations/slide.d.ts"
+ ],
+ "fade": [
+ "dist/presentations/fade.d.ts"
+ ]
+ }
+ }
}
diff --git a/packages/transitions/src/test/transitions.test.tsx b/packages/transitions/src/test/transitions.test.tsx
new file mode 100644
index 0000000000..a25e3c2d92
--- /dev/null
+++ b/packages/transitions/src/test/transitions.test.tsx
@@ -0,0 +1,80 @@
+import { test } from "vitest";
+import { renderToString } from "react-dom/server";
+import { TransitionSeries } from "../TransitionSeries.js";
+import { AbsoluteFill, Internals } from "remotion";
+import { fade } from "../presentations/fade.js";
+import { linearTiming } from "../timings/linear.js";
+import { makeMockCompositionManagerContext } from "@remotion/test-utils";
+
+const renderForFrame = (frame: number, markup: React.ReactNode) => {
+ return renderToString(
+ <Internals.CanUseRemotionHooksProvider>
+ <Internals.CompositionManager.Provider
+ value={makeMockCompositionManagerContext()}
+ >
+ <Internals.Timeline.TimelineContext.Provider
+ value={{
+ rootId: "",
+ frame: {
+ "my-comp": frame,
+ },
+ playing: false,
+ imperativePlaying: {
+ current: false,
+ },
+ playbackRate: 1,
+ setPlaybackRate: () => {
+ throw new Error("playback rate");
+ },
+ audioAndVideoTags: { current: [] },
+ }}
+ >
+ {markup}
+ </Internals.Timeline.TimelineContext.Provider>
+ </Internals.CompositionManager.Provider>
+ </Internals.CanUseRemotionHooksProvider>
+ );
+};
+
+const Letter: React.FC<{
+ children: React.ReactNode;
+ color: string;
+}> = ({ children, color }) => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: color,
+ opacity: 0.9,
+ justifyContent: "center",
+ alignItems: "center",
+ fontSize: 200,
+ color: "white",
+ }}
+ >
+ {children}
+ </AbsoluteFill>
+ );
+};
+
+test("Transitions", () => {
+ renderForFrame(
+ 10,
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="green">C</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={fade({})}
+ timing={linearTiming({
+ durationInFrames: 40,
+ })}
+ />
+ <TransitionSeries.Transition
+ presentation={fade({})}
+ timing={linearTiming({
+ durationInFrames: 40,
+ })}
+ />
+ </TransitionSeries>
+ );
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 05b6a94647..3dfc3ce6c3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -364,8 +364,8 @@ importers:
specifier: ^10.8.0
version: 10.8.0(@types/[email protected])([email protected])
vitest:
- specifier: 0.24.3
- version: 0.24.3
+ specifier: 0.31.1
+ version: 0.31.1([email protected])
packages/cloudrun/container:
dependencies:
@@ -1707,6 +1707,36 @@ importers:
specifier: ^1.2.2
version: 1.2.2
+ packages/test-utils:
+ devDependencies:
+ '@jonny/eslint-config':
+ specifier: 3.0.266
+ '@types/node':
+ specifier: 18.14.6
+ version: 18.14.6
+ '@types/react':
+ specifier: 18.0.26
+ version: 18.0.26
+ eslint:
+ specifier: 8.42.0
+ version: 8.42.0
+ prettier:
+ specifier: ^2.7.1
+ version: 2.8.4
+ prettier-plugin-organize-imports:
+ specifier: ^3.2.2
+ react:
+ specifier: 18.0.0
+ version: 18.0.0
+ react-dom:
+ specifier: 18.0.0
+ version: 18.0.0([email protected])
+ remotion:
+ specifier: workspace:*
+ version: link:../core
+
packages/three:
dependencies:
remotion:
@@ -1768,6 +1798,9 @@ importers:
'@jonny/eslint-config':
specifier: 3.0.273
+ '@remotion/test-utils':
+ specifier: workspace:*
+ version: link:../test-utils
'@types/react':
specifier: 18.0.26
version: 18.0.26
@@ -1778,7 +1811,7 @@ importers:
specifier: 8.42.0
version: 8.42.0
prettier:
- specifier: ^2.0.5
+ specifier: ^2.7.1
version: 2.8.4
prettier-plugin-organize-imports:
specifier: ^3.2.2
@@ -1789,6 +1822,9 @@ importers:
react-dom:
specifier: 18.0.0
version: 18.0.0([email protected])
+ vitest:
+ specifier: 0.31.1
+ version: 0.31.1([email protected])
packages/zod-types:
dependencies:
@@ -8778,7 +8814,7 @@ packages:
chalk: 4.1.2
dom-accessibility-api: 0.5.14
lz-string: 1.4.4
- pretty-format: 27.2.4
+ pretty-format: 27.5.1
dev: true
@@ -20667,12 +20703,6 @@ packages:
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
engines: {node: '>=8'}
- resolution: {integrity: sha512-pv48ybn4iE1O9RLgCAN0iU4Xv7RlBTiit6DKmMiErbs9x1wH6vXBs45tWc0H5wUIF6TLTrKweqkmYF/iraQKNw==}
- dependencies:
- acorn: 8.8.2
- dev: true
-
resolution: {integrity: sha512-QZTsipNpa2Ppr6v1AmJHESqJ3Uz247MUS0OjrnnZjFAvEoWqxuyFuXn2xLgMtRnijJShAa1HL0gtJyUs7u7n3Q==}
dependencies:
@@ -21095,20 +21125,10 @@ packages:
resolution: {integrity: sha512-kRwSG8Zx4tjF9ZiyH4bhaebu+EDz1BOx9hOigYHlUW4xxI/wKIUQUqo018UlU4ar6ATPBsaMrdbKZ+tmPdohFA==}
- resolution: {integrity: sha512-NX5KeqHOBZU6Bc0xj9Vr5Szbb1j8tUHIeD18s41aDJaPeC5QTdEhK0SpdpUrZlj2nv5cctNcSjaKNanXlfcVEQ==}
- engines: {node: '>=14.0.0'}
- dev: true
-
resolution: {integrity: sha512-paHQtnrlS1QZYKF/GnLoOM/DN9fqaGOFbCbxzAhwniySnzl9Ebk8w73/dd34DAhe/obUbPAOldTyYXQZxnPBPQ==}
engines: {node: '>=14.0.0'}
- resolution: {integrity: sha512-bSGlgwLBYf7PnUsQ6WOc6SJ3pGOcd+d8AA6EUnLDDM0kWEstC1JIlSZA3UNliDXhd9ABoS7hiRBDCu+XP/sf1Q==}
- engines: {node: '>=14.0.0'}
- dev: true
-
resolution: {integrity: sha512-7eORpyqImoOvkQJCSkL0d0mB4NHHIFAy4b1u8PHdDa7SjGS2njzl6/lyGoZLm+eyYEtlUmFGE0rFj66SWxZgQQ==}
engines: {node: '>=14.0.0'}
@@ -22113,47 +22133,6 @@ packages:
vite: 4.1.3(@types/[email protected])
dev: false
- resolution: {integrity: sha512-aM0auuPPgMSstWvr851hB74g/LKaKBzSxcG3da7ejfZbx08Y21JpZmbmDYrMTCGhVZKqTGwzcnLMwyfz2WzkhQ==}
- engines: {node: '>=v14.16.0'}
- hasBin: true
- peerDependencies:
- '@edge-runtime/vm': '*'
- '@vitest/browser': '*'
- '@vitest/ui': '*'
- happy-dom: '*'
- jsdom: '*'
- peerDependenciesMeta:
- '@edge-runtime/vm':
- optional: true
- '@vitest/browser':
- optional: true
- '@vitest/ui':
- optional: true
- happy-dom:
- optional: true
- jsdom:
- optional: true
- dependencies:
- '@types/chai': 4.3.5
- '@types/chai-subset': 1.3.3
- '@types/node': 18.14.6
- chai: 4.3.7
- debug: 4.3.4([email protected])
- local-pkg: 0.4.3
- strip-literal: 0.4.2
- tinybench: 2.5.0
- tinypool: 0.3.0
- tinyspy: 1.0.2
- vite: 3.0.0
- transitivePeerDependencies:
- - less
- - sass
- - stylus
- - supports-color
- - terser
- dev: true
-
resolution: {integrity: sha512-/dOoOgzoFk/5pTvg1E65WVaobknWREN15+HF+0ucudo3dDG/vCZoXTQrjIfEaWvQXmqScwkRodrTbM/ScMpRcQ==}
engines: {node: '>=v14.18.0'}
diff --git a/tsconfig.json b/tsconfig.json
index c102c3c029..72b8efcc7f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -104,6 +104,9 @@
{
"path": "./packages/tailwind"
},
+ {
+ "path": "./packages/test-utils"
+ },
{
"path": "./packages/three"
},