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 * as NodeServices from "@effect/platform-node/NodeServices"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FileSystem from "effect/FileSystem"; |
| 4 | import * as Path from "effect/Path"; |
| 5 | import type * as Scope from "effect/Scope"; |
| 6 | import { describe, expect, it } from "vitest"; |
| 7 | import { NODE_BUNDLE_CONDITIONS, NODE_SERVE_ENTRY_FILE_NAME } from "../../core/NodeServe.ts"; |
| 8 | import { NITRO_HANDLER_SPECIFIER, NITRO_PRESET, makeNodeTarget, target } from "../node.ts"; |
| 9 | import type { NitroConfigSlice } from "../UserConfig.ts"; |
| 10 | |
| 11 | const runWithNode = <A, E>( |
| 12 | effect: Effect.Effect<A, E, FileSystem.FileSystem | Path.Path | Scope.Scope>, |
| 13 | ): Promise<A> => |
| 14 | Effect.runPromise( |
| 15 | Effect.scoped(effect).pipe(Effect.provide(NodeServices.layer)) as Effect.Effect<A, E>, |
| 16 | ); |
| 17 | |
| 18 | describe("makeNodeTarget", () => { |
| 19 | it("declares the node platform, the node nitro preset, and a finish pass", () => { |
| 20 | const node = makeNodeTarget(); |
| 21 | expect(node.platform).toBe("node"); |
| 22 | expect(node.nitroPreset).toBe(NITRO_PRESET); |
| 23 | expect(NITRO_PRESET).toBe("node"); |
| 24 | expect(NITRO_PRESET).not.toBe("aws-lambda"); |
| 25 | expect(NITRO_PRESET).not.toBe("cloudflare_module"); |
| 26 | expect(node.bundle?.conditions).toEqual([...NODE_BUNDLE_CONDITIONS]); |
| 27 | expect(node.bundle?.external ?? []).not.toContain("cloudflare:"); |
| 28 | expect(node.bundle?.external ?? []).not.toContain("@aws-sdk/"); |
| 29 | expect(node.build).toBeTypeOf("function"); |
| 30 | expect(node.finish).toBeTypeOf("function"); |
| 31 | }); |
| 32 | |
| 33 | it("does not wire aws-lambda streaming on the nitro config", () => { |
| 34 | const node = makeNodeTarget(); |
| 35 | const config: NitroConfigSlice = {}; |
| 36 | node.configureNitro?.(config, { root: "/project" }); |
| 37 | expect(config.awsLambda).toBeUndefined(); |
| 38 | expect(config.preset).toBeUndefined(); |
| 39 | }); |
| 40 | |
| 41 | it("exports the node-listener handler specifier for user entries", () => { |
| 42 | expect(NITRO_HANDLER_SPECIFIER).toBe("nitropack/presets/node/runtime/node-listener"); |
| 43 | expect(NITRO_HANDLER_SPECIFIER).not.toContain("aws-lambda"); |
| 44 | }); |
| 45 | |
| 46 | it("exposes the named `target` module export as the factory", () => { |
| 47 | expect(target).toBe(makeNodeTarget); |
| 48 | }); |
| 49 | }); |
| 50 | |
| 51 | describe("finish", () => { |
| 52 | it("wraps nitro's node-listener handler, not the aws-lambda handler", async () => { |
| 53 | const output = await runWithNode( |
| 54 | Effect.gen(function* () { |
| 55 | const fs = yield* FileSystem.FileSystem; |
| 56 | const path = yield* Path.Path; |
| 57 | const dir = yield* fs.makeTempDirectoryScoped({ |
| 58 | prefix: "solidstart-node-finish-", |
| 59 | }); |
| 60 | const serverDir = path.join(dir, "server"); |
| 61 | const publicDir = path.join(dir, "public"); |
| 62 | yield* fs.makeDirectory(serverDir, { recursive: true }); |
| 63 | yield* fs.makeDirectory(publicDir, { recursive: true }); |
| 64 | yield* fs.writeFileString( |
| 65 | path.join(serverDir, "index.mjs"), |
| 66 | "export const handler = () => {};", |
| 67 | ); |
| 68 | const node = makeNodeTarget(); |
| 69 | return yield* node.finish!( |
| 70 | { |
| 71 | distDirectory: dir, |
| 72 | clientDirectory: publicDir, |
| 73 | serverModules: [], |
| 74 | externalWorkspaces: new Set<string>(), |
| 75 | }, |
| 76 | { root: dir, framework: "solidstart" }, |
| 77 | ); |
| 78 | }), |
| 79 | ); |
| 80 | expect(output.serverModules?.[0]?.name).toBe(`server/${NODE_SERVE_ENTRY_FILE_NAME}`); |
| 81 | const source = String(output.serverModules?.[0]?.content); |
| 82 | expect(source).toContain("/health"); |
| 83 | expect(source).toContain("process.env.PORT"); |
| 84 | expect(source).toContain(`import { handler } from "./index.mjs"`); |
| 85 | expect(source).not.toContain("aws-lambda"); |
| 86 | expect(source).not.toContain("streamifyResponse"); |
| 87 | expect(source).not.toContain("workerd"); |
| 88 | }); |
| 89 | }); |