fix(dev-server): invalidate WRN cache by content

This commit is contained in:
2026-07-20 16:07:38 +05:30
parent 54f5309fca
commit 45e6fd3cb9
2 changed files with 31 additions and 6 deletions
+22 -1
View File
@@ -1,5 +1,5 @@
import { expect, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { invalidateModule, loadModule, setCompileCacheDir } from "../src/pipeline.ts";
@@ -41,3 +41,24 @@ test("invalidateModule recompiles changed WRN files in-process", async () => {
rmSync(root, { recursive: true, force: true });
}
});
test("WRN cache follows content when a replacement has an older mtime", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-cache-"));
const file = join(root, "component.wrn");
setCompileCacheDir(join(root, ".wrnexus"));
try {
writeFileSync(file, "component Example { view { <p>Old</p> } }\n");
const first = (await loadModule(file)).render as () => unknown;
expect(String(first())).toContain("Old");
writeFileSync(file, "component Example { view { <p>Current</p> } }\n");
utimesSync(file, new Date(0), new Date(0));
invalidateModule(file);
const current = (await loadModule(file)).render as () => unknown;
expect(String(current())).toContain("Current");
} finally {
rmSync(root, { recursive: true, force: true });
}
});