2022-03-30 12:42:19 +00:00
|
|
|
import { runBuildAndStartApp } from './helpers.js';
|
2022-04-15 21:01:33 +00:00
|
|
|
import { assertEquals, assert, DOMParser } from './deps.js';
|
|
|
|
|
|
|
|
async function startApp(cb) {
|
|
|
|
await runBuildAndStartApp('./fixtures/basics/', cb);
|
|
|
|
}
|
2022-03-30 12:42:19 +00:00
|
|
|
|
2022-05-31 15:41:33 +00:00
|
|
|
// this needs to be here and not in the specific test case, because
|
|
|
|
// the variables are loaded in the global scope of the built server
|
|
|
|
// module, which is only executed once upon the first load
|
|
|
|
const varContent = 'this is a value stored in env variable';
|
|
|
|
Deno.env.set('SOME_VARIABLE', varContent);
|
|
|
|
|
2022-03-30 12:42:19 +00:00
|
|
|
Deno.test({
|
|
|
|
name: 'Basics',
|
|
|
|
async fn() {
|
2022-04-15 21:01:33 +00:00
|
|
|
await startApp(async () => {
|
2022-03-30 12:42:19 +00:00
|
|
|
const resp = await fetch('http://127.0.0.1:8085/');
|
|
|
|
assertEquals(resp.status, 200);
|
|
|
|
const html = await resp.text();
|
|
|
|
assert(html);
|
2022-04-21 16:10:06 +00:00
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
2022-04-21 16:11:09 +00:00
|
|
|
const div = doc.querySelector('#react');
|
2022-04-21 16:10:06 +00:00
|
|
|
assert(div, 'div exists');
|
2022-03-30 12:42:19 +00:00
|
|
|
});
|
2022-03-30 12:43:13 +00:00
|
|
|
},
|
2022-03-30 12:42:19 +00:00
|
|
|
});
|
2022-04-15 21:01:33 +00:00
|
|
|
|
2022-08-31 20:11:46 +00:00
|
|
|
Deno.test({
|
|
|
|
name: 'Custom 404',
|
|
|
|
async fn() {
|
|
|
|
await startApp(async () => {
|
|
|
|
const resp = await fetch('http://127.0.0.1:8085/this-does-not-exist');
|
|
|
|
assertEquals(resp.status, 404);
|
|
|
|
const html = await resp.text();
|
|
|
|
assert(html);
|
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
|
|
|
const header = doc.querySelector('#custom-404');
|
|
|
|
assert(header, 'displays custom 404');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-15 21:01:33 +00:00
|
|
|
Deno.test({
|
|
|
|
name: 'Loads style assets',
|
|
|
|
async fn() {
|
|
|
|
await startApp(async () => {
|
|
|
|
let resp = await fetch('http://127.0.0.1:8085/');
|
|
|
|
const html = await resp.text();
|
|
|
|
|
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
|
|
|
const link = doc.querySelector('link');
|
|
|
|
const href = link.getAttribute('href');
|
2022-04-15 21:02:19 +00:00
|
|
|
|
2022-04-15 21:01:33 +00:00
|
|
|
resp = await fetch(new URL(href, 'http://127.0.0.1:8085/'));
|
|
|
|
assertEquals(resp.status, 200);
|
|
|
|
const ct = resp.headers.get('content-type');
|
|
|
|
assertEquals(ct, 'text/css');
|
2022-04-15 21:02:19 +00:00
|
|
|
await resp.body.cancel();
|
2022-04-15 21:01:33 +00:00
|
|
|
});
|
2022-04-15 21:02:19 +00:00
|
|
|
},
|
|
|
|
});
|
2022-05-31 15:41:33 +00:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: 'Correctly loads run-time env variables',
|
|
|
|
async fn() {
|
|
|
|
await startApp(async () => {
|
|
|
|
const resp = await fetch('http://127.0.0.1:8085/');
|
|
|
|
const html = await resp.text();
|
|
|
|
|
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
|
|
|
const p = doc.querySelector('p#env-value');
|
|
|
|
assertEquals(p.innerText, varContent);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2022-08-16 14:08:40 +00:00
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: 'Works with Markdown',
|
|
|
|
async fn() {
|
|
|
|
await startApp(async () => {
|
|
|
|
const resp = await fetch('http://127.0.0.1:8085/markdown');
|
|
|
|
const html = await resp.text();
|
|
|
|
|
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
|
|
|
const h1 = doc.querySelector('h1');
|
|
|
|
assertEquals(h1.innerText, 'Heading from Markdown');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: 'Works with MDX',
|
|
|
|
async fn() {
|
|
|
|
await startApp(async () => {
|
|
|
|
const resp = await fetch('http://127.0.0.1:8085/mdx');
|
|
|
|
const html = await resp.text();
|
|
|
|
|
|
|
|
const doc = new DOMParser().parseFromString(html, `text/html`);
|
|
|
|
const h1 = doc.querySelector('h1');
|
|
|
|
assertEquals(h1.innerText, 'Heading from MDX');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|