-
Notifications
You must be signed in to change notification settings - Fork 0
/
luhmann_test_e2e.ts
41 lines (33 loc) · 1.62 KB
/
luhmann_test_e2e.ts
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 { assert, assertSnapshot } from "./dev_deps.ts";
import { parse } from "./deps.ts";
const baseFileUrl = " http://localhost:4507/";
const baseTestUrl = "http://localhost:8080/";
const sitemapResource = "sitemap.yaml";
Deno.test("e2e isEtagHit", async function (): Promise<void> {
// Get the homepage the first time
const homePageResponse = await fetch(baseTestUrl);
// Dispose of the response to prevent a 'leaking resources' error
await homePageResponse.body?.cancel();
// Extract the etag from header for reuse in the next request
const etag = await homePageResponse.headers.get("etag");
const headers = { headers: { "If-None-Match": etag ? etag : "NOETAG" } };
// Get the homepage the second time, now with If-None-Match header
const homePageIfNoneMatch = await fetch(baseTestUrl, headers);
// Again, dispose of the response to prevent a 'leaking resources' error
await homePageIfNoneMatch.body?.cancel();
await assert(homePageIfNoneMatch.status === 304);
});
Deno.test("e2e isSnapshotMatch", async function (t): Promise<void> {
const homePageResponse = await fetch(baseTestUrl);
const homePageText = await homePageResponse.text();
await assertSnapshot(t, homePageText);
const sitemapResponse = await fetch(`${baseFileUrl}${sitemapResource}`);
const sitemapbody = await sitemapResponse?.text();
const parsedYamlDocList = parse(sitemapbody) as string[];
for (const doc of parsedYamlDocList) {
const mdName = doc.split(".").slice(0, -1).join(".");
const docResponse = await fetch(`${baseTestUrl}${mdName}`);
const docText = await docResponse.text();
await assertSnapshot(t, docText);
}
});