Add unit test

This commit is contained in:
Michaël Lemaire 2021-09-12 18:24:09 +02:00
parent a2894d48b9
commit a0a0c579cc
3 changed files with 37 additions and 0 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
deno.d.ts
.vscode
.local
.output
web/*.js

6
deps.testing.ts Normal file
View file

@ -0,0 +1,6 @@
export {
describe,
expect,
it,
mockfn,
} from "https://js.thunderk.net/testing@1.0.0/mod.ts";

View file

@ -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);
});
});