serverus/tests/11_test_spa.test.ts

64 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

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/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);
2025-12-04 14:59:14 -08:00
asserts.assertMatch(body, /test include/s);
}
{
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/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}/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();
}
}
}
});