From 858d0e5640d447d6a41f6e50c895cee2b4a5939f Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 6 Nov 2024 14:14:18 +0000 Subject: [PATCH] fix tests, and add one more case --- packages/astro/e2e/actions-blog.test.js | 14 +++++++++++++- .../e2e/fixtures/actions-blog/astro.config.mjs | 2 +- .../e2e/fixtures/actions-blog/src/middleware.ts | 2 +- .../e2e/fixtures/actions-blog/src/pages/sum.astro | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro diff --git a/packages/astro/e2e/actions-blog.test.js b/packages/astro/e2e/actions-blog.test.js index a8d9a7fc67b93..231cd49f67080 100644 --- a/packages/astro/e2e/actions-blog.test.js +++ b/packages/astro/e2e/actions-blog.test.js @@ -155,7 +155,7 @@ test.describe('Astro Actions - Blog', () => { await expect(page).toHaveURL(astro.resolveUrl('/blog/')); }); - test('Should redirect to the origin pathname when there is a rewrite', async ({ + test('Should redirect to the origin pathname when there is a rewrite from an Astro page', async ({ page, astro, }) => { @@ -166,4 +166,16 @@ test.describe('Astro Actions - Blog', () => { const p = page.locator('p').nth(0); await expect(p).toContainText('Form result: {"data":3}'); }); + + test('Should redirect to the origin pathname when there is a rewrite from the middleware', async ({ + page, + astro, + }) => { + await page.goto(astro.resolveUrl('/second-sum')); + const submitButton = page.getByTestId('submit'); + await submitButton.click(); + await expect(page).toHaveURL(astro.resolveUrl('/second-sum')); + const p = page.locator('p').nth(0); + await expect(p).toContainText('Form result: {"data":3}'); + }); }); diff --git a/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs b/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs index 35f7481f230e6..c00c4da70df2b 100644 --- a/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs +++ b/packages/astro/e2e/fixtures/actions-blog/astro.config.mjs @@ -7,7 +7,7 @@ import node from '@astrojs/node'; export default defineConfig({ site: 'https://example.com', integrations: [db(), react()], - output: 'static', + output: 'server', adapter: node({ mode: 'standalone', }), diff --git a/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts b/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts index 53bb8235ac2af..26d9fd811486e 100644 --- a/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts +++ b/packages/astro/e2e/fixtures/actions-blog/src/middleware.ts @@ -1,7 +1,7 @@ import { defineMiddleware } from "astro:middleware"; export const onRequest = defineMiddleware((ctx, next) => { - if (ctx.request.method === "GET" && ctx.url.pathname === "/sum") { + if (ctx.request.method === "GET" && ctx.url.pathname === "/second-sum") { return next("/rewritten") } diff --git a/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro b/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro new file mode 100644 index 0000000000000..ef00a5e66162c --- /dev/null +++ b/packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro @@ -0,0 +1,3 @@ +--- +return Astro.rewrite('/rewritten' + Astro.url.search) +---