Skip to content

Commit ba8050c

Browse files
committed
Fix tests
1 parent 71a3757 commit ba8050c

15 files changed

+123
-179
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"deno.enable": true,
33
"editor.defaultFormatter": "denoland.vscode-deno",
4-
"npm.autoDetect": "off"
4+
"npm.autoDetect": "off",
5+
"[typescript]": {
6+
"editor.defaultFormatter": "denoland.vscode-deno"
7+
}
58
}

deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"version": "3.2.0",
44
"exports": "./mod.ts",
55
"imports": {
6+
"@deno-library/compress": "jsr:@deno-library/compress@^0.5.5",
67
"@dldc/chemin": "jsr:@dldc/chemin@^12.0.0",
78
"@dldc/compose": "jsr:@dldc/compose@^6.0.2",
89
"@dldc/erreur": "jsr:@dldc/erreur@^7.1.1",
910
"@dldc/stack": "jsr:@dldc/stack@^7.0.0",
1011
"@dldc/zenjson": "jsr:@dldc/zenjson@^3.0.1",
12+
"@openjs/port-free": "jsr:@openjs/port-free@^1.0.0",
1113
"@std/assert": "jsr:@std/assert@^1.0.11",
1214
"@std/expect": "jsr:@std/expect@^1.0.13",
1315
"@std/http": "jsr:@std/http@^1.0.13"

deno.lock

Lines changed: 64 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/compress.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { gunzip, inflate } from "@deno-library/compress";
12
import { assert } from "@std/assert";
23
import { expect } from "@std/expect";
34
import {
@@ -8,7 +9,6 @@ import {
89
json,
910
ZenResponse,
1011
} from "../mod.ts";
11-
import { gunzip, inflate } from "./deps.ts";
1212
import { expectHeaders } from "./utils/expectHeaders.ts";
1313
import { request } from "./utils/request.ts";
1414
import { streamSizeReader } from "./utils/streamSizeReader.ts";

tests/cookies.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Deno.test("should set the Set-Cookie header", async () => {
1919
value: "T55YTRR55554",
2020
}]);
2121
});
22-
const { close, url, fetch } = mountServer(app);
22+
const { close, url, fetch } = await mountServer(app);
2323
const res = await fetch(url);
2424
expectHeaders(
2525
res,
@@ -39,7 +39,7 @@ Deno.test("should set the Set-Cookie header using Manager", async () => {
3939
return noContent();
4040
}),
4141
);
42-
const { close, url, fetch } = mountServer(app);
42+
const { close, url, fetch } = await mountServer(app);
4343
const res = await fetch(url);
4444
expectHeaders(
4545
res,
@@ -61,7 +61,7 @@ Deno.test("should set two Set-Cookie header using Manager", async () => {
6161
return noContent();
6262
}),
6363
);
64-
const { close, url, fetch } = mountServer(app);
64+
const { close, url, fetch } = await mountServer(app);
6565
const res = await fetch(url);
6666
expectHeaders(
6767
res,
@@ -83,7 +83,7 @@ Deno.test("should return the same result as koa", async () => {
8383
}]);
8484
});
8585

86-
const { close, url, fetch } = mountServer(app);
86+
const { close, url, fetch } = await mountServer(app);
8787

8888
const res = await fetch(url);
8989

@@ -107,7 +107,7 @@ Deno.test("should return the same result as koa when deleting cookie", async ()
107107
expires: new Date(0),
108108
}]);
109109
});
110-
const { close, url, fetch } = mountServer(app);
110+
const { close, url, fetch } = await mountServer(app);
111111
const res = await fetch(url);
112112

113113
expectHeaders(
@@ -132,7 +132,7 @@ Deno.test("Cookie manager should set and delete cookies", async () => {
132132
}),
133133
);
134134

135-
const { close, url, fetch } = mountServer(app);
135+
const { close, url, fetch } = await mountServer(app);
136136
const res = await fetch(url);
137137

