Skip to content

Commit

Permalink
fix tests, and add one more case
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 6, 2024
1 parent 047e6de commit 858d0e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
14 changes: 13 additions & 1 deletion packages/astro/e2e/actions-blog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) => {
Expand All @@ -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}');
});
});
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/actions-blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/actions-blog/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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")
}

Expand Down
3 changes: 3 additions & 0 deletions packages/astro/e2e/fixtures/actions-blog/src/pages/sum.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
return Astro.rewrite('/rewritten' + Astro.url.search)
---

0 comments on commit 858d0e5

Please sign in to comment.