Open source CapCut alternative.
TypeScript
fix(site): run the ffmpeg recipe tests on CI's ffmpeg
David Lee2bb3c6e060c
diff --git a/site/packages/effects-kit/src/flash.test.ts b/site/packages/effects-kit/src/flash.test.tsindex a2561e33..d8b306d5 100644--- a/site/packages/effects-kit/src/flash.test.ts+++ b/site/packages/effects-kit/src/flash.test.ts@@ -1,9 +1,7 @@import { describe, expect, test } from "bun:test";import { spawnSync } from "node:child_process";-import { existsSync } from "node:fs";-import path from "node:path";-import { fileURLToPath } from "node:url";import { Canvas } from "skia-canvas";+import { TEST_FFMPEG } from "./testing/ffmpeg";import { applyClipEffects, applyEffectToCanvas, effectFilterLines, effectPreviewState } from "./effects";// The black strobe: a flash held dark for the first half of every pulse.@@ -46,9 +44,8 @@ describe("the flash strobe", () => {expect(lum(lit)).toBe(128);});- test("the ffmpeg recipe strobes the same frames in the bundled LGPL build", () => {- const bin = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");- expect(existsSync(bin)).toBe(true);+ test("the ffmpeg recipe strobes the same frames in ffmpeg", () => {+ const bin = TEST_FFMPEG;const lines = effectFilterLines("in", "out", "flash", 1, 0, 1, 64, 64, "t", undefined, undefined, undefined, STROBE)!;const graph = `color=c=0x808080:s=64x64:r=30:d=0.4,format=yuv420p[in];${lines.join(";")}`;const run = spawnSync(bin, [@@ -78,8 +75,8 @@ describe("the fastest strobe", () => {expect(dark).toEqual([...Array(N).keys()].map((n) => n % 2 === 0));});- test("alternates on the same frames in the bundled LGPL build", () => {- const bin = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");+ test("alternates on the same frames in ffmpeg", () => {+ const bin = TEST_FFMPEG;const lines = effectFilterLines("in", "out", "flash", 1, START, START + 1, 64, 64, "t", undefined, undefined, undefined, FAST)!;const graph = `color=c=0x808080:s=64x64:r=30:d=4.2,format=yuv420p[in];${lines.join(";")}`;const run = spawnSync(bin, ["-v", "error", "-filter_complex", graph, "-map", "[out]", "-f", "rawvideo", "-pix_fmt", "gray", "-"]);@@ -121,8 +118,8 @@ describe("the flash flicker", () => {expect(px(0, 0)[3]).toBe(0);});- test("the ffmpeg recipe lights the same frames in the bundled LGPL build", () => {- const bin = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");+ test("the ffmpeg recipe lights the same frames in ffmpeg", () => {+ const bin = TEST_FFMPEG;const lines = effectFilterLines("in", "out", "flash", 1, 0, 2, 64, 64, "t", undefined, undefined, undefined, FLICKER)!;const graph = `color=c=0x202020:s=64x64:r=30:d=${FRAMES / 30},format=yuv420p[in];${lines.join(";")}`;const run = spawnSync(bin, ["-v", "error", "-filter_complex", graph, "-map", "[out]", "-f", "rawvideo", "-pix_fmt", "gray", "-"]);diff --git a/site/packages/effects-kit/src/glitchRgb.test.ts b/site/packages/effects-kit/src/glitchRgb.test.tsindex 4eb80511..4907399c 100644--- a/site/packages/effects-kit/src/glitchRgb.test.ts+++ b/site/packages/effects-kit/src/glitchRgb.test.ts@@ -1,9 +1,7 @@import { afterAll, beforeAll, describe, expect, test } from "bun:test";import { spawnSync } from "node:child_process";-import { existsSync } from "node:fs";-import path from "node:path";-import { fileURLToPath } from "node:url";import { Canvas } from "skia-canvas";+import { TEST_FFMPEG } from "./testing/ffmpeg";import { applyEffectToCanvas, effectFilterLines, effectPreviewState, effectRecipe, glitchHitAt } from "./effects";/**@@ -94,9 +92,8 @@ describe("a pinned glitch", () => {}});- test("the ffmpeg recipe splits the same way in the bundled LGPL build", () => {- const bin = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");- expect(existsSync(bin)).toBe(true);+ test("the ffmpeg recipe splits the same way in ffmpeg", () => {+ const bin = TEST_FFMPEG;const { up, down } = sides();const lines = effectFilterLines("in", "out", "glitch:rgb", 1, 0, 0.2, S, S, "t")!;const graph =diff --git a/site/packages/effects-kit/src/scorch.test.ts b/site/packages/effects-kit/src/scorch.test.tsindex b4c90806..5dae336c 100644--- a/site/packages/effects-kit/src/scorch.test.ts+++ b/site/packages/effects-kit/src/scorch.test.ts@@ -1,9 +1,7 @@import { describe, expect, test } from "bun:test";import { spawnSync } from "node:child_process";-import { existsSync } from "node:fs";-import path from "node:path";-import { fileURLToPath } from "node:url";import { Canvas } from "skia-canvas";+import { TEST_FFMPEG } from "./testing/ffmpeg";import { applyEffectToCanvas, effectFilterLines, effectPreviewState, effectRecipe, type WashArea } from "./effects";/**@@ -141,9 +139,8 @@ describe("the scorch", () => {expect(Math.abs(graph(10).length - graph(1).length)).toBeLessThan(40);});- test("the ffmpeg recipe deals the same tones and patches in the bundled LGPL build", () => {- const bin = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");- expect(existsSync(bin)).toBe(true);+ test("the ffmpeg recipe deals the same tones and patches in ffmpeg", () => {+ const bin = TEST_FFMPEG;// A 4:4:4 chain, so the rims keep their color per pixel.const chroma = { pixFmt: "yuv444p", overlay: ":format=yuv444" };const lines = effectFilterLines("in", "out", "scorch", 1, 0, FRAMES / 30, S, S, "t", undefined, undefined, chroma)!;diff --git a/site/packages/effects-kit/src/testing/ffmpeg.ts b/site/packages/effects-kit/src/testing/ffmpeg.tsnew file mode 100644index 00000000..b02cdb83--- /dev/null+++ b/site/packages/effects-kit/src/testing/ffmpeg.ts@@ -0,0 +1,9 @@+import { existsSync } from "node:fs";+import path from "node:path";+import { fileURLToPath } from "node:url";++// The ffmpeg the recipe tests render with: the app's bundled build on a Mac+// checkout, and the one on PATH in CI, which installs ffmpeg itself.+const BUNDLED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../../vendor/donkey-tools/ffmpeg");++export const TEST_FFMPEG = existsSync(BUNDLED) ? BUNDLED : "ffmpeg";diff --git a/site/src/cut/lib/localImportPreview.test.ts b/site/src/cut/lib/localImportPreview.test.tsindex 9b3bab22..3fca7a53 100644--- a/site/src/cut/lib/localImportPreview.test.ts+++ b/site/src/cut/lib/localImportPreview.test.ts@@ -11,7 +11,7 @@ describe("openLocalImport", () => {const item = useLightbox.getState().item;expect(item?.ratio).toBe(1080 / 1920);expect(item?.duration).toBe(21.8);- expect(item?.poster).toStartWith("blob:");+ expect(item?.poster?.startsWith("blob:")).toBe(true);useLightbox.getState().close();});diff --git a/site/src/cut/lib/transitionShape.test.ts b/site/src/cut/lib/transitionShape.test.tsindex 2c962f11..ce528520 100644--- a/site/src/cut/lib/transitionShape.test.ts+++ b/site/src/cut/lib/transitionShape.test.ts@@ -22,7 +22,9 @@ const H = 160;const FPS = 30;const SECONDS = 0.5;const FRAMES = Math.round(SECONDS * FPS);-const FFMPEG = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");+// The app's bundled ffmpeg on a Mac checkout; CI installs ffmpeg on PATH.+const BUNDLED_FFMPEG = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../vendor/donkey-tools/ffmpeg");+const FFMPEG = existsSync(BUNDLED_FFMPEG) ? BUNDLED_FFMPEG : "ffmpeg";beforeAll(() => {setRasterFactory({@@ -104,8 +106,8 @@ const meanDiff = (a: Uint8Array, b: Uint8Array) => a.reduce((s, v, i) => s + Matconst at = (f: Uint8Array, x: number, y: number) => f[Math.round(y) * W + Math.round(x)];describe("the shaped transitions", () => {- test("the bundled ffmpeg is there", () => {- expect(existsSync(FFMPEG)).toBe(true);+ test("an ffmpeg is there", () => {+ expect(spawnSync(FFMPEG, ["-version"]).status).toBe(0);});test("the clock wipe sweeps a wedge from the top edge down to the left one", () => {