ui-thing 0.0.16 → 0.0.18

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,71 +1,71 @@
1
- import * as execa from "execa";
2
- import fse from "fs-extra";
3
- import { afterEach, describe, expect, it, vi } from "vitest";
4
- import type { PathLike } from "fs";
5
-
6
- import * as testingFn from "../../src/utils/addPrettierConfig";
7
-
8
- const currentDir = process.cwd();
9
-
10
- describe("utils/addPrettierConfig", () => {
11
- afterEach(() => {
12
- vi.restoreAllMocks();
13
- vi.resetAllMocks();
14
- });
15
-
16
- it("should ask the user if they want to overwrite the existing prettier config file if one exists", async () => {
17
- vi.spyOn(fse, "existsSync").mockImplementation((path: PathLike) => true);
18
- vi.mock("prompts", async () => {
19
- const prompts = await vi.importActual<typeof import("prompts")>("prompts");
20
- return {
21
- ...prompts,
22
- default: async () => {
23
- return { overwrite: false };
24
- },
25
- };
26
- });
27
- const prompts = await import("prompts");
28
- vi.spyOn(prompts, "default");
29
-
30
- const result = await testingFn.addPrettierConfig();
31
- expect(result).toBe(false);
32
- expect(fse.existsSync).toHaveBeenCalledTimes(1);
33
- expect(prompts.default).toHaveBeenCalledTimes(1);
34
- });
35
-
36
- it("should create config file if one does not exist", async () => {
37
- vi.spyOn(fse, "existsSync").mockImplementation(() => false);
38
- vi.spyOn(fse, "writeFile").mockResolvedValue();
39
-
40
- const result = await testingFn.addPrettierConfig(currentDir, false);
41
- expect(result).toBe(true);
42
- expect(fse.existsSync).toHaveBeenCalledTimes(1);
43
- expect(fse.writeFile).toHaveBeenCalledTimes(1);
44
- });
45
-
46
- it("should format files with prettier if format is true", async () => {
47
- vi.spyOn(testingFn, "addPrettierConfig");
48
- vi.spyOn(fse, "existsSync").mockImplementation(() => false);
49
- vi.spyOn(fse, "writeFile").mockResolvedValue();
50
- vi.mock("execa", async () => {
51
- const execa = await vi.importActual<typeof import("execa")>("execa");
52
- return {
53
- ...execa,
54
- $: async () => {
55
- return true;
56
- },
57
- default: async () => {
58
- return true;
59
- },
60
- };
61
- });
62
- vi.spyOn(execa, "$");
63
-
64
- const result = await testingFn.addPrettierConfig(currentDir, true);
65
- expect(result).toBe(true);
66
- expect(fse.existsSync).toHaveBeenCalledTimes(1);
67
- expect(fse.writeFile).toHaveBeenCalledTimes(1);
68
- expect(execa.$).toHaveBeenCalledTimes(1);
69
- expect(testingFn.addPrettierConfig).toHaveBeenCalledTimes(1);
70
- });
71
- });
1
+ import * as execa from "execa";
2
+ import fse from "fs-extra";
3
+ import { afterEach, describe, expect, it, vi } from "vitest";
4
+ import type { PathLike } from "fs";
5
+
6
+ import * as testingFn from "../../src/utils/addPrettierConfig";
7
+
8
+ const currentDir = process.cwd();
9
+
10
+ describe("utils/addPrettierConfig", () => {
11
+ afterEach(() => {
12
+ vi.restoreAllMocks();
13
+ vi.resetAllMocks();
14
+ });
15
+
16
+ it("should ask the user if they want to overwrite the existing prettier config file if one exists", async () => {
17
+ vi.spyOn(fse, "existsSync").mockImplementation((path: PathLike) => true);
18
+ vi.mock("prompts", async () => {
19
+ const prompts = await vi.importActual<typeof import("prompts")>("prompts");
20
+ return {
21
+ ...prompts,
22
+ default: async () => {
23
+ return { overwrite: false };
24
+ },
25
+ };
26
+ });
27
+ const prompts = await import("prompts");
28
+ vi.spyOn(prompts, "default");
29
+
30
+ const result = await testingFn.addPrettierConfig();
31
+ expect(result).toBe(false);
32
+ expect(fse.existsSync).toHaveBeenCalledTimes(1);
33
+ expect(prompts.default).toHaveBeenCalledTimes(1);
34
+ });
35
+
36
+ it("should create config file if one does not exist", async () => {
37
+ vi.spyOn(fse, "existsSync").mockImplementation(() => false);
38
+ vi.spyOn(fse, "writeFile").mockResolvedValue();
39
+
40
+ const result = await testingFn.addPrettierConfig(currentDir, false);
41
+ expect(result).toBe(true);
42
+ expect(fse.existsSync).toHaveBeenCalledTimes(1);
43
+ expect(fse.writeFile).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it("should format files with prettier if format is true", async () => {
47
+ vi.spyOn(testingFn, "addPrettierConfig");
48
+ vi.spyOn(fse, "existsSync").mockImplementation(() => false);
49
+ vi.spyOn(fse, "writeFile").mockResolvedValue();
50
+ vi.mock("execa", async () => {
51
+ const execa = await vi.importActual<typeof import("execa")>("execa");
52
+ return {
53
+ ...execa,
54
+ $: async () => {
55
+ return true;
56
+ },
57
+ default: async () => {
58
+ return true;
59
+ },
60
+ };
61
+ });
62
+ vi.spyOn(execa, "$");
63
+
64
+ const result = await testingFn.addPrettierConfig(currentDir, true);
65
+ expect(result).toBe(true);
66
+ expect(fse.existsSync).toHaveBeenCalledTimes(1);
67
+ expect(fse.writeFile).toHaveBeenCalledTimes(1);
68
+ expect(execa.$).toHaveBeenCalledTimes(1);
69
+ expect(testingFn.addPrettierConfig).toHaveBeenCalledTimes(1);
70
+ });
71
+ });
@@ -1,60 +1,60 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- import { UIConfig } from "../../src/types";
4
- import * as testingFn from "../../src/utils/compareUIConfig";
5
- import * as configModule from "../../src/utils/config";
6
-
7
- const goodConfig: UIConfig = {
8
- theme: "string",
9
- tailwindCSSLocation: "string",
10
- tailwindConfigLocation: "string",
11
- componentsLocation: "string",
12
- composablesLocation: "string",
13
- utilsLocation: "string",
14
- force: true,
15
- useDefaultFilename: true,
16
- packageManager: "string",
17
- };
18
-
19
- const badConfig = {
20
- theme: "string",
21
- tailwindCSSLocation: "string",
22
- tailwindConfigLocation: "string",
23
- utilsLocation: "string",
24
- force: true,
25
- };
26
-
27
- describe("utils/compareUIConfig", () => {
28
- afterEach(() => {
29
- vi.restoreAllMocks();
30
- vi.resetAllMocks();
31
- });
32
-
33
- it("should return false if properties are missing", async () => {
34
- // create spies
35
- vi.spyOn(configModule, "getUIConfig").mockResolvedValue(badConfig as UIConfig);
36
- vi.spyOn(testingFn, "compareUIConfig");
37
-
38
- // call the function we are testing
39
- const configValue = await testingFn.compareUIConfig();
40
-
41
- // assertions
42
- expect(configValue).toBe(false);
43
- expect(testingFn.compareUIConfig).toHaveBeenCalledTimes(1);
44
- expect(configModule.getUIConfig).toHaveBeenCalledTimes(1);
45
- });
46
-
47
- it("should return true if all properties are present", async () => {
48
- // create spies
49
- vi.spyOn(configModule, "getUIConfig").mockResolvedValue(goodConfig);
50
- vi.spyOn(testingFn, "compareUIConfig");
51
-
52
- // call the function we are testing
53
- const configValue = await testingFn.compareUIConfig();
54
-
55
- // assertions
56
- expect(configValue).toBe(true);
57
- expect(testingFn.compareUIConfig).toHaveBeenCalledTimes(1);
58
- expect(configModule.getUIConfig).toHaveBeenCalledTimes(1);
59
- });
60
- });
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { UIConfig } from "../../src/types";
4
+ import * as testingFn from "../../src/utils/compareUIConfig";
5
+ import * as configModule from "../../src/utils/config";
6
+
7
+ const goodConfig: UIConfig = {
8
+ theme: "string",
9
+ tailwindCSSLocation: "string",
10
+ tailwindConfigLocation: "string",
11
+ componentsLocation: "string",
12
+ composablesLocation: "string",
13
+ utilsLocation: "string",
14
+ force: true,
15
+ useDefaultFilename: true,
16
+ packageManager: "string",
17
+ };
18
+
19
+ const badConfig = {
20
+ theme: "string",
21
+ tailwindCSSLocation: "string",
22
+ tailwindConfigLocation: "string",
23
+ utilsLocation: "string",
24
+ force: true,
25
+ };
26
+
27
+ describe("utils/compareUIConfig", () => {
28
+ afterEach(() => {
29
+ vi.restoreAllMocks();
30
+ vi.resetAllMocks();
31
+ });
32
+
33
+ it("should return false if properties are missing", async () => {
34
+ // create spies
35
+ vi.spyOn(configModule, "getUIConfig").mockResolvedValue(badConfig as UIConfig);
36
+ vi.spyOn(testingFn, "compareUIConfig");
37
+
38
+ // call the function we are testing
39
+ const configValue = await testingFn.compareUIConfig();
40
+
41
+ // assertions
42
+ expect(configValue).toBe(false);
43
+ expect(testingFn.compareUIConfig).toHaveBeenCalledTimes(1);
44
+ expect(configModule.getUIConfig).toHaveBeenCalledTimes(1);
45
+ });
46
+
47
+ it("should return true if all properties are present", async () => {
48
+ // create spies
49
+ vi.spyOn(configModule, "getUIConfig").mockResolvedValue(goodConfig);
50
+ vi.spyOn(testingFn, "compareUIConfig");
51
+
52
+ // call the function we are testing
53
+ const configValue = await testingFn.compareUIConfig();
54
+
55
+ // assertions
56
+ expect(configValue).toBe(true);
57
+ expect(testingFn.compareUIConfig).toHaveBeenCalledTimes(1);
58
+ expect(configModule.getUIConfig).toHaveBeenCalledTimes(1);
59
+ });
60
+ });