|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { describe, it } from "node:test"; |
| 3 | +import { createRun402Adapter } from "./ssr-adapter.js"; |
| 4 | + |
| 5 | +type CapturedAdapter = { |
| 6 | + name?: string; |
| 7 | + entrypointResolution?: unknown; |
| 8 | + serverEntrypoint?: unknown; |
| 9 | + exports?: unknown; |
| 10 | + adapterFeatures?: { buildOutput?: unknown } & Record<string, unknown>; |
| 11 | + supportedAstroFeatures?: Record<string, unknown>; |
| 12 | +}; |
| 13 | + |
| 14 | +function runConfigDone(integration: ReturnType<typeof createRun402Adapter>): CapturedAdapter { |
| 15 | + const captured: { adapter?: CapturedAdapter } = {}; |
| 16 | + const fakeOutDir = new URL("file:///tmp/run402-astro-test/dist/"); |
| 17 | + const hook = integration.hooks["astro:config:done"]; |
| 18 | + if (!hook) throw new Error("expected astro:config:done hook"); |
| 19 | + (hook as (params: unknown) => unknown)({ |
| 20 | + setAdapter: (a: CapturedAdapter) => { |
| 21 | + captured.adapter = a; |
| 22 | + }, |
| 23 | + config: { outDir: fakeOutDir }, |
| 24 | + logger: { info() {}, warn() {}, error() {} }, |
| 25 | + setRoutes() {}, |
| 26 | + }); |
| 27 | + if (!captured.adapter) throw new Error("setAdapter was not called"); |
| 28 | + return captured.adapter; |
| 29 | +} |
| 30 | + |
| 31 | +describe("createRun402Adapter — Astro 6 shape (kychee-com/run402#403)", () => { |
| 32 | + it("declares entrypointResolution: 'auto'", () => { |
| 33 | + const adapter = runConfigDone(createRun402Adapter()); |
| 34 | + assert.equal( |
| 35 | + adapter.entrypointResolution, |
| 36 | + "auto", |
| 37 | + "must opt into Astro 6 auto resolution; explicit is deprecated and prints a warning on every build", |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it("does not pass deprecated `exports` field", () => { |
| 42 | + const adapter = runConfigDone(createRun402Adapter()); |
| 43 | + assert.equal( |
| 44 | + adapter.exports, |
| 45 | + undefined, |
| 46 | + "the `exports` array is only used by the deprecated explicit mode; auto mode reads exports from the runtime module directly", |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it("does not force adapterFeatures.buildOutput", () => { |
| 51 | + const adapter = runConfigDone(createRun402Adapter()); |
| 52 | + assert.equal( |
| 53 | + adapter.adapterFeatures?.buildOutput, |
| 54 | + undefined, |
| 55 | + "leave buildOutput unset so Astro derives it from output + per-page prerender", |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it("declares sharpImageService so default-sharp users don't get an [ERROR]", () => { |
| 60 | + const adapter = runConfigDone(createRun402Adapter()); |
| 61 | + assert.equal( |
| 62 | + adapter.supportedAstroFeatures?.sharpImageService, |
| 63 | + "stable", |
| 64 | + "Astro 6 will print '[config] adapter does not currently support sharp' otherwise", |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + it("declares static + server + hybrid output support", () => { |
| 69 | + const adapter = runConfigDone(createRun402Adapter()); |
| 70 | + const feats = adapter.supportedAstroFeatures ?? {}; |
| 71 | + assert.equal(feats.staticOutput, "stable"); |
| 72 | + assert.equal(feats.serverOutput, "stable"); |
| 73 | + assert.equal(feats.hybridOutput, "stable"); |
| 74 | + }); |
| 75 | + |
| 76 | + it("points serverEntrypoint at the runtime export", () => { |
| 77 | + const adapter = runConfigDone(createRun402Adapter()); |
| 78 | + assert.equal(adapter.serverEntrypoint, "@run402/astro/runtime/server"); |
| 79 | + }); |
| 80 | +}); |
0 commit comments