Add unit test

This commit is contained in:
Michaël Lemaire 2021-09-07 00:13:56 +02:00
parent 6a39521a07
commit a214d1cb86
2 changed files with 34 additions and 0 deletions

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,28 @@
import { ProjectNormalizer } from "./normalize.ts";
import { describe, expect, it, mockfn } from "../deps.testing.ts";
describe(ProjectNormalizer, () => {
it("uses 'deno fmt' to format path", async () => {
const sys = {
run: mockfn(() => ({
async status() {
return { success: true };
},
async output() {
return new TextEncoder().encode("");
},
async stderrOutput() {
return new TextEncoder().encode("");
},
})),
} as typeof Deno;
const normalizer = new ProjectNormalizer(sys);
await normalizer.formatPath("dist/test.js");
expect(sys.run).toHaveBeenCalledTimes(1);
expect(sys.run).toHaveBeenCalledWith({
cmd: ["./run", "fmt", "-q", "dist/test.js"],
stdout: "piped",
stderr: "piped",
});
});
});