diff --git a/.gitignore b/.gitignore index d69a4c0..8b7abdc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ deno.d.ts .vscode .local +.output +web/*.js diff --git a/deps.testing.ts b/deps.testing.ts new file mode 100644 index 0000000..878ad92 --- /dev/null +++ b/deps.testing.ts @@ -0,0 +1,6 @@ +export { + describe, + expect, + it, + mockfn, +} from "https://js.thunderk.net/testing@1.0.0/mod.ts"; diff --git a/src/run.test.ts b/src/run.test.ts index e69de29..8b11f66 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -0,0 +1,29 @@ +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); + }); +});