| 1 | import { isDeployTarget } from "../../core/index.ts"; |
| 2 | import { NODE_BUNDLE_CONDITIONS } from "../../core/NodeServe.ts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as NodePath from "node:path"; |
| 5 | import { describe, expect, it } from "vitest"; |
| 6 | import { makeNodeTarget, target } from "../node.ts"; |
| 7 | |
| 8 | const context = { |
| 9 | root: "/project", |
| 10 | wakuDirectory: "/project/node_modules/waku", |
| 11 | phase: "build" as const, |
| 12 | }; |
| 13 | |
| 14 | describe("makeNodeTarget", () => { |
| 15 | it("declares the node platform, empty vite plugins, and a finish pass", async () => { |
| 16 | const node = makeNodeTarget(); |
| 17 | expect(isDeployTarget(node)).toBe(true); |
| 18 | expect(node.platform).toBe("node"); |
| 19 | expect(node.bundle?.conditions).toEqual([...NODE_BUNDLE_CONDITIONS]); |
| 20 | expect(node.bundle?.external ?? []).not.toContain("cloudflare:"); |
| 21 | expect(node.build).toBeTypeOf("function"); |
| 22 | expect(node.finish).toBeTypeOf("function"); |
| 23 | const plugins = await Effect.runPromise(node.vitePlugins(context)); |
| 24 | expect(plugins).toEqual([]); |
| 25 | }); |
| 26 | |
| 27 | it("selects waku's node adapter from the project's waku package", async () => { |
| 28 | const node = makeNodeTarget(); |
| 29 | const adapter = await Effect.runPromise(node.adapter(context)); |
| 30 | expect(adapter).toBe( |
| 31 | NodePath.join(context.wakuDirectory, "dist/adapters/node.js"), |
| 32 | ); |
| 33 | expect(adapter).not.toContain("aws-adapter"); |
| 34 | expect(adapter).not.toContain("cloudflare"); |
| 35 | }); |
| 36 | |
| 37 | it("exposes the named `target` module export as the factory", () => { |
| 38 | expect(target).toBe(makeNodeTarget); |
| 39 | }); |
| 40 | }); |