Skip to content

Commit

Permalink
test(cli): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslz committed Jan 28, 2024
1 parent becd299 commit 8813298
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
37 changes: 21 additions & 16 deletions packages/cli/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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[]);
});
3 changes: 1 addition & 2 deletions packages/cli/src/utils/hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down

0 comments on commit 8813298

Please sign in to comment.