import { describe, it } from "@std/testing/bdd"; import { assertEquals } from "@std/assert"; import { assertSpyCall, assertSpyCalls, returnsNext, stub, } from "@std/testing/mock"; // IMPORTANT: Delay the import of `gitDir` to after the stub let gitDir: typeof import("./index.ts").gitDir; describe("gitDir", () => { it("resolves with trimmed decoded stdout", async () => { const encoded = new TextEncoder().encode( " /home/user/project \n", ) as Uint8Array; const fakeOutput = Promise.resolve({ success: true, code: 0, stdout: encoded, stderr: new Uint8Array(), signal: null, }); using outputStub = stub( Deno.Command.prototype, "output", returnsNext([fakeOutput]), ); // Now import gitDir AFTER stubbing ({ gitDir } = await import("./index.ts")); const result = await gitDir(); assertEquals(result.pathname, "/home/user/project"); assertSpyCall(outputStub, 0, { args: [], returned: fakeOutput }); assertSpyCalls(outputStub, 1); }); });