@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 86 lines 2.94 KB
Raw
1 import { describe, expect, it } from "vitest";
2 import { fromHarnessOptions, resolveExportTarget } from "../index.ts";
3
4 describe("fromHarnessOptions", () => {
5 it("maps the shared vite options onto SvelteKit options", () => {
6 const bindings = ["text-binding-hook"];
7 const options = fromHarnessOptions({
8 vite: {
9 compatibilityDate: "2026-03-10",
10 compatibilityFlags: ["nodejs_compat"],
11 worker: {
12 bindings,
13 assets: { notFoundHandling: "404-page" },
14 },
15 },
16 });
17 expect(options.compatibilityDate).toBe("2026-03-10");
18 expect(options.compatibilityFlags).toEqual(["nodejs_compat"]);
19 expect(options.adapter?.notFoundHandling).toBe("404-page");
20 // binding hooks pass through wholesale — the deploy target's dev
21 // platform serves them (resource bindings included)
22 expect(options.dev?.bindings).toBe(bindings);
23 });
24
25 it("prefers the target-scoped carriage over the deprecated vite alias", () => {
26 const scoped = ["scoped-binding-hook"];
27 const options = fromHarnessOptions({
28 target: {
29 cloudflare: {
30 worker: {
31 compatibilityDate: "2026-03-10",
32 worker: {
33 bindings: scoped,
34 assets: { notFoundHandling: "single-page-application" },
35 },
36 },
37 },
38 },
39 vite: {
40 compatibilityDate: "1999-01-01",
41 worker: { assets: { notFoundHandling: "none" } },
42 },
43 });
44 expect(options.compatibilityDate).toBe("2026-03-10");
45 expect(options.adapter?.notFoundHandling).toBe("single-page-application");
46 expect(options.dev?.bindings).toBe(scoped);
47 });
48
49 it("falls back to the deprecated vite alias when no target is scoped", () => {
50 const options = fromHarnessOptions({
51 vite: { compatibilityDate: "2026-03-10" },
52 });
53 expect(options.compatibilityDate).toBe("2026-03-10");
54 });
55
56 it("tolerates fully-empty options", () => {
57 const options = fromHarnessOptions({});
58 expect(options.compatibilityDate).toBeUndefined();
59 expect(options.dev?.bindings).toBeUndefined();
60 });
61 });
62
63 describe("resolveExportTarget", () => {
64 it("accepts a plain string target", () => {
65 expect(resolveExportTarget("./src/exports/vite/index.js")).toBe("./src/exports/vite/index.js");
66 });
67
68 it("picks the import condition (kit's ESM-only ./vite export)", () => {
69 expect(
70 resolveExportTarget({
71 types: "./types/index.d.ts",
72 import: "./src/exports/vite/index.js",
73 }),
74 ).toBe("./src/exports/vite/index.js");
75 });
76
77 it("falls back to default and resolves nested conditions", () => {
78 expect(resolveExportTarget({ default: { import: "./dist/index.js" } })).toBe("./dist/index.js");
79 });
80
81 it("returns undefined for unusable entries", () => {
82 expect(resolveExportTarget(undefined)).toBeUndefined();
83 expect(resolveExportTarget({ types: "./types/index.d.ts" })).toBeUndefined();
84 expect(resolveExportTarget(null)).toBeUndefined();
85 });
86 });