Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions packages/astro/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,58 @@ it('Works with adapter and all pages prerendered', async () => {
await devServer.stop();
});

describe('Astro Actions with adapter and all project pages prerendered', () => {
it('exposes action RPC routes in dev', async () => {
const fixture = await loadFixture({
root: './fixtures/actions-all-prerendered/',
adapter: testAdapter(),
});
const devServer = await fixture.startDevServer();
assert.ok(devServer, 'Expected dev server to start');

try {
const res = await fixture.fetch('/_actions/ping', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: 'hello' }),
});

assert.equal(res.ok, true);
assert.equal(res.headers.get('Content-Type'), 'application/json+devalue');

const data = devalue.parse(await res.text());
assert.equal(data.message, 'hello');
} finally {
await devServer.stop();
}
});

it('builds server output and exposes action RPC routes', async () => {
const fixture = await loadFixture({
root: './fixtures/actions-all-prerendered/',
adapter: testAdapter(),
});
await fixture.build();
const app = await fixture.loadTestAdapterApp();
const req = new Request('http://example.com/_actions/ping', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: 'hello' }),
});
const res = await app.render(req);

assert.equal(res.ok, true);
assert.equal(res.headers.get('Content-Type'), 'application/json+devalue');

const data = devalue.parse(await res.text());
assert.equal(data.message, 'hello');
});
});

it('Base path should be used', async () => {
const fixture = await loadFixture({
root: './fixtures/actions/',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'astro/config';

export default defineConfig({
output: 'server',
security: {
checkOrigin: false,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/actions-all-prerendered",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineAction } from 'astro:actions';
import { z } from 'astro/zod';

export const server = {
ping: defineAction({
input: z.object({
message: z.string(),
}),
handler: async ({ message }) => {
return { message };
},
}),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender = true;
---

<p>All project pages are prerendered.</p>
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading