ui-thing 0.0.6 → 0.0.8

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.
@@ -0,0 +1,34 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import * as testingFn from "../../src/templates/css";
4
+
5
+ describe("templates/css", () => {
6
+ afterEach(() => {
7
+ vi.restoreAllMocks();
8
+ vi.resetAllMocks();
9
+ });
10
+
11
+ it("should return ZINC theme if an invalid theme is passed", async () => {
12
+ // create spies
13
+ vi.spyOn(testingFn, "createCSS");
14
+
15
+ // call function
16
+ const result = testingFn.createCSS("BAD_THEME" as any);
17
+
18
+ // assertions
19
+ expect(result).toContain(testingFn.ZINC_THEME);
20
+ expect(testingFn.createCSS).toHaveBeenCalledTimes(1);
21
+ });
22
+
23
+ it("should returned the expected theme", async () => {
24
+ // create spies
25
+ vi.spyOn(testingFn, "createCSS");
26
+
27
+ // call function
28
+ const result = testingFn.createCSS("BLUE");
29
+
30
+ // assertions
31
+ expect(result).toContain(testingFn.BLUE_THEME);
32
+ expect(testingFn.createCSS).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
@@ -1,45 +1,39 @@
1
+ import * as execa from "execa";
1
2
  import fse from "fs-extra";
2
- import * as prompts from "prompts";
3
- import * as execa from "execa";
4
- import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
3
+ import { afterEach, describe, expect, it, vi } from "vitest";
4
+ import type { PathLike } from "fs";
5
5
 
6
6
  import * as testingFn from "../../src/utils/addPrettierConfig";
7
7
 
8
8
  const currentDir = process.cwd();
9
- const question = "A prettier config file already exists. Overwrite?";
10
- const promptOptions = {
11
- name: "overwrite",
12
- type: "confirm",
13
- message: question,
14
- initial: true,
15
- };
16
9
 
17
10
  describe("utils/addPrettierConfig", () => {
18
11
  afterEach(() => {
19
12
  vi.restoreAllMocks();
13
+ vi.resetAllMocks();
20
14
  });
21
15
 
22
- it(
23
- "should ask the user if they want to overwrite the existing prettier config file if one exists",
24
- async () => {
25
- vi.spyOn(fse, "existsSync").mockImplementation(() => true);
26
- vi.mock('prompts', async () => {
27
- const prompts = await import('prompts');
28
- return {
29
- ...prompts,
30
- default: async () => {
31
- return { overwrite: false };
32
- }
33
- }
34
- });
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");
35
29
 
36
- const result = await testingFn.addPrettierConfig();
37
- expect(result).toBe(false);
38
- expect(fse.existsSync).toHaveBeenCalledTimes(1);
39
- }
40
- );
30
+ const result = await testingFn.addPrettierConfig();
31
+ expect(result).toBe(false);
32
+ expect(fse.existsSync).toHaveBeenCalledTimes(1);
33
+ expect(prompts.default).toHaveBeenCalledTimes(1);
34
+ });
41
35
 
42
- it('should create config file if one does not exist', async () => {
36
+ it("should create config file if one does not exist", async () => {
43
37
  vi.spyOn(fse, "existsSync").mockImplementation(() => false);
44
38
  vi.spyOn(fse, "writeFile").mockResolvedValue();
45
39
 
@@ -47,25 +41,25 @@ describe("utils/addPrettierConfig", () => {
47
41
  expect(result).toBe(true);
48
42
  expect(fse.existsSync).toHaveBeenCalledTimes(1);
49
43
  expect(fse.writeFile).toHaveBeenCalledTimes(1);
50
- })
44
+ });
51
45
 
52
- it('should format files with prettier if format is true', async () => {
53
- vi.spyOn(execa, '$')
54
- vi.spyOn(testingFn, 'addPrettierConfig')
46
+ it("should format files with prettier if format is true", async () => {
47
+ vi.spyOn(testingFn, "addPrettierConfig");
55
48
  vi.spyOn(fse, "existsSync").mockImplementation(() => false);
56
49
  vi.spyOn(fse, "writeFile").mockResolvedValue();
57
- vi.mock('execa', async () => {
58
- const execa = await import('execa');
50
+ vi.mock("execa", async () => {
51
+ const execa = await vi.importActual<typeof import("execa")>("execa");
59
52
  return {
60
53
  ...execa,
61
- '$': async () => {
62
- return true
54
+ $: async () => {
55
+ return true;
63
56
  },
64
57
  default: async () => {
65
- return true
66
- }
67
- }
58
+ return true;
59
+ },
60
+ };
68
61
  });
62
+ vi.spyOn(execa, "$");
69
63
 
70
64
  const result = await testingFn.addPrettierConfig(currentDir, true);
71
65
  expect(result).toBe(true);
@@ -73,6 +67,5 @@ describe("utils/addPrettierConfig", () => {
73
67
  expect(fse.writeFile).toHaveBeenCalledTimes(1);
74
68
  expect(execa.$).toHaveBeenCalledTimes(1);
75
69
  expect(testingFn.addPrettierConfig).toHaveBeenCalledTimes(1);
76
-
77
- })
70
+ });
78
71
  });
@@ -0,0 +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
+ });