summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorAlan Pearce2023-09-13 14:46:08 +0200
committerAlan Pearce2023-09-13 14:46:08 +0200
commit2574e38f6241bfa4dd5193fcb636e8b76f5c6437 (patch)
tree1b88063ea7bcd63c64a549af1e10e28f968275be /test
parentda0355160e9603f097438c446ef1f9c992758ddb (diff)
downloadwebsite-2574e38f6241bfa4dd5193fcb636e8b76f5c6437.tar.lz
website-2574e38f6241bfa4dd5193fcb636e8b76f5c6437.tar.zst
website-2574e38f6241bfa4dd5193fcb636e8b76f5c6437.zip
Add tests
Diffstat (limited to 'test')
-rw-r--r--test/index.test.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/index.test.ts b/test/index.test.ts
index c1f5f64..2f682a9 100644
--- a/test/index.test.ts
+++ b/test/index.test.ts
@@ -24,3 +24,74 @@ test("/asdf returns 404", async function () {
   const res = await fetch(`${base}asdf`);
   expect(res.status).toBe(404);
 });
+
+test("/ returns 304 with newer if-modified-since header", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "if-modified-since": new Date().toUTCString(),
+    },
+  });
+  expect(res.status).toBe(304);
+  expect(res.headers.get("vary")).toBe("Accept-Encoding");
+});
+
+test("/ returns 200 with older if-modified-since header", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "if-modified-since": new Date(0).toUTCString(),
+    },
+  });
+  expect(res.status).toBe(200);
+});
+
+test("/ returns gzipped content with accept-encoding: gzip", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "accept-encoding": "gzip",
+    },
+  });
+  expect(res.status).toBe(200);
+  // Bun 0.8.1 this doesn't work, but `verbose` shows it's there
+  // expect(res.headers.get("content-encoding")).toBe("gzip");
+  // response is automatically gunzipped
+  const body = await res.text();
+  expect(body.length).toBeGreaterThan(
+    Number(res.headers.get("content-length")),
+  );
+});
+
+test("/ returns uncompressed content with accept-encoding: identity", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "accept-encoding": "identity",
+    },
+  });
+  expect(res.status).toBe(200);
+  const body = await res.text();
+  expect(body.length).toBe(Number(res.headers.get("content-length")));
+});
+
+test("/ returns brotli-compressed content with accept-encoding: br", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "accept-encoding": "br",
+    },
+  });
+  expect(res.status).toBe(200);
+  expect(res.headers.get("content-encoding")).toBe("br");
+  const body = await res.text();
+  expect(body.length).toBeLessThan(Number(res.headers.get("content-length")));
+});
+
+test("/ returns zstd-compressed content with accept-encoding: zstd", async function () {
+  const res = await fetch(base, {
+    headers: {
+      "accept-encoding": "zstd",
+    },
+  });
+  expect(res.status).toBe(200);
+  expect(res.headers.get("content-encoding")).toBe("zstd");
+  expect(res.headers.get("vary")).toBe("Accept-Encoding");
+  const body = await res.text();
+  expect(body.length).toBeLessThan(Number(res.headers.get("content-length")));
+});