| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { |
| 3 | makeAwsTarget, |
| 4 | NITRO_HANDLER_SPECIFIER, |
| 5 | NITRO_PRESET, |
| 6 | } from "../aws.ts"; |
| 7 | import type { NitroConfigSlice } from "../UserConfig.ts"; |
| 8 | |
| 9 | describe("makeAwsTarget", () => { |
| 10 | it("declares the aws platform, the nitro preset, and node bundle settings", () => { |
| 11 | const target = makeAwsTarget(); |
| 12 | expect(target.platform).toBe("aws"); |
| 13 | expect(target.nitroPreset).toBe(NITRO_PRESET); |
| 14 | expect(target.bundle?.conditions).toEqual(["node", "import", "module"]); |
| 15 | expect(target.bundle?.external).toEqual(["@aws-sdk/"]); |
| 16 | // Nitro's aws-lambda output is already a complete Node deployment unit. |
| 17 | expect(target.finish).toBeUndefined(); |
| 18 | }); |
| 19 | |
| 20 | it("runs the build in a disposable child process", () => { |
| 21 | expect(typeof makeAwsTarget().build).toBe("function"); |
| 22 | }); |
| 23 | |
| 24 | it("enables response streaming by default", () => { |
| 25 | const config: NitroConfigSlice = {}; |
| 26 | makeAwsTarget().configureNitro?.(config, { root: "/project" }); |
| 27 | expect(config.awsLambda).toEqual({ streaming: true }); |
| 28 | }); |
| 29 | |
| 30 | it("honors an explicit streaming opt-out (buffered handler)", () => { |
| 31 | const config: NitroConfigSlice = {}; |
| 32 | makeAwsTarget({ streaming: false }).configureNitro?.(config, { |
| 33 | root: "/project", |
| 34 | }); |
| 35 | expect(config.awsLambda).toEqual({ streaming: false }); |
| 36 | }); |
| 37 | |
| 38 | it("preserves foreign awsLambda keys while overriding the owned one", () => { |
| 39 | const config: NitroConfigSlice = { |
| 40 | awsLambda: { streaming: false, someOtherKey: 1 }, |
| 41 | }; |
| 42 | makeAwsTarget().configureNitro?.(config, { root: "/project" }); |
| 43 | expect(config.awsLambda).toEqual({ streaming: true, someOtherKey: 1 }); |
| 44 | }); |
| 45 | |
| 46 | it("carries the caller's nitro overrides on the target config", () => { |
| 47 | const target = makeAwsTarget({ nitro: { prerender: { routes: ["/"] } } }); |
| 48 | expect(target.config.nitro).toEqual({ prerender: { routes: ["/"] } }); |
| 49 | }); |
| 50 | |
| 51 | it("exports the wrappable-handler specifier for custom entries", () => { |
| 52 | expect(NITRO_HANDLER_SPECIFIER).toBe( |
| 53 | "nitropack/presets/aws-lambda/runtime/aws-lambda-streaming", |
| 54 | ); |
| 55 | }); |
| 56 | }); |