feature: support .spa files for Single Page Apps

This commit is contained in:
Andy Burke 2025-11-20 16:44:49 -08:00
parent 604090d8b8
commit 9fc91f4cf4
11 changed files with 329 additions and 8 deletions

62
tests/11_test_spa.test.ts Normal file
View file

@ -0,0 +1,62 @@
import * as asserts from '@std/assert';
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from './helpers.ts';
Deno.test({
name: 'check that .spa files work',
permissions: {
env: true,
read: true,
write: true,
net: true
},
fn: async () => {
let test_server_info: EPHEMERAL_SERVER | null = null;
const cwd = Deno.cwd();
try {
Deno.chdir('./tests/www');
test_server_info = await get_ephemeral_listen_server();
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/foo/bar/baz`, {
method: 'GET'
});
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /SPA PAGE/s);
}
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/testing`, {
method: 'GET'
});
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /Hello World - Testing/s);
}
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/testing/blah.html`, {
method: 'GET'
});
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /Hello World - Blah/s);
}
} finally {
Deno.chdir(cwd);
if (test_server_info) {
await test_server_info?.server?.stop();
}
}
}
});