feature: add ability to drop a .spa.static into the tree

This commit is contained in:
Andy Burke 2026-01-15 20:33:26 -08:00
parent 75439172c9
commit d07991bc60
6 changed files with 175 additions and 70 deletions

View file

@ -1,26 +1,29 @@
import * as asserts from '@std/assert';
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from './helpers.ts';
import * as asserts from "@std/assert";
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from "./helpers.ts";
Deno.test({
name: 'check that .spa files work',
name: "check that .spa files work",
permissions: {
env: true,
read: true,
write: true,
net: true
net: true,
},
fn: async () => {
let test_server_info: EPHEMERAL_SERVER | null = null;
const cwd = Deno.cwd();
try {
Deno.chdir('./tests/www/spa');
Deno.chdir("./tests/www/spa");
test_server_info = await get_ephemeral_listen_server();
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/foo/bar/baz`, {
method: 'GET'
});
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/foo/bar/baz`,
{
method: "GET",
},
);
const body = await response.text();
@ -31,9 +34,12 @@ Deno.test({
}
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/testing`, {
method: 'GET'
});
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/testing`,
{
method: "GET",
},
);
const body = await response.text();
@ -43,9 +49,12 @@ Deno.test({
}
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/testing/blah.html`, {
method: 'GET'
});
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/testing/blah.html`,
{
method: "GET",
},
);
const body = await response.text();
@ -59,5 +68,75 @@ Deno.test({
await test_server_info?.server?.stop();
}
}
}
},
});
Deno.test({
name: "check that .spa.static 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/spa");
test_server_info = await get_ephemeral_listen_server();
{
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/foo/bar/baz`,
{
method: "GET",
},
);
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /SPA PAGE/s);
asserts.assertMatch(body, /test include/s);
}
{
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/possibly_missing/here.html`,
{
method: "GET",
},
);
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /here/s);
}
{
const response = await fetch(
`http://${test_server_info.hostname}:${test_server_info.port}/possibly_missing/missing.html`,
{
method: "GET",
},
);
const body = await response.text();
asserts.assert(!response.ok);
asserts.assert(body);
asserts.assertEquals(response.status, 404);
}
} finally {
Deno.chdir(cwd);
if (test_server_info) {
await test_server_info?.server?.stop();
}
}
},
});

View file

@ -0,0 +1,6 @@
<!doctype html>
<html>
<body>
<h1>here</h1>
</body>
</html>