deno.land / x / alosaur@v1.1.1 / e2e / response-cache.test.ts

response-cache.test.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, assertEquals } from "../src/deps_test.ts";import { killServer, startServer } from "./test.utils.ts";const { test } = Deno;
/** * Test cases */test({ name: "[http] cache should give the next response instantly", async fn(): Promise<void> { const process = await startServer("./examples/cache/app.ts"); const baseUrl = "http://localhost:8000";
try { // First request const perf1 = performance.now(); const r1 = await fetch(baseUrl); const text_r1 = await r1.text();
const perf2 = performance.now();
assertEquals(r1.status, 200); assertEquals(text_r1, "Hello world");
// Second request const perf3 = performance.now(); const r2 = await fetch(baseUrl); const text_r2 = await r2.text();
const perf4 = performance.now();
assertEquals(r2.status, 200); assertEquals(text_r2, "Hello world");
assert((perf2 - perf1 - 200) > perf4 - perf3); } finally { killServer(process); } },});
alosaur

Version Info

Tagged at
2 months ago