ui-thing 0.0.7 → 0.0.9
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.
- package/CHANGELOG.md +86 -57
- package/dist/index.d.ts +0 -0
- package/dist/index.js +4016 -3839
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/commands/add.ts +285 -285
- package/src/comp.ts +2287 -2261
- package/tests/templates/css.test.ts +34 -0
- package/tests/utils/addPrettierConfig.test.ts +71 -71
- package/tests/utils/compareUIConfig.test.ts +60 -0
|
@@ -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,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
|
+
});
|
|
@@ -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
|
+
});
|