summaryrefslogtreecommitdiff
path: root/packages/integrations/deno/test/basics.test.js
blob: bc7322067ae70a341878734be07cb5bb4ccfa0b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { runBuildAndStartApp } from './helpers.js';
import { assertEquals, assert, DOMParser } from './deps.js';

async function startApp(cb) {
	await runBuildAndStartApp('./fixtures/basics/', cb);
}

Deno.test({
	name: 'Basics',
	async fn() {
		await startApp(async () => {
			const resp = await fetch('http://127.0.0.1:8085/');
			assertEquals(resp.status, 200);
			const html = await resp.text();
			assert(html);
			const doc = new DOMParser().parseFromString(html, `text/html`);
			const div = doc.querySelector('#react');
			assert(div, 'div exists');
		});
	},
});

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');

			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');
			await resp.body.cancel();
		});
	},
});