forked from heygen-com/hyperframes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog-drift.test.ts
More file actions
35 lines (32 loc) · 1.42 KB
/
Copy pathcatalog-drift.test.ts
File metadata and controls
35 lines (32 loc) · 1.42 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
import assert from "node:assert/strict";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { test } from "node:test";
import { treeDifferences } from "./catalog-drift.ts";
function tree(files: Record<string, string>): string {
const root = mkdtempSync(join(tmpdir(), "catalog-drift-test-"));
for (const [name, text] of Object.entries(files)) {
mkdirSync(join(root, name, ".."), { recursive: true });
writeFileSync(join(root, name), text);
}
return root;
}
test("identical trees have no differences", () => {
const generated = tree({ "blocks/a.json": "{}", "vendor/x.json": "1" });
const committed = tree({ "blocks/a.json": "{}", "vendor/x.json": "1" });
assert.deepEqual(treeDifferences(generated, committed), []);
rmSync(generated, { recursive: true });
rmSync(committed, { recursive: true });
});
test("a stale payload, a missing file and a leftover file each turn the check red", () => {
const generated = tree({ "blocks/a.json": '{"v":2}', "blocks/new.json": "{}" });
const committed = tree({ "blocks/a.json": '{"v":1}', "blocks/gone.json": "{}" });
assert.deepEqual(treeDifferences(generated, committed), [
"not committed: blocks/new.json",
"no longer generated: blocks/gone.json",
"stale: blocks/a.json",
]);
rmSync(generated, { recursive: true });
rmSync(committed, { recursive: true });
});