feature: serverus modularly serves up a directory as an HTTP server

This commit is contained in:
Andy Burke 2025-06-19 15:43:01 -07:00
commit 58139b078d
20 changed files with 1449 additions and 0 deletions

View file

@ -0,0 +1,73 @@
import * as asserts from '@std/assert';
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from './helpers.ts';
Deno.test({
name: 'get markdown file (html)',
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}/test.md`, {
method: 'GET'
});
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertMatch(body, /\<html\>.*?\<\/html\>/is);
} finally {
Deno.chdir(cwd);
if (test_server_info) {
await test_server_info?.server?.stop();
}
}
}
});
Deno.test({
name: 'get markdown file (markdown)',
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}/test.md`, {
method: 'GET',
headers: {
'Accept': 'text/markdown'
}
});
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertNotMatch(body, /\<html\>.*?\<\/html\>/is);
} finally {
Deno.chdir(cwd);
if (test_server_info) {
await test_server_info?.server?.stop();
}
}
}
});