summary refs log tree commit diff
path: root/src/web/server.test.js
blob: 6ed3535c2026a37de6fb24a42350fb6d2883a893 (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
// @ts-check

const streamWeb = require("stream/web")
const {test} = require("../../test/web")
const {router} = require("../../test/web")
const assert = require("assert").strict

require("./server")

test("web server: can get home", async t => {
	t.has(await router.test("get", "/", {}), /a bridge between the Discord and Matrix chat apps/)
})

test("web server: can get htmx", async t => {
	t.match(await router.test("get", "/static/htmx.js", {}), /htmx =/)
})

test("web server: can get css", async t => {
	t.match(await router.test("get", "/static/stacks.min.css", {}), /--stacks-/)
})

test("web server: can get icon", async t => {
	const content = await router.test("get", "/icon.png", {})
	t.ok(content instanceof Buffer)
})

test("web server: compresses static resources", async t => {
	const content = await router.test("get", "/static/stacks.min.css", {
		headers: {
			"accept-encoding": "gzip"
		}
	})
	assert(content instanceof streamWeb.ReadableStream)
	const firstChunk = await content.getReader().read()
	t.ok(firstChunk.value instanceof Uint8Array, "can get data")
	t.deepEqual(firstChunk.value.slice(0, 3), Uint8Array.from([31, 139, 8]), "has compressed gzip header")
})