-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.ts
67 lines (54 loc) · 1.65 KB
/
utils_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { isNoTransform, reCalcContentLength } from "./utils.ts";
import { assert, describe, equalsResponse, it } from "./_dev_deps.ts";
describe("isNoTransform", () => {
it("should return true", () => {
const table: string[] = [
"no-transform",
" no-transform",
"no-transform ",
" no-transform ",
"abc, no-transform",
];
table.forEach((input) => {
assert(isNoTransform(input));
});
});
it("should return false", () => {
const table: string[] = [
"",
"abc",
"notransform",
];
table.forEach((input) => {
assert(!isNoTransform(input));
});
});
});
describe("reCalcContentLength", () => {
it("should have new content-length if the response has content-length header", async () => {
const response = await reCalcContentLength(
new Response("abc", { headers: { "content-length": "100000" } }),
);
assert(
equalsResponse(
response,
new Response("abc", { headers: { "content-length": "3" } }),
true,
),
);
});
it("should return same response if the response has been read", async () => {
const initResponse = new Response("abc", {
headers: { "content-length": "100000" },
});
await initResponse.text();
assert(initResponse.bodyUsed);
const response = await reCalcContentLength(initResponse);
assert(initResponse === response);
});
it("should return same response if the response does not have content-length header", async () => {
const initResponse = new Response("abc");
const response = await reCalcContentLength(initResponse);
assert(initResponse === response);
});
});