From ae8bca661a1bed5c5bf5f6ffce929a4ec4a55a11 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Tue, 10 Oct 2023 20:21:58 +0000 Subject: [PATCH] add test --- .../test/fixtures/locals/src/middleware.ts | 6 ++++++ .../test/fixtures/locals/src/pages/api.js | 4 ++-- ...{foo.astro => from-astro-middleware.astro} | 0 .../src/pages/from-node-middleware.astro | 4 ++++ .../integrations/node/test/locals.test.js | 20 ++++++++++++++++--- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 packages/integrations/node/test/fixtures/locals/src/middleware.ts rename packages/integrations/node/test/fixtures/locals/src/pages/{foo.astro => from-astro-middleware.astro} (100%) create mode 100644 packages/integrations/node/test/fixtures/locals/src/pages/from-node-middleware.astro diff --git a/packages/integrations/node/test/fixtures/locals/src/middleware.ts b/packages/integrations/node/test/fixtures/locals/src/middleware.ts new file mode 100644 index 000000000..e349ca41d --- /dev/null +++ b/packages/integrations/node/test/fixtures/locals/src/middleware.ts @@ -0,0 +1,6 @@ +import { defineMiddleware } from 'astro:middleware'; + +export const onRequest = defineMiddleware(({ url, locals }, next) => { + if (url.pathname === "/from-astro-middleware") locals.foo = "baz"; + return next(); +}) diff --git a/packages/integrations/node/test/fixtures/locals/src/pages/api.js b/packages/integrations/node/test/fixtures/locals/src/pages/api.js index 8b209c582..3c279e37b 100644 --- a/packages/integrations/node/test/fixtures/locals/src/pages/api.js +++ b/packages/integrations/node/test/fixtures/locals/src/pages/api.js @@ -1,6 +1,6 @@ -export async function post({ locals }) { - let out = { ...locals }; +export async function POST({ locals }) { + const out = { ...locals }; return new Response(JSON.stringify(out), { headers: { diff --git a/packages/integrations/node/test/fixtures/locals/src/pages/foo.astro b/packages/integrations/node/test/fixtures/locals/src/pages/from-astro-middleware.astro similarity index 100% rename from packages/integrations/node/test/fixtures/locals/src/pages/foo.astro rename to packages/integrations/node/test/fixtures/locals/src/pages/from-astro-middleware.astro diff --git a/packages/integrations/node/test/fixtures/locals/src/pages/from-node-middleware.astro b/packages/integrations/node/test/fixtures/locals/src/pages/from-node-middleware.astro new file mode 100644 index 000000000..224a875ec --- /dev/null +++ b/packages/integrations/node/test/fixtures/locals/src/pages/from-node-middleware.astro @@ -0,0 +1,4 @@ +--- +const { foo } = Astro.locals; +--- +