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