(realPath: string | null)
| 8 | (typeof import("./installerDetection.js"))["detectInstaller"] extends () => infer R ? R : never; |
| 9 | |
| 10 | async function detectWith(realPath: string | null): Promise<InstallerInfo> { |
| 11 | vi.resetModules(); |
| 12 | const origArgv1 = process.argv[1]; |
| 13 | if (realPath === null) { |
| 14 | process.argv[1] = ""; |
| 15 | } else { |
| 16 | // argv[1] doesn't matter — realpathSync is what gets checked after the |
| 17 | // resolver runs. Set it to the unresolved form and stub fs.realpathSync |
| 18 | // to return the scenario's resolved path. |
| 19 | process.argv[1] = "/not/used/at/runtime"; |
| 20 | } |
| 21 | vi.doMock("node:fs", async () => { |
| 22 | const actual = await vi.importActual<typeof import("node:fs")>("node:fs"); |
| 23 | return { |
| 24 | ...actual, |
| 25 | realpathSync: |
| 26 | realPath === null |
| 27 | ? () => { |
| 28 | throw new Error("simulated unresolved path"); |
| 29 | } |
| 30 | : () => realPath, |
| 31 | }; |
| 32 | }); |
| 33 | |
| 34 | const mod = await import("./installerDetection.js"); |
| 35 | const info = mod.detectInstaller(); |
| 36 | process.argv[1] = origArgv1 ?? ""; |
| 37 | return info; |
| 38 | } |
| 39 | |
| 40 | describe("detectInstaller", () => { |
| 41 | afterEach(() => { |
no outgoing calls
no test coverage detected