138138
expectHeaders(
@@ -162,7 +162,7 @@ Deno.test("Cookies should not be set on error response", async () => {
162162
},
163163
),
164164
);
165-
const { url, close, fetch } = mountServer(app);
165+
const { url, close, fetch } = await mountServer(app);
166166
const res = await fetch(url);
167167
expectHeaders(
168168
res,

tests/cors.actual.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Deno.test("create server with cors does not throw", () => {
1818

1919
Deno.test("simple text response", async () => {
2020
const handler = createCorsHandler();
21-
const { url, close, fetch } = mountServer(handler);
21+
const { url, close, fetch } = await mountServer(handler);
2222
const res = await fetch(url);
2323
expectHeaders(
2424
res,
@@ -38,7 +38,7 @@ Deno.test("6.1.1 Does not set headers if Origin is missing", async () => {
3838
const app = createCorsHandler({
3939
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
4040
});
41-
const { url, close, fetch } = mountServer(app);
41+
const { url, close, fetch } = await mountServer(app);
4242
const res = await fetch(url);
4343
expectHeaders(
4444
res,
@@ -58,7 +58,7 @@ Deno.test("6.1.2 Does not set headers if Origin does not match", async () => {
5858
const app = createCorsHandler({
5959
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
6060
});
61-
const { url, close, fetch } = mountServer(app);
61+
const { url, close, fetch } = await mountServer(app);
6262
const res = await fetch(url, {
6363
headers: {
6464
Origin: "http://random-website.com",
@@ -82,7 +82,7 @@ Deno.test("6.1.3 Sets Allow-Origin headers if the Origin matches", async () => {
8282
const app = createCorsHandler({
8383
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
8484
});
85-
const { url, close, fetch } = mountServer(app);
85+
const { url, close, fetch } = await mountServer(app);
8686
const res = await fetch(url, {
8787
headers: {
8888
Origin: "http://api.myapp.com",
@@ -107,7 +107,7 @@ Deno.test("Sets Allow-Origin headers if allowOrigin is true (wildcard)", async (
107107
const app = createCorsHandler({
108108
allowOrigin: true,
109109
});
110-
const { url, close, fetch } = mountServer(app);
110+
const { url, close, fetch } = await mountServer(app);
111111
const res = await fetch(url, {
112112
headers: {
113113
Origin: "http://api.myapp.com",
@@ -133,7 +133,7 @@ Deno.test("6.1.3 Sets Access-Control-Allow-Credentials header if configured", as
133133
allowOrigin: ["http://api.myapp.com"],
134134
allowCredentials: true,
135135
});
136-
const { url, close, fetch } = mountServer(app);
136+
const { url, close, fetch } = await mountServer(app);
137137
const res = await fetch(url, {
138138
headers: {
139139
Origin: "http://api.myapp.com",
@@ -159,7 +159,7 @@ Deno.test("6.1.4 Does not set exposed headers if empty", async () => {
159159
const app = createCorsHandler({
160160
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
161161
});
162-
const { url, close, fetch } = mountServer(app);
162+
const { url, close, fetch } = await mountServer(app);
163163
const res = await fetch(url, {
164164
headers: {
165165
Origin: "http://api.myapp.com",
@@ -185,7 +185,7 @@ Deno.test("6.1.4 Sets exposed headers if configured", async () => {
185185
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
186186
exposeHeaders: ["HeaderA", "HeaderB"],
187187
});
188-
const { url, close, fetch } = mountServer(app);
188+
const { url, close, fetch } = await mountServer(app);
189189
const res = await fetch(url, {
190190
headers: {
191191
Origin: "http://api.myapp.com",

tests/cors.package.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Deno.test("create a server with CorsPackage does not throw", () => {
2727

2828
Deno.test("response to actual request", async () => {
2929
const app = createCorsHandler();
30-
const { url, close, fetch } = mountServer(app);
30+
const { url, close, fetch } = await mountServer(app);
3131
const res = await fetch(url, {
3232
headers: {
3333
Origin: "http://api.myapp.com",
@@ -50,7 +50,7 @@ Deno.test("response to actual request", async () => {
5050

5151
Deno.test("response to preflight request", async () => {
5252
const app = createCorsHandler();
53-
const { url, close, fetch } = mountServer(app);
53+
const { url, close, fetch } = await mountServer(app);
5454
const res = await fetch(url, {
5555
method: "OPTIONS",
5656
headers: {
@@ -86,7 +86,7 @@ Deno.test("handle error", async () => {
8686
},
8787
),
8888
);
89-
const { url, close, fetch } = mountServer(handler);
89+
const { url, close, fetch } = await mountServer(handler);
9090
const res = await fetch(url, {
9191
headers: {
9292
Origin: "http://api.myapp.com",
@@ -113,7 +113,7 @@ Deno.test("handle error on preflight", async () => {
113113
throw createNotFound();
114114
}),
115115
);
116-
const { url, close, fetch } = mountServer(handler);
116+
const { url, close, fetch } = await mountServer(handler);
117117
const res = await fetch(url, {
118118
method: "OPTIONS",
119119
headers: {

tests/cors.preflight.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Deno.test("6.2.1 Does not set headers if Origin is missing", async () => {
3232
const app = createCorsHandler({
3333
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
3434
});
35-
const { url, close, fetch } = mountServer(app);
35+
const { url, close, fetch } = await mountServer(app);
3636
const res = await fetch(url, {
3737
headers: {},
3838
});
@@ -54,7 +54,7 @@ Deno.test("6.2.2 Does not set headers if Origin does not match", async () => {
5454
const app = createCorsHandler({
5555
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
5656
});
57-
const { url, close, fetch } = mountServer(app);
57+
const { url, close, fetch } = await mountServer(app);
5858
const res = await fetch(url, {
5959
method: "POST",
6060
headers: {
@@ -79,7 +79,7 @@ Deno.test("6.2.3 Does not set headers if Access-Control-Request-Method is missin
7979
const app = createCorsHandler({
8080
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
8181
});
82-
const { url, close, fetch } = mountServer(app);
82+
const { url, close, fetch } = await mountServer(app);
8383
const res = await fetch(url, {
8484
method: "POST",
8585
headers: {
@@ -112,7 +112,7 @@ Deno.test("6.2.6 Does not set headers if Access-Control-Request-Headers does not
112112
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
113113
allowHeaders: ["API-Token"],
114114
});
115-
const { url, close, fetch } = mountServer(app);
115+
const { url, close, fetch } = await mountServer(app);
116116
const res = await fetch(url, {
117117
method: "POST",
118118
headers: {
@@ -138,7 +138,7 @@ Deno.test("6.2.7 Set the Allow-Origin header if it matches", async () => {
138138
const app = createCorsHandler({
139139
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
140140
});
141-
const { url, close, fetch } = mountServer(app);
141+
const { url, close, fetch } = await mountServer(app);
142142
const res = await fetch(url, {
143143
method: "OPTIONS",
144144
headers: {

tests/deps.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Deno.test("create hanlder without crashing", () => {
2020

2121
Deno.test("simple text response", async () => {
2222
const handler = createHandler(() => ZenResponse.create("Hey"));
23-
const { url, close, fetch } = mountServer(handler);
23+
const { url, close, fetch } = await mountServer(handler);
2424
const res = await fetch(url);
2525

2626
expect(await res.text()).toBe("Hey");
@@ -40,7 +40,7 @@ Deno.test("simple text response", async () => {
4040

4141
Deno.test("send two requests", async () => {
4242
const handler = createHandler(() => ZenResponse.create("Hey"));
43-
const { url, close, fetch } = mountServer(handler);
43+
const { url, close, fetch } = await mountServer(handler);
4444

4545
const res = await fetch(url);
4646
expectHeaders(
@@ -68,7 +68,7 @@ Deno.test("send two requests", async () => {
6868

6969
Deno.test("response to arbitrary path", async () => {
7070
const handler = createHandler(() => ZenResponse.create("Hey"));
71-
const { url, close, fetch } = mountServer(handler);
71+
const { url, close, fetch } = await mountServer(handler);
7272

7373
const res = await fetch(`${url}${"/some/path"}`);
7474
expectHeaders(
@@ -87,7 +87,7 @@ Deno.test("response to arbitrary path", async () => {
8787

8888
Deno.test("response to post method", async () => {
8989
const handler = createHandler(() => ZenResponse.create("Hey"));
90-
const { url, close, fetch } = mountServer(handler);
90+
const { url, close, fetch } = await mountServer(handler);
9191

9292
const res = await fetch(url, { method: HttpMethod.POST });
9393
expectHeaders(
@@ -106,7 +106,7 @@ Deno.test("response to post method", async () => {
106106

107107
Deno.test("head request return 204 & empty body", async () => {
108108
const handler = createHandler(() => noContent());
109-
const { url, close, fetch } = mountServer(handler);
109+
const { url, close, fetch } = await mountServer(handler);
110110

111111
const res = await fetch(url, {
112112
method: HttpMethod.HEAD,
@@ -128,7 +128,7 @@ Deno.test("throw HttpError return an error", async () => {
128128
throw createNotFound();
129129
}),
130130
);
131-
const { close, url, fetch } = mountServer(handler);
131+
const { close, url, fetch } = await mountServer(handler);
132132
const res = await fetch(url);
133133
expectHeaders(
134134
res,
@@ -154,7 +154,7 @@ Deno.test("throw return an error", async () => {
154154
},
155155
),
156156
);
157-
const { close, url, fetch } = mountServer(handler);
157+
const { close, url, fetch } = await mountServer(handler);
158158
const res = await fetch(url);
159159
expectHeaders(
160160
res,

0 commit comments

Comments
 (0)