Skip to content

Commit 36b0d4e

Browse files
committed
Update config manipulation test.
1 parent f950b51 commit 36b0d4e

6 files changed

Lines changed: 58 additions & 17 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "@solidjs/start/config";
2+
// Simulates an app config
3+
export default defineConfig({
4+
vite: {
5+
plugins: [solid()]
6+
}
7+
});

packages/commands/tests/assets/sample_unocss_result.txt renamed to packages/commands/tests/assets/sample_unocss_app_result.txt

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import UnoCss from "unocss/vite";
2+
import { defineConfig } from "vite";
3+
// Simulates an app config
4+
export default defineConfig({
5+
plugins: [
6+
solid(),
7+
UnoCss({})
8+
]
9+
});
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { defineConfig } from "@solidjs/start/config";
1+
import { defineConfig } from "vite";
22
// Simulates an app config
33
export default defineConfig({
4-
vite: {
5-
plugins: [solid()]
6-
}
4+
plugins: [solid()]
75
});

packages/commands/tests/config_manipulation.test.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ const readFile = async (path: string): Promise<string> => {
99
readFile1(path, (_, data) => res(data.toString())),
1010
);
1111
};
12+
1213
const removeWhitespace = (str: string) => str.replace(/\s/g, "");
14+
1315
vi.mock("fs/promises", () => {
1416
return {
1517
readFile: async (name: string) => {
1618
if (name === "app.config.ts") {
19+
const sampleConfig: string = await readFile("./packages/commands/tests/assets/sample_app_config.txt");
20+
return sampleConfig;
21+
}
22+
if (name === "vite.config.ts") {
1723
const sampleConfig: string = await readFile("./packages/commands/tests/assets/sample_vite_config.txt");
1824
return sampleConfig;
1925
}
26+
2027
return "{}";
2128
},
2229
writeFile: async (_, contents: string) => {
@@ -46,22 +53,41 @@ vi.mock("@solid-cli/utils/updates", async () => {
4653

4754
vi.mock("../src/lib/utils/helpers.ts", async () => {
4855
return {
49-
getConfigFile: async (): Promise<string> => new Promise((r) => r("app.config.ts")),
50-
fileExists: (path: string) => path.includes("app_config") || path.includes("app.tsx") || path.includes("index.tsx"),
56+
getConfigFile: async (file: string): Promise<string> => new Promise((r) => r(`${file}.config.ts`)),
57+
fileExists: (path: string) =>
58+
path.includes("vite_config") ||
59+
path.includes("app_config") ||
60+
path.includes("app.tsx") ||
61+
path.includes("index.tsx"),
5162
getRootFile: async (): Promise<string> => new Promise((r) => r("./src/app.tsx")),
5263
};
5364
});
65+
66+
let testingSolidStart = false;
67+
68+
vi.mock("@solid-cli/utils", async () => {
69+
return {
70+
isSolidStart: async () => new Promise((r) => r(testingSolidStart)),
71+
};
72+
});
73+
5474
describe("Update config", () => {
55-
it(
56-
"Adds a plugin properly to the config",
57-
async () => {
58-
await handleAdd(["unocss"]);
75+
it("Adds a plugin properly to the app config", { timeout: 50000 }, async () => {
76+
testingSolidStart = true;
77+
await handleAdd(["unocss"]);
5978

60-
const expected = await readFile("./packages/commands/tests/assets/sample_unocss_result.txt");
61-
// @ts-ignore
62-
const newConfig = UPDATESQUEUE.find((u) => u.name === "app.config.ts")?.contents;
63-
expect(removeWhitespace(expected)).toBe(removeWhitespace(newConfig));
64-
},
65-
{ timeout: 50000 },
66-
);
79+
const expected = await readFile("./packages/commands/tests/assets/sample_unocss_app_result.txt");
80+
// @ts-ignore
81+
const newConfig = UPDATESQUEUE.find((u) => u.name === "app.config.ts")?.contents;
82+
expect(removeWhitespace(newConfig)).toBe(removeWhitespace(expected));
83+
});
84+
it("Adds a plugin properly to the vite config", { timeout: 50000 }, async () => {
85+
testingSolidStart = false;
86+
await handleAdd(["unocss"]);
87+
88+
const expected = await readFile("./packages/commands/tests/assets/sample_unocss_vite_result.txt");
89+
// @ts-ignore
90+
const newConfig = UPDATESQUEUE.find((u) => u.name === "vite.config.ts")?.contents;
91+
expect(removeWhitespace(newConfig)).toBe(removeWhitespace(expected));
92+
});
6793
});

packages/utils/tests/plugin_transforms.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ plugins: []
122122

123123
test("Object method config is updated properly", async () => {
124124
const config: Config = {
125+
type: "app",
125126
name: "app.config.ts",
126127
contents: makeExampleConfig(["solid()"], [], "method"),
127128
};

0 commit comments

Comments
 (0)