feature: serverus modularly serves up a directory as an HTTP server
This commit is contained in:
commit
58139b078d
20 changed files with 1449 additions and 0 deletions
48
tests/04_test_overriding_handlers.test.ts
Normal file
48
tests/04_test_overriding_handlers.test.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import * as asserts from '@std/assert';
|
||||
import { EPHEMERAL_SERVER, get_ephemeral_listen_server } from './helpers.ts';
|
||||
import * as path from '@std/path';
|
||||
|
||||
Deno.test({
|
||||
name: 'override the default handlers',
|
||||
permissions: {
|
||||
env: true,
|
||||
read: true,
|
||||
write: true,
|
||||
net: true
|
||||
},
|
||||
fn: async () => {
|
||||
let test_server_info: EPHEMERAL_SERVER | null = null;
|
||||
const cwd = Deno.cwd();
|
||||
const old_handlers: string | undefined = Deno.env.get('SERVERUS_HANDLERS');
|
||||
|
||||
try {
|
||||
Deno.chdir('./tests/www');
|
||||
Deno.env.set(
|
||||
'SERVERUS_HANDLERS',
|
||||
`${path.join(path.dirname(path.resolve(path.fromFileUrl(import.meta.url))), 'handlers')}${
|
||||
old_handlers ? (';' + old_handlers) : ''
|
||||
}`
|
||||
);
|
||||
test_server_info = await get_ephemeral_listen_server();
|
||||
|
||||
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/echo/hello_world.foo`, {
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
const body = await response.text();
|
||||
|
||||
asserts.assert(response.ok);
|
||||
asserts.assert(body);
|
||||
asserts.assertEquals(body, 'foo');
|
||||
} finally {
|
||||
Deno.chdir(cwd);
|
||||
Deno.env.delete('SERVERUS_HANDLERS');
|
||||
if (old_handlers) {
|
||||
Deno.env.set('SERVERUS_HANDLERS', old_handlers);
|
||||
}
|
||||
if (test_server_info) {
|
||||
await test_server_info?.server?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue