2026-01-15 20:33:26 -08:00
|
|
|
import * as asserts from "@std/assert";
|
|
|
|
|
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from "./helpers.ts";
|
2025-11-20 16:44:49 -08:00
|
|
|
|
|
|
|
|
Deno.test({
|
2026-01-15 20:33:26 -08:00
|
|
|
name: "check that .spa files work",
|
2025-11-20 16:44:49 -08:00
|
|
|
permissions: {
|
|
|
|
|
env: true,
|
|
|
|
|
read: true,
|
|
|
|
|
write: true,
|
2026-01-15 20:33:26 -08:00
|
|
|
net: true,
|
2025-11-20 16:44:49 -08:00
|
|
|
},
|
|
|
|
|
fn: async () => {
|
|
|
|
|
let test_server_info: EPHEMERAL_SERVER | null = null;
|
|
|
|
|
const cwd = Deno.cwd();
|
|
|
|
|
|
|
|
|
|
try {
|
2026-01-15 20:33:26 -08:00
|
|
|
Deno.chdir("./tests/www/spa");
|
2025-11-20 16:44:49 -08:00
|
|
|
test_server_info = await get_ephemeral_listen_server();
|
|
|
|
|
|
|
|
|
|
{
|
2026-01-15 20:33:26 -08:00
|
|
|
const response = await fetch(
|
|
|
|
|
`http://${test_server_info.hostname}:${test_server_info.port}/foo/bar/baz`,
|
|
|
|
|
{
|
|
|
|
|
method: "GET",
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-11-20 16:44:49 -08:00
|
|
|
|
|
|
|
|
const body = await response.text();
|
|
|
|
|
|
|
|
|
|
asserts.assert(response.ok);
|
|
|
|
|
asserts.assert(body);
|
|
|
|
|
asserts.assertMatch(body, /SPA PAGE/s);
|
2025-12-04 14:59:14 -08:00
|
|
|
asserts.assertMatch(body, /test include/s);
|
2025-11-20 16:44:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2026-01-15 20:33:26 -08:00
|
|
|
const response = await fetch(
|
|
|
|
|
`http://${test_server_info.hostname}:${test_server_info.port}/testing`,
|
|
|
|
|
{
|
|
|
|
|
method: "GET",
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-11-20 16:44:49 -08:00
|
|
|
|
|
|
|
|
const body = await response.text();
|
|
|
|
|
|
|
|
|
|
asserts.assert(response.ok);
|
|
|
|
|
asserts.assert(body);
|
|
|
|
|
asserts.assertMatch(body, /Hello World - Testing/s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2026-01-15 20:33:26 -08:00
|
|
|
const response = await fetch(
|
|
|
|
|
`http://${test_server_info.hostname}:${test_server_info.port}/testing/blah.html`,
|
|
|
|
|
{
|
|
|
|
|
method: "GET",
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-11-20 16:44:49 -08:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-15 20:33:26 -08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-11-20 16:44:49 -08:00
|
|
|
});
|