1import { describe, expect, it } from "vitest";
2import { NODE_BUNDLE_CONDITIONS } from "../../core/NodeServe.ts";
3import type { NitroConfigSlice } from "../UserConfig.ts";
4import {
5 NITRO_HANDLER_SPECIFIER,
6 NITRO_PRESET,
7 makeNodeTarget,
8 target,
9} from "../node.ts";
10
11describe("makeNodeTarget", () => {
12 it("declares the node platform, the node nitro preset, and a finish pass", () => {
13 const node = makeNodeTarget();
14 expect(node.platform).toBe("node");
15 expect(node.nitroPreset).toBe(NITRO_PRESET);
16 expect(NITRO_PRESET).toBe("node");
17 expect(NITRO_PRESET).not.toBe("aws-lambda");
18 expect(NITRO_PRESET).not.toBe("cloudflare_module");
19 expect(node.bundle?.conditions).toEqual([...NODE_BUNDLE_CONDITIONS]);
20 expect(node.bundle?.external ?? []).not.toContain("cloudflare:");
21 expect(node.bundle?.external ?? []).not.toContain("@aws-sdk/");
22 expect(node.build).toBeTypeOf("function");
23 expect(node.finish).toBeTypeOf("function");
24 });
25
26 it("does not wire the user entry at the config level", () => {
27 const node = makeNodeTarget({ main: "./server-entry.ts" });
28 const config: NitroConfigSlice = {};
29 node.configureNitro?.(config, {
30 root: "/project",
31 entry: "/project/server-entry.ts",
32 });
33 expect(config.entry).toBeUndefined();
34 });
35
36 it("exports the node-listener handler specifier for user entries", () => {
37 expect(NITRO_HANDLER_SPECIFIER).toBe(
38 "nitropack/presets/node/runtime/node-listener",
39 );
40 });
41
42 it("exposes the named `target` module export as the factory", () => {
43 expect(target).toBe(makeNodeTarget);
44 });
45});