|
1 | 1 | import assert from "node:assert/strict"; |
2 | 2 | import { spawnSync } from "node:child_process"; |
3 | | -import { cpSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { |
| 4 | + cpSync, |
| 5 | + mkdirSync, |
| 6 | + mkdtempSync, |
| 7 | + readFileSync, |
| 8 | + readdirSync, |
| 9 | + rmSync, |
| 10 | + writeFileSync, |
| 11 | +} from "node:fs"; |
4 | 12 | import { tmpdir } from "node:os"; |
5 | 13 | import { dirname, join, resolve } from "node:path"; |
6 | 14 | import test from "node:test"; |
@@ -80,3 +88,44 @@ test("every embedded-caption theme compiles a sane heroless body timeline", asyn |
80 | 88 | }); |
81 | 89 | } |
82 | 90 | }); |
| 91 | + |
| 92 | +for (const heroless of [false, true]) { |
| 93 | + for (const grain of [0, 3, undefined]) { |
| 94 | + test(`postfx preserves grain ${grain} with heroless=${heroless}`, (t) => { |
| 95 | + const workspace = mkdtempSync(join(tmpdir(), "embedded-captions-grain-")); |
| 96 | + t.after(() => rmSync(workspace, { recursive: true, force: true })); |
| 97 | + const project = join(workspace, "project"); |
| 98 | + cpSync(fixturesDir, project, { recursive: true }); |
| 99 | + mkdirSync(join(workspace, "scripts")); |
| 100 | + mkdirSync(join(workspace, "themes")); |
| 101 | + const compiler = join(workspace, "scripts", "make-theme.cjs"); |
| 102 | + cpSync(makeTheme, compiler); |
| 103 | + const dna = JSON.parse(readFileSync(join(skillDir, "themes", "anchor.json"), "utf8")); |
| 104 | + dna.plate.grain = grain; |
| 105 | + writeFileSync(join(workspace, "themes", "anchor.json"), JSON.stringify(dna)); |
| 106 | + writeFileSync( |
| 107 | + join(project, "theme.json"), |
| 108 | + JSON.stringify({ |
| 109 | + ...fixtureTheme, |
| 110 | + dna: "anchor", |
| 111 | + ...(heroless |
| 112 | + ? {} |
| 113 | + : { |
| 114 | + hero: { match: "hero" }, |
| 115 | + lines: fixtureTheme.lines.map((line) => line.filter((word) => word !== "hero")), |
| 116 | + }), |
| 117 | + }), |
| 118 | + ); |
| 119 | + const result = spawnSync(process.execPath, [compiler, project], { |
| 120 | + encoding: "utf8", |
| 121 | + timeout: 10_000, |
| 122 | + }); |
| 123 | + assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`); |
| 124 | + const postfx = readFileSync(join(project, "_postfx.sh"), "utf8"); |
| 125 | + if (grain === 0) assert.doesNotMatch(postfx, /noise=/); |
| 126 | + else assert.match(postfx, new RegExp(`noise=alls=${grain ?? 5}:allf=t\\+u`)); |
| 127 | + assert.doesNotMatch(postfx, /,\s*\[v\]/); |
| 128 | + assert.match(postfx, heroless ? /\[0:v\]null/ : /zoompan=/); |
| 129 | + }); |
| 130 | + } |
| 131 | +} |
0 commit comments