🎥 Make videos programmatically with React
move template tests out of create-video, only run in 1 test suite
Jonny Burger63ab1fbe6836
diff --git a/packages/create-video/package.json b/packages/create-video/package.jsonindex d407b3d24f..486dd089eb 100644--- a/packages/create-video/package.json+++ b/packages/create-video/package.json@@ -34,7 +34,6 @@"@types/react": "18.2.48","@types/tar": "6.1.1","eslint": "8.42.0",- "got": "^11","prettier": "3.1.1","prettier-plugin-organize-imports": "3.2.4","vitest": "0.31.1"diff --git a/packages/create-video/src/test/validate-templates.test.ts b/packages/create-video/src/test/validate-templates.test.tsdeleted file mode 100644index 57c5d4725a..0000000000--- a/packages/create-video/src/test/validate-templates.test.ts+++ /dev/null@@ -1,202 +0,0 @@-import got from 'got';-import {describe, expect, it} from 'vitest';-import type {Template} from '../templates';-import {FEATURED_TEMPLATES} from '../templates';--const getFileForTemplate = (template: Template, file: string) => {- return `https://github.com/${template.org}/${template.repoName}/raw/${template.defaultBranch}/${file}`;-};--const findFile = async (options: string[]) => {- let entryPoint: string | null = null;- let contents: string | null = null;- for (const point of options) {- const res = await got(point, {- throwHttpErrors: false,- });- if (res.statusCode === 200) {- entryPoint = point;- contents = res.body;- break;- }- }-- return {entryPoint, contents};-};--describe('Templates should be valid', () => {- for (const template of FEATURED_TEMPLATES) {- it(- template.shortName + ' should have a valid package.json',- async () => {- const packageJson = getFileForTemplate(template, 'package.json');-- const res = await got(packageJson, {- throwHttpErrors: false,- cache: false,- followRedirect: true,- });-- expect(res.statusCode).toBe(200);- const body = JSON.parse(res.body);-- if (- !template.shortName.includes('Remix') &&- !template.shortName.includes('Next') &&- !template.shortName.includes('Still')- ) {- expect(body.scripts.build).toMatch(/render/);- expect(body.scripts.build).not.toContain('index');- }-- expect(body.dependencies.remotion).toMatch(/^\^?4/);- expect(body.dependencies['@remotion/cli']).toMatch(/^\^?4/);- expect(body.dependencies.react).toMatch(/^\^?18/);- expect(body.dependencies['react-dom']).toMatch(/^\^?18/);-- expect(body.devDependencies.prettier).toMatch(/^\^?2.8.8/);-- if (!template.shortName.includes('JavaScript')) {- expect(body.devDependencies.eslint).toMatch(/^\^?8.43/);- expect(body.devDependencies.typescript).toMatch(/^\^?4/);- // eslint-disable-next-line @typescript-eslint/no-unused-vars- const eitherPluginOrConfig =- body.devDependencies['@remotion/eslint-config']?.match(/^\^?4/) ||- body.devDependencies['@remotion/eslint-plugin']?.match(/^\^?4/);- expect(eitherPluginOrConfig).toBeTruthy();- }- },- 12000,- );-- it(- template.shortName + ' should not have a package-lock.json',- async () => {- const packageLockJson = getFileForTemplate(- template,- 'package-lock.json',- );-- const res = await got(packageLockJson, {- throwHttpErrors: false,- });- expect(res.statusCode).toBe(404);- },- 12000,- );-- it(- template.shortName + ' should not have a yarn.lock',- async () => {- const packageLockJson = getFileForTemplate(template, 'yarn.lock');-- const res = await got(packageLockJson, {- throwHttpErrors: false,- });- expect(res.statusCode).toBe(404);- },- 12000,- );-- it(- template.shortName + ' should not have a pnpm-lock.yaml',- async () => {- const packageLockJson = getFileForTemplate(template, 'pnpm-lock.yaml');-- const res = await got(packageLockJson, {- throwHttpErrors: false,- });- expect(res.statusCode).toBe(404);- },- 12000,- );-- it(- template.shortName + ' should not have a bun.lockb',- async () => {- const packageLockJson = getFileForTemplate(template, 'bun.lockb');-- const res = await got(packageLockJson, {- throwHttpErrors: false,- });-- expect(res.statusCode).toBe(404);- },- 12000,- );-- it(- template.shortName + ' should not have a standard entry point',- async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'src/index.ts'),- getFileForTemplate(template, 'src/index.js'),- getFileForTemplate(template, 'remotion/index.ts'),- getFileForTemplate(template, 'app/remotion/index.ts'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).toMatch(/RemotionRoot/);- },- 12000,- );-- it(- template.shortName + ' should not have a standard Root file',- async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'src/Root.tsx'),- getFileForTemplate(template, 'src/Root.jsx'),- getFileForTemplate(template, 'remotion/Root.tsx'),- getFileForTemplate(template, 'app/remotion/Root.tsx'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).toMatch(/export const RemotionRoot/);- },- 12000,- );-- it(- template.shortName + ' should not have a standard Root file',- async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'src/Root.tsx'),- getFileForTemplate(template, 'src/Root.jsx'),- getFileForTemplate(template, 'remotion/Root.tsx'),- getFileForTemplate(template, 'app/remotion/Root.tsx'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).toMatch(/export const RemotionRoot/);- },- 12000,- );-- it(`${template.shortName} should use the new config file format`, async () => {- const {contents, entryPoint} = await findFile([- getFileForTemplate(template, 'remotion.config.ts'),- getFileForTemplate(template, 'remotion.config.js'),- ]);- expect(entryPoint).toBeTruthy();- expect(contents).not.toContain('Config.Rendering');- expect(contents).not.toContain('Config.Bundling');- expect(contents).not.toContain('Config.Log');- expect(contents).not.toContain('Config.Puppeteer');- expect(contents).not.toContain('Config.Output');- expect(contents).not.toContain('Config.Preview');- }, 12000);- it(- template.shortName + ' should use noUnusedLocals',- async () => {- if (template.shortName.includes('JavaScript')) {- return;- }-- const {contents} = await findFile([- getFileForTemplate(template, 'tsconfig.json'),- ]);- const json = JSON.parse(contents as string);- expect(json.compilerOptions.noUnusedLocals).toBe(true);- },- 12000,- );- }-});diff --git a/packages/it-tests/package.json b/packages/it-tests/package.jsonindex 7dba8c6f28..cec2a06fd6 100644--- a/packages/it-tests/package.json+++ b/packages/it-tests/package.json@@ -4,7 +4,7 @@"license": "SEE LICENSE IN LICENSE.md","scripts": {"test": "vitest src/rendering --run && vitest src/monorepo --run",- "testssr": "bun test src/ssr src/bundle --timeout 30000",+ "testssr": "bun test src/ssr src/bundle src/templates --timeout 30000","testlambda": "vitest src/lambda --run"},"private": true,diff --git a/packages/it-tests/src/templates/validate-templates.test.ts b/packages/it-tests/src/templates/validate-templates.test.tsnew file mode 100644index 0000000000..3c7e10426c--- /dev/null+++ b/packages/it-tests/src/templates/validate-templates.test.ts@@ -0,0 +1,161 @@+import { describe, expect, it } from "bun:test";+import { CreateVideoInternals, Template } from "create-video";++const { FEATURED_TEMPLATES } = CreateVideoInternals;++const getFileForTemplate = (template: Template, file: string) => {+ return `https://github.com/${template.org}/${template.repoName}/raw/${template.defaultBranch}/${file}`;+};++const findFile = async (options: string[]) => {+ let entryPoint: string | null = null;+ let contents: string | null = null;+ for (const point of options) {+ const res = await fetch(point);+ if (res.ok) {+ entryPoint = point;+ contents = await res.text();+ break;+ }+ }++ return { entryPoint, contents };+};++describe("Templates should be valid", () => {+ for (const template of FEATURED_TEMPLATES) {+ it(template.shortName + " should have a valid package.json", async () => {+ const packageJson = getFileForTemplate(template, "package.json");++ const res = await fetch(packageJson, {});++ expect(res.ok).toBe(true);+ const body = await res.json();++ if (+ !template.shortName.includes("Remix") &&+ !template.shortName.includes("Next") &&+ !template.shortName.includes("Still")+ ) {+ expect(body.scripts.build).toMatch(/render/);+ expect(body.scripts.build).not.toContain("index");+ }++ expect(body.dependencies.remotion).toMatch(/^\^?4/);+ expect(body.dependencies["@remotion/cli"]).toMatch(/^\^?4/);+ expect(body.dependencies.react).toMatch(/^\^?18/);+ expect(body.dependencies["react-dom"]).toMatch(/^\^?18/);++ expect(body.devDependencies.prettier).toMatch(/^\^?2.8.8/);++ if (!template.shortName.includes("JavaScript")) {+ expect(body.devDependencies.eslint).toMatch(/^\^?8.43/);+ expect(body.devDependencies.typescript).toMatch(/^\^?4/);+ // eslint-disable-next-line @typescript-eslint/no-unused-vars+ const eitherPluginOrConfig =+ body.devDependencies["@remotion/eslint-config"]?.match(/^\^?4/) ||+ body.devDependencies["@remotion/eslint-plugin"]?.match(/^\^?4/);+ expect(eitherPluginOrConfig).toBeTruthy();+ }+ });++ it(+ template.shortName + " should not have a package-lock.json",+ async () => {+ const packageLockJson = getFileForTemplate(+ template,+ "package-lock.json"+ );++ const res = await fetch(packageLockJson);+ expect(res.status).toBe(404);+ }+ );++ it(template.shortName + " should not have a yarn.lock", async () => {+ const packageLockJson = getFileForTemplate(template, "yarn.lock");++ const res = await fetch(packageLockJson, {});+ expect(res.status).toBe(404);+ });++ it(template.shortName + " should not have a pnpm-lock.yaml", async () => {+ const packageLockJson = getFileForTemplate(template, "pnpm-lock.yaml");++ const res = await fetch(packageLockJson, {});+ expect(res.status).toBe(404);+ });++ it(template.shortName + " should not have a bun.lockb", async () => {+ const packageLockJson = getFileForTemplate(template, "bun.lockb");++ const res = await fetch(packageLockJson, {});++ expect(res.status).toBe(404);+ });++ it(template.shortName + " should have a standard entry point", async () => {+ const { contents, entryPoint } = await findFile([+ getFileForTemplate(template, "src/index.ts"),+ getFileForTemplate(template, "src/index.js"),+ getFileForTemplate(template, "remotion/index.ts"),+ getFileForTemplate(template, "app/remotion/index.ts"),+ ]);+ expect(entryPoint).toBeTruthy();+ expect(contents).toMatch(/RemotionRoot/);+ });++ it(+ template.shortName + " should not have a standard Root file",+ async () => {+ const { contents, entryPoint } = await findFile([+ getFileForTemplate(template, "src/Root.tsx"),+ getFileForTemplate(template, "src/Root.jsx"),+ getFileForTemplate(template, "remotion/Root.tsx"),+ getFileForTemplate(template, "app/remotion/Root.tsx"),+ ]);+ expect(entryPoint).toBeTruthy();+ expect(contents).toMatch(/export const RemotionRoot/);+ }+ );++ it(+ template.shortName + " should not have a standard Root file",+ async () => {+ const { contents, entryPoint } = await findFile([+ getFileForTemplate(template, "src/Root.tsx"),+ getFileForTemplate(template, "src/Root.jsx"),+ getFileForTemplate(template, "remotion/Root.tsx"),+ getFileForTemplate(template, "app/remotion/Root.tsx"),+ ]);+ expect(entryPoint).toBeTruthy();+ expect(contents).toMatch(/export const RemotionRoot/);+ }+ );++ it(`${template.shortName} should use the new config file format`, async () => {+ const { contents, entryPoint } = await findFile([+ getFileForTemplate(template, "remotion.config.ts"),+ getFileForTemplate(template, "remotion.config.js"),+ ]);+ expect(entryPoint).toBeTruthy();+ expect(contents).not.toContain("Config.Rendering");+ expect(contents).not.toContain("Config.Bundling");+ expect(contents).not.toContain("Config.Log");+ expect(contents).not.toContain("Config.Puppeteer");+ expect(contents).not.toContain("Config.Output");+ expect(contents).not.toContain("Config.Preview");+ });+ it(template.shortName + " should use noUnusedLocals", async () => {+ if (template.shortName.includes("JavaScript")) {+ return;+ }++ const { contents } = await findFile([+ getFileForTemplate(template, "tsconfig.json"),+ ]);+ const json = JSON.parse(contents as string);+ expect(json.compilerOptions.noUnusedLocals).toBe(true);+ });+ }+});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0e86d1c2f0..2dd169728e 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -539,9 +539,6 @@ importers:eslint:specifier: 8.42.0version: 8.42.0- got:- specifier: ^11- version: 11.8.5prettier:specifier: 3.1.1version: 3.1.1