pm-auto 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,7 @@
1
1
  import { describe, it, expect, vi, beforeEach } from "vitest";
2
2
  import * as fs from "fs";
3
3
  import * as os from "os";
4
- import {
5
- saveConfigPath,
6
- getConfigPath,
7
- clearConfigPath,
8
- } from "../src/config_path.js";
4
+ import { saveConfigPath, getConfigPath } from "../src/config_path.js";
9
5
  import * as display from "../src/display.js";
10
6
 
11
7
  const mocks = vi.hoisted(() => {
@@ -121,22 +117,4 @@ describe("Config Path Management", () => {
121
117
  expect(result).toBe("");
122
118
  });
123
119
  });
124
-
125
- describe("clearConfigPath", () => {
126
- it("deletes settings file if exists", () => {
127
- vi.mocked(fs.existsSync).mockReturnValue(true);
128
-
129
- clearConfigPath();
130
-
131
- expect(fs.unlinkSync).toHaveBeenCalledWith(mockSettingsFile);
132
- });
133
-
134
- it("does nothing if file does not exist", () => {
135
- vi.mocked(fs.existsSync).mockReturnValue(false);
136
-
137
- clearConfigPath();
138
-
139
- expect(fs.unlinkSync).not.toHaveBeenCalled();
140
- });
141
- });
142
120
  });
@@ -0,0 +1,91 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { display, s } from "../src/display.js";
3
+ import { log, spinner } from "@clack/prompts";
4
+ import chalk from "chalk";
5
+
6
+ // Mock dependencies
7
+ vi.mock("@clack/prompts", () => ({
8
+ log: {
9
+ error: vi.fn(),
10
+ success: vi.fn(),
11
+ warn: vi.fn(),
12
+ info: vi.fn(),
13
+ message: vi.fn(),
14
+ },
15
+ spinner: vi.fn(() => ({
16
+ start: vi.fn(),
17
+ stop: vi.fn(),
18
+ })),
19
+ }));
20
+
21
+ vi.mock("chalk", () => ({
22
+ default: {
23
+ red: vi.fn((text) => `red:${text}`),
24
+ green: vi.fn((text) => `green:${text}`),
25
+ yellow: vi.fn((text) => `yellow:${text}`),
26
+ blue: vi.fn((text) => `blue:${text}`),
27
+ },
28
+ }));
29
+
30
+ describe("display function", () => {
31
+ let processExitSpy: any;
32
+
33
+ beforeEach(() => {
34
+ vi.clearAllMocks();
35
+ processExitSpy = vi
36
+ .spyOn(process, "exit")
37
+ .mockImplementation(() => ({}) as never);
38
+ });
39
+
40
+ afterEach(() => {
41
+ processExitSpy.mockRestore();
42
+ });
43
+
44
+ it("should display error message and exit process", () => {
45
+ display("Error occurred", "error");
46
+
47
+ expect(chalk.red).toHaveBeenCalledWith("Error occurred");
48
+ expect(log.error).toHaveBeenCalledWith("red:Error occurred");
49
+ expect(processExitSpy).toHaveBeenCalledWith(0);
50
+ });
51
+
52
+ it("should display success message", () => {
53
+ display("Operation successful", "success");
54
+
55
+ expect(chalk.green).toHaveBeenCalledWith("Operation successful");
56
+ expect(log.success).toHaveBeenCalledWith("green:Operation successful");
57
+ });
58
+
59
+ it("should display warning message", () => {
60
+ display("Warning message", "warning");
61
+
62
+ expect(chalk.yellow).toHaveBeenCalledWith("Warning message");
63
+ expect(log.warn).toHaveBeenCalledWith("yellow:Warning message");
64
+ });
65
+
66
+ it("should display info message", () => {
67
+ display("Info message", "info");
68
+
69
+ expect(chalk.blue).toHaveBeenCalledWith("Info message");
70
+ expect(log.info).toHaveBeenCalledWith("blue:Info message");
71
+ });
72
+
73
+ it("should start spinner for loading type", () => {
74
+ const result = display("Loading...", "loading");
75
+
76
+ expect(s.start).toHaveBeenCalledWith("Loading...");
77
+ expect(result).toBe(s);
78
+ });
79
+
80
+ it("should display default message for empty type", () => {
81
+ display("Default message", "");
82
+
83
+ expect(log.message).toHaveBeenCalledWith("Default message");
84
+ });
85
+
86
+ it("should display default message for unrecognized type", () => {
87
+ display("Random message", "unknown" as any);
88
+
89
+ expect(log.message).toHaveBeenCalledWith("Random message");
90
+ });
91
+ });
@@ -26,10 +26,6 @@ describe("install", () => {
26
26
 
27
27
  await install(commands);
28
28
 
29
- expect(display.stopSpinner).toHaveBeenCalledWith(
30
- "Starting interactive command...",
31
- 0,
32
- );
33
29
  expect(execa).toHaveBeenCalledWith("npm", ["init"], { stdio: "inherit" });
34
30
  expect(display.display).toHaveBeenCalledWith(expect.any(String), "info");
35
31
  });
@@ -73,7 +69,6 @@ describe("install", () => {
73
69
  expect(execa).toHaveBeenNthCalledWith(2, "npm", ["install"], {
74
70
  stdio: "inherit",
75
71
  });
76
- expect(display.stopSpinner).toHaveBeenCalled();
77
72
  });
78
73
 
79
74
  it("handles multiple interactive commands sequentially", async () => {