-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdiff.test.mjs
More file actions
63 lines (57 loc) · 2.21 KB
/
diff.test.mjs
File metadata and controls
63 lines (57 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import assert from "node:assert/strict";
import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { after, describe, it } from "node:test";
import { fileURLToPath } from "node:url";
import { spawnCli } from "./helpers/spawn-cli.mjs";
const __dirname = dirname(fileURLToPath(import.meta.url));
const FIXTURE = join(__dirname, "draft_content.json");
describe("diff", () => {
function pair() {
const dir = mkdtempSync(join(tmpdir(), "capcut-diff-"));
copyFileSync(FIXTURE, join(dir, "A.json"));
copyFileSync(FIXTURE, join(dir, "B.json"));
return {
dir,
a: join(dir, "A.json"),
b: join(dir, "B.json"),
cleanup: () => rmSync(dir, { recursive: true, force: true }),
};
}
it("reports no change for identical drafts", () => {
const p = pair();
after(p.cleanup);
const r = spawnCli(["diff", p.a, p.b]);
assert.equal(r.status, 0, `stderr: ${r.stderr}`);
assert.equal(r.json.changed, false);
});
it("detects a text edit as a changed material", () => {
const p = pair();
after(p.cleanup);
const id = spawnCli(["texts", p.b]).json[0].id;
spawnCli(["set-text", p.b, id, "EDITED", "-q"]);
const r = spawnCli(["diff", p.a, p.b]);
assert.equal(r.json.changed, true);
assert.equal(r.json.materials.changed.length, 1);
});
it("detects a segment timing change", () => {
const p = pair();
after(p.cleanup);
const seg = spawnCli(["segments", p.b]).json[0];
spawnCli(["shift", p.b, seg.id, "+1s", "-q"]);
const r = spawnCli(["diff", p.a, p.b]);
const changed = r.json.segments.changed.find((c) => seg.id.startsWith(c.id) || c.id === seg.id);
assert.ok(changed, "the shifted segment should appear in segments.changed");
assert.ok(changed.fields.includes("start"));
});
it("detects an added material", () => {
const p = pair();
after(p.cleanup);
const d = JSON.parse(readFileSync(p.b, "utf-8"));
d.materials.texts.push({ id: "NEW_MAT" });
writeFileSync(p.b, JSON.stringify(d, null, 2));
const r = spawnCli(["diff", p.a, p.b]);
assert.ok(r.json.materials.added.includes("NEW_MAT"));
});
});