diff --git a/packages/cli/global-setup.ts b/packages/cli/global-setup.ts index ba44f3d..2913a81 100644 --- a/packages/cli/global-setup.ts +++ b/packages/cli/global-setup.ts @@ -4,28 +4,24 @@ import shell from "shelljs"; import { beforeEach, vi } from "vitest"; vi.mock("fs"); -vi.mock("fs/promises"); vi.mock("consola"); vi.mock("shelljs"); -vi.mock("path", () => ({ - default: { - resolve: () => "/root/path", - }, -})); - beforeEach(() => { vi.resetAllMocks(); vi.clearAllMocks(); vi.resetModules(); - vi.spyOn(crypto, "randomUUID") - .mockImplementationOnce(() => "48d1a85c-377a-40ef-8a82-d1405f7a074f") - .mockImplementationOnce(() => "da406b35-79b8-4909-9af1-07cfdcf37d00") - .mockImplementationOnce(() => "39b9ad76-115f-47b3-a73d-7c3297eb4351"); + vi.mock("path", async (importOriginal) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const actual: any = await importOriginal(); - vi.spyOn(shell, "exit").mockImplementation(() => { - throw new Error(); + return { + default: { + ...actual.default, + resolve: () => "/root/path", + }, + }; }); vi.mock("@dimaslz/local-ssl-management-core", () => { @@ -35,9 +31,18 @@ beforeEach(() => { }; }); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - vi.spyOn(fs, "readdirSync").mockImplementationOnce((): any[] => [ + vi.spyOn(crypto, "randomUUID") + .mockImplementationOnce(() => "48d1a85c-377a-40ef-8a82-d1405f7a074f") + .mockImplementationOnce(() => "da406b35-79b8-4909-9af1-07cfdcf37d00") + .mockImplementationOnce(() => "39b9ad76-115f-47b3-a73d-7c3297eb4351"); + + vi.spyOn(shell, "exit").mockImplementation(() => { + throw new Error(); + }); + + vi.spyOn(fs, "readdirSync").mockReturnValue([ "some-domain.com-cert.pem", "some-domain.com-key.pem", - ]); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ] as any[]); }); diff --git a/packages/cli/src/utils/hosts.ts b/packages/cli/src/utils/hosts.ts index a0f4e98..d990c70 100644 --- a/packages/cli/src/utils/hosts.ts +++ b/packages/cli/src/utils/hosts.ts @@ -3,8 +3,7 @@ import fs from "fs"; import path from "path"; import { HOSTS_END, HOSTS_START } from "@/constants"; - -import { updateSystemHosts } from "./update-system-hosts"; +import { updateSystemHosts } from "@/utils"; const distPath = path.resolve(__dirname, "./"); const tmpHostsPath = `${distPath}/.tmp-hosts`;