sitegen/framework/incremental.test.ts
chloe caruso c5ac450f21 feat: dynamic page regeneration (#24)
the asset system is reworked to support "dynamic" entries, where each
entry is a separate file on disk containing the latest generation's
headers+raw+gzip+zstd. when calling view.regenerate, it will look for
pages that had "export const regenerate" during generation, and render
those pages using the view system, but then store the results as assets
instead of sending as a response.

pages configured as regenerable are also bundled as views, using the
non-aliasing key "page:${page.id}". this cannot alias because file
paths may not contain a colon.
2025-08-11 22:43:27 -07:00

56 lines
1.5 KiB
TypeScript

test("trivial case", async () => {
incr.reset();
const file1 = tmpFile("example.txt");
file1.write("one");
async function compilation() {
const first = incr.work({
label: "first compute",
async run(io) {
await setTimeout(1000);
const contents = await io.readFile(file1.path);
return [contents, Math.random()] as const;
},
});
const second = incr.work({
label: "second compute",
wait: first,
async run(io) {
await setTimeout(1000);
return io.readWork(first)[0].toUpperCase();
},
});
const third = incr.work({
label: "third compute",
wait: first,
async run(io) {
await setTimeout(1000);
return io.readWork(first)[1] * 1000;
},
});
return incr.work({
label: "last compute",
wait: [second, third],
async run(io) {
await setTimeout(1000);
return {
second: io.readWork(second),
third: io.readWork(third),
};
},
});
}
const { value: first } = await incr.compile(compilation);
const { value: second } = await incr.compile(compilation);
ASSERT(first === second);
incr.forceInvalidate(file1.path);
const { value: third } = await incr.compile(compilation);
ASSERT(first !== third);
ASSERT(first[0] === third[0]);
});
import * as incr from "./incremental2.ts";
import { beforeEach, test } from "node:test";
import { tmpFile } from "#sitegen/testing";
import { setTimeout } from "node:timers/promises";