feature: html with SSI
This commit is contained in:
parent
d917b69753
commit
0f65e57539
10 changed files with 210 additions and 27 deletions
73
tests/08_test_html_includes.test.ts
Normal file
73
tests/08_test_html_includes.test.ts
Normal 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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
1
tests/www/another_include.html
Normal file
1
tests/www/another_include.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div>Include #2!</div>
|
9
tests/www/index.html
Normal file
9
tests/www/index.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<html>
|
||||
<body>
|
||||
<p>Hello. An include should follow:</p>
|
||||
|
||||
<!-- #include file="./test_include.html" -->
|
||||
<!-- #include file="./yet_another_include.html" -->
|
||||
<p>Goodbye. The includes should be above.</p>
|
||||
</body>
|
||||
</html>
|
3
tests/www/test_include.html
Normal file
3
tests/www/test_include.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div>Include #1</div>
|
||||
|
||||
<!-- #include file="./another_include.html" -->
|
1
tests/www/yet_another_include.html
Normal file
1
tests/www/yet_another_include.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div>Include #3</div>
|
Loading…
Add table
Add a link
Reference in a new issue