34 lines
1.6 KiB
TypeScript
34 lines
1.6 KiB
TypeScript
import { afterAll, expect, test } from "bun:test";
|
|
import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { runBuild } from "../src/build.ts";
|
|
const scratch = join(import.meta.dir, ".tmp-client-dependency");
|
|
mkdirSync(scratch, { recursive: true });
|
|
afterAll(() => rmSync(scratch, { recursive: true, force: true }));
|
|
test("changing a bundled dependency changes the immutable client URL", async () => {
|
|
const root = mkdtempSync(join(scratch, "app-"));
|
|
mkdirSync(join(root, "app/pages"), { recursive: true });
|
|
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "client-cache-fixture" }));
|
|
writeFileSync(join(root, "wrnexus.config.ts"), "export default {};\n");
|
|
writeFileSync(
|
|
join(root, "app/pages/index.wrn"),
|
|
'import {message} from "../message.ts"\npage Home { functions { client function show(){alert(message)} } view { <button type="button" on:click={show()}>Show message</button> } }',
|
|
);
|
|
const files: string[] = [];
|
|
for (const message of ["first dependency", "updated dependency"]) {
|
|
writeFileSync(join(root, "app/message.ts"), `export const message=${JSON.stringify(message)};`);
|
|
await runBuild(root);
|
|
const file = readdirSync(join(root, "dist/client")).find(
|
|
(name) =>
|
|
name.startsWith("index-") &&
|
|
readFileSync(join(root, "dist/client", name), "utf8").includes(message),
|
|
);
|
|
expect(file).toBeDefined();
|
|
files.push(file!);
|
|
expect(readFileSync(join(root, "dist/server.js"), "utf8")).toContain(
|
|
`/__wrnexus/client/${file}`,
|
|
);
|
|
}
|
|
expect(files[0]).not.toBe(files[1]);
|
|
}, 120000);
|