1import { describe, expect, it } from "vitest";
2import { NODE_BUNDLE_CONDITIONS } from "../../core/NodeServe.ts";
3import {
4 SERVER_ENTRYPOINT,
5 distilledNode,
6 makeNodeTarget,
7 target,
8} from "../node.ts";
9
10describe("makeNodeTarget", () => {
11 it("declares the node platform, Node bundle conditions, and a finish pass", () => {
12 const node = makeNodeTarget();
13 expect(node.platform).toBe("node");
14 expect(node.bundle?.conditions).toEqual([...NODE_BUNDLE_CONDITIONS]);
15 expect(node.bundle?.external ?? []).not.toContain("cloudflare:");
16 expect(node.bundle?.external ?? []).not.toContain("@aws-sdk/");
17 expect(node.build).toBeTypeOf("function");
18 expect(node.finish).toBeTypeOf("function");
19 expect(node.integration).toBeTypeOf("function");
20 });
21
22 it("pins the node-server entrypoint (not the aws-lambda wrapper)", () => {
23 expect(SERVER_ENTRYPOINT).toBe(
24 "@alchemy.run/frontend-frameworks/astro/entrypoints/node-server",
25 );
26 expect(SERVER_ENTRYPOINT).not.toContain("aws-server");
27 });
28
29 it("rejects a user-declared adapter at astro:config:done", () => {
30 const integration = distilledNode();
31 const setup = integration.hooks["astro:config:setup"];
32 expect(setup).toBeTypeOf("function");
33 const done = integration.hooks["astro:config:done"];
34 expect(done).toBeTypeOf("function");
35 expect(() =>
36 (done as (ctx: never) => void)({
37 setAdapter: () => {},
38 config: {
39 adapter: { name: "@astrojs/node" },
40 build: { serverEntry: "entry.mjs" },
41 },
42 buildOutput: "server",
43 } as never),
44 ).toThrow(/already provides the Node adapter/);
45 });
46
47 it("exposes the named `target` module export as the factory", () => {
48 expect(target).toBe(makeNodeTarget);
49 });
50});