@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 119 lines 3.9 KB
Raw
1 import { describe, expect, it } from "vitest";
2 import {
3 findPresetConflict,
4 hasForeignNitroPlugin,
5 isSamePreset,
6 markInjectedPlugins,
7 NITRO_PLUGIN_NAME,
8 normalizePresetName,
9 resolveNitroConfig,
10 resolveNitroOutputDirs,
11 type NitroConfigSlice,
12 } from "../UserConfig.ts";
13
14 const resolve = (...segments: Array<string>): string =>
15 segments.reduce((acc, segment) => (segment.startsWith("/") ? segment : `${acc}/${segment}`));
16
17 describe("normalizePresetName / isSamePreset", () => {
18 it("treats kebab, snake, and camel spellings as the same preset", () => {
19 expect(normalizePresetName("awsLambda")).toBe("aws-lambda");
20 expect(normalizePresetName("aws_lambda")).toBe("aws-lambda");
21 expect(isSamePreset("aws-lambda", "awsLambda")).toBe(true);
22 expect(isSamePreset("aws-lambda", "node-server")).toBe(false);
23 });
24 });
25
26 describe("findPresetConflict", () => {
27 it("returns undefined when no preset is given or it matches the target", () => {
28 expect(findPresetConflict(undefined, "aws-lambda")).toBeUndefined();
29 expect(findPresetConflict({}, "aws-lambda")).toBeUndefined();
30 expect(findPresetConflict({ preset: "aws_lambda" }, "aws-lambda")).toBeUndefined();
31 });
32
33 it("surfaces a foreign preset so the build can fail actionably", () => {
34 expect(findPresetConflict({ preset: "netlify" }, "aws-lambda")).toBe("netlify");
35 });
36 });
37
38 describe("resolveNitroConfig", () => {
39 it("enforces the target's preset and rootDir over the caller's overrides", () => {
40 const config = resolveNitroConfig({
41 preset: "aws-lambda",
42 rootDir: "/project",
43 nitro: {
44 preset: "node-server",
45 rootDir: "/elsewhere",
46 prerender: { crawlLinks: true },
47 },
48 });
49 expect(config.preset).toBe("aws-lambda");
50 expect(config.rootDir).toBe("/project");
51 expect(config.buildDir).toBe("/project/.nitro");
52 // Everything the integration does not own is preserved.
53 expect(config["prerender"]).toEqual({ crawlLinks: true });
54 });
55
56 it("runs the target's configure pass after the preset is enforced", () => {
57 const config = resolveNitroConfig({
58 preset: "aws-lambda",
59 rootDir: "/project",
60 nitro: { awsLambda: { foo: 1 } },
61 configure: (nitroConfig: NitroConfigSlice) => {
62 nitroConfig.awsLambda = {
63 ...(nitroConfig.awsLambda as Record<string, unknown>),
64 streaming: true,
65 };
66 },
67 });
68 expect(config.awsLambda).toEqual({ foo: 1, streaming: true });
69 });
70 });
71
72 describe("resolveNitroOutputDirs", () => {
73 it("mirrors nitro's defaults", () => {
74 expect(resolveNitroOutputDirs({}, "/project", resolve)).toEqual({
75 dir: "/project/.output",
76 serverDir: "/project/.output/server",
77 publicDir: "/project/.output/public",
78 });
79 });
80
81 it("honors an output override on the nitro config", () => {
82 expect(
83 resolveNitroOutputDirs(
84 { output: { dir: "build", serverDir: "fn", publicDir: "static" } },
85 "/project",
86 resolve,
87 ),
88 ).toEqual({
89 dir: "/project/build",
90 serverDir: "/project/build/fn",
91 publicDir: "/project/build/static",
92 });
93 });
94 });
95
96 describe("hasForeignNitroPlugin", () => {
97 it("ignores the plugin instances this integration created", () => {
98 const injected = markInjectedPlugins([
99 { name: "alchemy:solidstart-nitro-conflict" },
100 [{ name: NITRO_PLUGIN_NAME }, false],
101 ]);
102 expect(hasForeignNitroPlugin(injected)).toBe(false);
103 });
104
105 it("detects a project-registered nitro plugin, however nested", () => {
106 const injected = markInjectedPlugins([{ name: NITRO_PLUGIN_NAME }]);
107 expect(
108 hasForeignNitroPlugin([
109 [{ name: "solid-start:config" }, [{ name: NITRO_PLUGIN_NAME }]],
110 injected,
111 ]),
112 ).toBe(true);
113 });
114
115 it("tolerates falsy and non-plugin entries", () => {
116 expect(hasForeignNitroPlugin([false, null, undefined, "x"])).toBe(false);
117 expect(hasForeignNitroPlugin(undefined)).toBe(false);
118 });
119 });