Skip to content

Commit 32ca201

Browse files
committed
test: add test case
1 parent 3d37091 commit 32ca201

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

middleware_test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("compression", () => {
9797
await response.text();
9898
});
9999

100-
it("should override default encoding", async () => {
100+
it("should override default encoding by providing encoding map", async () => {
101101
const middleware = compression({ gzip: () => "def" });
102102
const request = new Request("test:", {
103103
headers: { "accept-encoding": "gzip" },
@@ -119,6 +119,28 @@ describe("compression", () => {
119119
);
120120
});
121121

122+
it("should override default encoding by providing encoder", async () => {
123+
const middleware = compression([{ encoding: "gzip", encode: () => "def" }]);
124+
const request = new Request("test:", {
125+
headers: { "accept-encoding": "gzip" },
126+
});
127+
128+
const response = await middleware(request, () => new Response("abc"));
129+
130+
assert(
131+
await equalsResponse(
132+
response,
133+
new Response("def", {
134+
headers: {
135+
"content-encoding": "gzip",
136+
vary: "accept-encoding",
137+
},
138+
}),
139+
true,
140+
),
141+
);
142+
});
143+
122144
it("should skip if the accept-encoding is identity", async () => {
123145
const fn = spy(() => "");
124146
const middleware = compression({ identity: fn });
@@ -153,8 +175,6 @@ describe("compression", () => {
153175
() => new Response("abc", { headers: { "vary": "Accept-Encoding" } }),
154176
);
155177

156-
console.log(response);
157-
158178
assert(
159179
await equalsResponse(
160180
response,

0 commit comments

Comments
 (0)