Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed Feb 12, 2025
1 parent 71a3757 commit ba8050c
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 179 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"deno.enable": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"npm.autoDetect": "off"
"npm.autoDetect": "off",
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
2 changes: 2 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"version": "3.2.0",
"exports": "./mod.ts",
"imports": {
"@deno-library/compress": "jsr:@deno-library/compress@^0.5.5",
"@dldc/chemin": "jsr:@dldc/chemin@^12.0.0",
"@dldc/compose": "jsr:@dldc/compose@^6.0.2",
"@dldc/erreur": "jsr:@dldc/erreur@^7.1.1",
"@dldc/stack": "jsr:@dldc/stack@^7.0.0",
"@dldc/zenjson": "jsr:@dldc/zenjson@^3.0.1",
"@openjs/port-free": "jsr:@openjs/port-free@^1.0.0",
"@std/assert": "jsr:@std/assert@^1.0.11",
"@std/expect": "jsr:@std/expect@^1.0.13",
"@std/http": "jsr:@std/http@^1.0.13"
Expand Down
187 changes: 64 additions & 123 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/compress.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gunzip, inflate } from "@deno-library/compress";
import { assert } from "@std/assert";
import { expect } from "@std/expect";
import {
Expand All @@ -8,7 +9,6 @@ import {
json,
ZenResponse,
} from "../mod.ts";
import { gunzip, inflate } from "./deps.ts";
import { expectHeaders } from "./utils/expectHeaders.ts";
import { request } from "./utils/request.ts";
import { streamSizeReader } from "./utils/streamSizeReader.ts";
Expand Down
14 changes: 7 additions & 7 deletions tests/cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Deno.test("should set the Set-Cookie header", async () => {
value: "T55YTRR55554",
}]);
});
const { close, url, fetch } = mountServer(app);
const { close, url, fetch } = await mountServer(app);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -39,7 +39,7 @@ Deno.test("should set the Set-Cookie header using Manager", async () => {
return noContent();
}),
);
const { close, url, fetch } = mountServer(app);
const { close, url, fetch } = await mountServer(app);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -61,7 +61,7 @@ Deno.test("should set two Set-Cookie header using Manager", async () => {
return noContent();
}),
);
const { close, url, fetch } = mountServer(app);
const { close, url, fetch } = await mountServer(app);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -83,7 +83,7 @@ Deno.test("should return the same result as koa", async () => {
}]);
});

const { close, url, fetch } = mountServer(app);
const { close, url, fetch } = await mountServer(app);

const res = await fetch(url);

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

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

const { close, url, fetch } = mountServer(app);
const { close, url, fetch } = await mountServer(app);
const res = await fetch(url);

expectHeaders(
Expand Down Expand Up @@ -162,7 +162,7 @@ Deno.test("Cookies should not be set on error response", async () => {
},
),
);
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url);
expectHeaders(
res,
Expand Down
16 changes: 8 additions & 8 deletions tests/cors.actual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Deno.test("create server with cors does not throw", () => {

Deno.test("simple text response", async () => {
const handler = createCorsHandler();
const { url, close, fetch } = mountServer(handler);
const { url, close, fetch } = await mountServer(handler);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -38,7 +38,7 @@ Deno.test("6.1.1 Does not set headers if Origin is missing", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -58,7 +58,7 @@ Deno.test("6.1.2 Does not set headers if Origin does not match", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://random-website.com",
Expand All @@ -82,7 +82,7 @@ Deno.test("6.1.3 Sets Allow-Origin headers if the Origin matches", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand All @@ -107,7 +107,7 @@ Deno.test("Sets Allow-Origin headers if allowOrigin is true (wildcard)", async (
const app = createCorsHandler({
allowOrigin: true,
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand All @@ -133,7 +133,7 @@ Deno.test("6.1.3 Sets Access-Control-Allow-Credentials header if configured", as
allowOrigin: ["http://api.myapp.com"],
allowCredentials: true,
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand All @@ -159,7 +159,7 @@ Deno.test("6.1.4 Does not set exposed headers if empty", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand All @@ -185,7 +185,7 @@ Deno.test("6.1.4 Sets exposed headers if configured", async () => {
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
exposeHeaders: ["HeaderA", "HeaderB"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand Down
8 changes: 4 additions & 4 deletions tests/cors.package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Deno.test("create a server with CorsPackage does not throw", () => {

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

Deno.test("response to preflight request", async () => {
const app = createCorsHandler();
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
method: "OPTIONS",
headers: {
Expand Down Expand Up @@ -86,7 +86,7 @@ Deno.test("handle error", async () => {
},
),
);
const { url, close, fetch } = mountServer(handler);
const { url, close, fetch } = await mountServer(handler);
const res = await fetch(url, {
headers: {
Origin: "http://api.myapp.com",
Expand All @@ -113,7 +113,7 @@ Deno.test("handle error on preflight", async () => {
throw createNotFound();
}),
);
const { url, close, fetch } = mountServer(handler);
const { url, close, fetch } = await mountServer(handler);
const res = await fetch(url, {
method: "OPTIONS",
headers: {
Expand Down
10 changes: 5 additions & 5 deletions tests/cors.preflight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Deno.test("6.2.1 Does not set headers if Origin is missing", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
headers: {},
});
Expand All @@ -54,7 +54,7 @@ Deno.test("6.2.2 Does not set headers if Origin does not match", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
method: "POST",
headers: {
Expand All @@ -79,7 +79,7 @@ Deno.test("6.2.3 Does not set headers if Access-Control-Request-Method is missin
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
method: "POST",
headers: {
Expand Down Expand Up @@ -112,7 +112,7 @@ Deno.test("6.2.6 Does not set headers if Access-Control-Request-Headers does not
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
allowHeaders: ["API-Token"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
method: "POST",
headers: {
Expand All @@ -138,7 +138,7 @@ Deno.test("6.2.7 Set the Allow-Origin header if it matches", async () => {
const app = createCorsHandler({
allowOrigin: ["http://api.myapp.com", "http://www.myapp.com"],
});
const { url, close, fetch } = mountServer(app);
const { url, close, fetch } = await mountServer(app);
const res = await fetch(url, {
method: "OPTIONS",
headers: {
Expand Down
6 changes: 0 additions & 6 deletions tests/deps.ts

This file was deleted.

14 changes: 7 additions & 7 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Deno.test("create hanlder without crashing", () => {

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

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

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

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

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

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

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

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

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

const res = await fetch(url, {
method: HttpMethod.HEAD,
Expand All @@ -128,7 +128,7 @@ Deno.test("throw HttpError return an error", async () => {
throw createNotFound();
}),
);
const { close, url, fetch } = mountServer(handler);
const { close, url, fetch } = await mountServer(handler);
const res = await fetch(url);
expectHeaders(
res,
Expand All @@ -154,7 +154,7 @@ Deno.test("throw return an error", async () => {
},
),
);
const { close, url, fetch } = mountServer(handler);
const { close, url, fetch } = await mountServer(handler);
const res = await fetch(url);
expectHeaders(
res,
Expand Down
Loading

0 comments on commit ba8050c

Please sign in to comment.