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
| 1 | import { expect, layer } from "@alchemy.run/test"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as FileSystem from "effect/FileSystem"; |
| 5 | import * as Path from "effect/Path"; |
| 6 | import * as Bundle from "@/Bundle/Bundle"; |
| 7 | |
| 8 | layer(NodeServices.layer)("Bundle.build default text module types", (it) => { |
| 9 | it.effect( |
| 10 | "inlines a bare .sql import as a string default export", |
| 11 | () => |
| 12 | Effect.gen(function* () { |
| 13 | const fs = yield* FileSystem.FileSystem; |
| 14 | const path = yield* Path.Path; |
| 15 | const root = yield* fs.makeTempDirectory({ prefix: "alchemy-sql-module-" }); |
| 16 | yield* fs.writeFileString( |
| 17 | path.join(root, "0000_init.sql"), |
| 18 | "CREATE TABLE sql_module_marker (id integer primary key);", |
| 19 | ); |
| 20 | const entry = path.join(root, "entry.ts"); |
| 21 | yield* fs.writeFileString( |
| 22 | entry, |
| 23 | `import m0000 from "./0000_init.sql";\nconsole.log(m0000);\n`, |
| 24 | ); |
| 25 | |
| 26 | const result = yield* Bundle.build({ input: entry, cwd: root }); |
| 27 | |
| 28 | const code = result.files |
| 29 | .filter((f) => typeof f.content === "string") |
| 30 | .map((f) => f.content as string) |
| 31 | .join("\n"); |
| 32 | expect(code).toContain("CREATE TABLE sql_module_marker"); |
| 33 | // Inlined into the chunk, not emitted as a separate asset. |
| 34 | expect(result.files.every((f) => !f.path.endsWith(".sql"))).toBe(true); |
| 35 | |
| 36 | yield* fs.remove(root, { recursive: true }); |
| 37 | }), |
| 38 | { tags: ["unit", "local"] }, |
| 39 | ); |
| 40 | |
| 41 | it.effect( |
| 42 | "bundles a drizzle-kit durable-sqlite migrations layout", |
| 43 | () => |
| 44 | Effect.gen(function* () { |
| 45 | const fs = yield* FileSystem.FileSystem; |
| 46 | const path = yield* Path.Path; |
| 47 | const root = yield* fs.makeTempDirectory({ prefix: "alchemy-drizzle-migrations-" }); |
| 48 | // Mirror `drizzle-kit generate` output for `driver: "durable-sqlite"`: |
| 49 | // migrations.js imports each .sql migration and the meta journal. |
| 50 | yield* fs.makeDirectory(path.join(root, "drizzle", "meta"), { recursive: true }); |
| 51 | yield* fs.writeFileString( |
| 52 | path.join(root, "drizzle", "0000_cool_migration.sql"), |
| 53 | "CREATE TABLE drizzle_do_marker (id integer primary key, name text);", |
| 54 | ); |
| 55 | yield* fs.writeFileString( |
| 56 | path.join(root, "drizzle", "meta", "_journal.json"), |
| 57 | JSON.stringify({ |
| 58 | version: "7", |
| 59 | dialect: "sqlite", |
| 60 | entries: [ |
| 61 | { idx: 0, version: "6", when: 1, tag: "0000_cool_migration", breakpoints: true }, |
| 62 | ], |
| 63 | }), |
| 64 | ); |
| 65 | yield* fs.writeFileString( |
| 66 | path.join(root, "drizzle", "migrations.js"), |
| 67 | [ |
| 68 | `import journal from './meta/_journal.json';`, |
| 69 | `import m0000 from './0000_cool_migration.sql';`, |
| 70 | `export default { journal, migrations: { m0000 } };`, |
| 71 | ].join("\n"), |
| 72 | ); |
| 73 | const entry = path.join(root, "entry.ts"); |
| 74 | yield* fs.writeFileString( |
| 75 | entry, |
| 76 | `import migrations from "./drizzle/migrations.js";\nconsole.log(migrations);\n`, |
| 77 | ); |
| 78 | |
| 79 | const result = yield* Bundle.build({ input: entry, cwd: root }); |
| 80 | |
| 81 | const code = result.files |
| 82 | .filter((f) => typeof f.content === "string") |
| 83 | .map((f) => f.content as string) |
| 84 | .join("\n"); |
| 85 | expect(code).toContain("CREATE TABLE drizzle_do_marker"); |
| 86 | expect(code).toContain("0000_cool_migration"); |
| 87 | |
| 88 | yield* fs.remove(root, { recursive: true }); |
| 89 | }), |
| 90 | { tags: ["unit", "local"] }, |
| 91 | ); |
| 92 | |
| 93 | it.effect( |
| 94 | "inlines bare .txt and .html imports as strings", |
| 95 | () => |
| 96 | Effect.gen(function* () { |
| 97 | const fs = yield* FileSystem.FileSystem; |
| 98 | const path = yield* Path.Path; |
| 99 | const root = yield* fs.makeTempDirectory({ prefix: "alchemy-text-module-" }); |
| 100 | yield* fs.writeFileString(path.join(root, "note.txt"), "TXT_MODULE_MARKER"); |
| 101 | yield* fs.writeFileString(path.join(root, "page.html"), "<h1>HTML_MODULE_MARKER</h1>"); |
| 102 | const entry = path.join(root, "entry.ts"); |
| 103 | yield* fs.writeFileString( |
| 104 | entry, |
| 105 | [ |
| 106 | `import note from "./note.txt";`, |
| 107 | `import page from "./page.html";`, |
| 108 | `console.log(note, page);`, |
| 109 | ].join("\n"), |
| 110 | ); |
| 111 | |
| 112 | const result = yield* Bundle.build({ input: entry, cwd: root }); |
| 113 | |
| 114 | const code = result.files |
| 115 | .filter((f) => typeof f.content === "string") |
| 116 | .map((f) => f.content as string) |
| 117 | .join("\n"); |
| 118 | expect(code).toContain("TXT_MODULE_MARKER"); |
| 119 | expect(code).toContain("HTML_MODULE_MARKER"); |
| 120 | |
| 121 | yield* fs.remove(root, { recursive: true }); |
| 122 | }), |
| 123 | { tags: ["unit", "local"] }, |
| 124 | ); |
| 125 | |
| 126 | it.effect( |
| 127 | "caller-provided moduleTypes override the defaults", |
| 128 | () => |
| 129 | Effect.gen(function* () { |
| 130 | const fs = yield* FileSystem.FileSystem; |
| 131 | const path = yield* Path.Path; |
| 132 | const root = yield* fs.makeTempDirectory({ prefix: "alchemy-module-override-" }); |
| 133 | yield* fs.writeFileString(path.join(root, "data.sql"), "OVERRIDE_MARKER"); |
| 134 | const entry = path.join(root, "entry.ts"); |
| 135 | yield* fs.writeFileString(entry, `import data from "./data.sql";\nconsole.log(data);\n`); |
| 136 | |
| 137 | const result = yield* Bundle.build({ |
| 138 | input: entry, |
| 139 | cwd: root, |
| 140 | moduleTypes: { ".sql": "base64" }, |
| 141 | }); |
| 142 | |
| 143 | const code = result.files |
| 144 | .filter((f) => typeof f.content === "string") |
| 145 | .map((f) => f.content as string) |
| 146 | .join("\n"); |
| 147 | expect(code).not.toContain("OVERRIDE_MARKER"); |
| 148 | expect(code).toContain(Buffer.from("OVERRIDE_MARKER").toString("base64")); |
| 149 | |
| 150 | yield* fs.remove(root, { recursive: true }); |
| 151 | }), |
| 152 | { tags: ["unit", "local"] }, |
| 153 | ); |
| 154 | }); |