run/src/run.test.ts
2021-09-12 18:24:09 +02:00

30 lines
987 B
TypeScript

import { Sys } from "../deps.ts";
import { describe, expect, it, mockfn } from "../deps.testing.ts";
import { Runner } from "./run.ts";
describe(Runner, () => {
it("works with a file timestamp", async () => {
async function check(stat: any, expected: boolean) {
const sys = {
stat: mockfn(() => stat),
writeTextFile: mockfn(),
};
const runner = new Runner(sys as typeof Sys);
const path = "/tmp/thunderk-run-run-test.stamp";
const result = await runner.checkStamp("run-test");
expect(result).toBe(expected);
expect(sys.stat).toHaveBeenLastCalledWith(path);
if (expected) {
expect(sys.writeTextFile).not.toHaveBeenCalled();
} else {
expect(sys.writeTextFile).toHaveBeenLastCalledWith(path, "");
}
}
await check({ isFile: false }, false);
await check({ isFile: true, mtime: new Date(2000, 1, 1) }, false);
await check({ isFile: true, mtime: new Date() }, true);
});
});