2025-08-02 17:31:58 -07:00
|
|
|
test("trivial case", async () => {
|
|
|
|
incr.reset();
|
|
|
|
|
|
|
|
const file1 = tmpFile("example.txt");
|
|
|
|
file1.write("one");
|
|
|
|
|
|
|
|
async function compilation() {
|
|
|
|
const first = incr.work({
|
|
|
|
label: "first compute",
|
2025-08-11 22:43:27 -07:00
|
|
|
async run(io) {
|
2025-08-02 17:31:58 -07:00
|
|
|
await setTimeout(1000);
|
|
|
|
const contents = await io.readFile(file1.path);
|
|
|
|
return [contents, Math.random()] as const;
|
2025-08-11 22:43:27 -07:00
|
|
|
},
|
2025-08-02 17:31:58 -07:00
|
|
|
});
|
|
|
|
const second = incr.work({
|
|
|
|
label: "second compute",
|
|
|
|
wait: first,
|
2025-08-11 22:43:27 -07:00
|
|
|
async run(io) {
|
2025-08-02 17:31:58 -07:00
|
|
|
await setTimeout(1000);
|
|
|
|
return io.readWork(first)[0].toUpperCase();
|
2025-08-11 22:43:27 -07:00
|
|
|
},
|
2025-08-02 17:31:58 -07:00
|
|
|
});
|
|
|
|
const third = incr.work({
|
|
|
|
label: "third compute",
|
|
|
|
wait: first,
|
2025-08-11 22:43:27 -07:00
|
|
|
async run(io) {
|
2025-08-02 17:31:58 -07:00
|
|
|
await setTimeout(1000);
|
|
|
|
return io.readWork(first)[1] * 1000;
|
2025-08-11 22:43:27 -07:00
|
|
|
},
|
2025-08-02 17:31:58 -07:00
|
|
|
});
|
|
|
|
return incr.work({
|
|
|
|
label: "last compute",
|
|
|
|
wait: [second, third],
|
2025-08-11 22:43:27 -07:00
|
|
|
async run(io) {
|
2025-08-02 17:31:58 -07:00
|
|
|
await setTimeout(1000);
|
|
|
|
return {
|
|
|
|
second: io.readWork(second),
|
|
|
|
third: io.readWork(third),
|
2025-08-11 22:43:27 -07:00
|
|
|
};
|
|
|
|
},
|
2025-08-02 17:31:58 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
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";
|
2025-08-11 22:43:27 -07:00
|
|
|
import { tmpFile } from "#sitegen/testing";
|
|
|
|
import { setTimeout } from "node:timers/promises";
|