@server/next 0.20.8 → 0.20.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth.test.js +43 -59
- package/src/helpers/cookies.test.js +23 -0
- package/src/helpers/createCookies.js +8 -10
- package/src/index.js +52 -0
- package/src/index.test.js +21 -30
- package/src/parseResponse.js +3 -1
- package/src/reply.js +5 -2
- package/src/router.test.js +21 -22
- package/src/session.test.js +26 -26
- package/src/url.test.js +13 -11
package/package.json
CHANGED
package/src/auth.test.js
CHANGED
|
@@ -2,77 +2,61 @@ import kv from "polystore";
|
|
|
2
2
|
|
|
3
3
|
import server from "./index.js";
|
|
4
4
|
|
|
5
|
-
const url = (token) =>
|
|
6
|
-
new Request("http://localhost:3000/", {
|
|
7
|
-
headers: { authorization: token },
|
|
8
|
-
});
|
|
9
|
-
|
|
10
5
|
describe("auth", () => {
|
|
11
6
|
const store = kv(new Map());
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const api = server({ store })
|
|
8
|
+
.get("/", (ctx) => ctx.headers.authorization)
|
|
9
|
+
.test();
|
|
15
10
|
|
|
16
11
|
it("should be Bearer", async () => {
|
|
17
|
-
const
|
|
18
|
-
|
|
12
|
+
const authorization = "Basic REqA2l022l8Q0tuIRtqLOPUy";
|
|
13
|
+
const { data } = await api.get("/", { headers: { authorization } });
|
|
14
|
+
expect(data).toBe("Invalid Authorization type, 'Basic'");
|
|
19
15
|
});
|
|
20
16
|
|
|
21
17
|
it("should have the proper token", async () => {
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
const authorization = "Bearer hola";
|
|
19
|
+
const { data } = await api.get("/", { headers: { authorization } });
|
|
20
|
+
expect(data).toBe("Invalid Authorization token");
|
|
24
21
|
});
|
|
25
22
|
|
|
26
23
|
it("can get the nested get", async () => {
|
|
27
|
-
const
|
|
28
|
-
|
|
24
|
+
const authorization = "Bearer REqA2l022l8Q0tuIRtqLOPUy";
|
|
25
|
+
const { data } = await api.get("/", { headers: { authorization } });
|
|
26
|
+
expect(data).toBe("Bearer REqA2l022l8Q0tuIRtqLOPUy");
|
|
29
27
|
});
|
|
28
|
+
});
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const url = (path, body = {}, headers = {}) =>
|
|
37
|
-
new Request("http://localhost:3000" + path, {
|
|
38
|
-
headers: {
|
|
39
|
-
cookie: "session=REqA2l022l8Q0tuIRtqLOPUy",
|
|
40
|
-
"content-type": "application/json",
|
|
41
|
-
...headers,
|
|
42
|
-
},
|
|
43
|
-
method: "POST",
|
|
44
|
-
body: JSON.stringify(body),
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const store = kv(new Map());
|
|
48
|
-
const app = server({ auth: { type: "token", providers: "email" }, store });
|
|
49
|
-
|
|
50
|
-
it("can create a new user", async () => {
|
|
51
|
-
const regReq = await app.fetch(
|
|
52
|
-
url("/auth/register/email", { email: EMAIL, password: PASS })
|
|
53
|
-
);
|
|
54
|
-
const register = await regReq.json();
|
|
55
|
-
expect(regReq.status).toBe(201);
|
|
56
|
-
expect(await store.keys()).toEqual([
|
|
57
|
-
"auth:abc@test.com",
|
|
58
|
-
"session:" + register.token,
|
|
59
|
-
]);
|
|
60
|
-
|
|
61
|
-
const logoutReq = await app.fetch(
|
|
62
|
-
url("/auth/logout", {}, { authorization: "Bearer " + register.token })
|
|
63
|
-
);
|
|
64
|
-
expect(logoutReq.status).toBe(200);
|
|
65
|
-
expect(await store.keys()).toEqual(["auth:abc@test.com"]);
|
|
30
|
+
describe("user creation flow", () => {
|
|
31
|
+
// These are obviously mock data
|
|
32
|
+
const EMAIL = "abc@test.com";
|
|
33
|
+
const PASS = "11111111";
|
|
34
|
+
const CREDENTIALS = { email: EMAIL, password: PASS };
|
|
66
35
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
36
|
+
const store = kv(new Map());
|
|
37
|
+
const auth = { type: "token", providers: "email" };
|
|
38
|
+
const api = server({ auth, store }).test();
|
|
39
|
+
|
|
40
|
+
it("can create a new user", async () => {
|
|
41
|
+
const register = await api.post("/auth/register/email", CREDENTIALS);
|
|
42
|
+
expect(register.status).toBe(201);
|
|
43
|
+
expect(await store.keys()).toEqual([
|
|
44
|
+
"auth:abc@test.com",
|
|
45
|
+
"session:" + register.data.token,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
const authorization = "Bearer " + register.data.token;
|
|
49
|
+
const headers = { authorization };
|
|
50
|
+
const logout = await api.post("/auth/logout", {}, { headers });
|
|
51
|
+
|
|
52
|
+
expect(logout.status).toBe(200);
|
|
53
|
+
expect(await store.keys()).toEqual(["auth:abc@test.com"]);
|
|
54
|
+
|
|
55
|
+
const login = await api.post("/auth/login/email", CREDENTIALS);
|
|
56
|
+
expect(login.status).toBe(200);
|
|
57
|
+
expect(await store.keys()).toEqual([
|
|
58
|
+
"auth:abc@test.com",
|
|
59
|
+
"session:" + login.data.token,
|
|
60
|
+
]);
|
|
77
61
|
});
|
|
78
62
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import server, { cookies } from "../index.js";
|
|
2
|
+
|
|
3
|
+
describe("set-cookie", () => {
|
|
4
|
+
const app = server()
|
|
5
|
+
.get("/hello", () => {
|
|
6
|
+
return cookies({ hello: "world" }).send();
|
|
7
|
+
})
|
|
8
|
+
.get("/multiple", () => {
|
|
9
|
+
return cookies({ a: "b", c: "d" }).send();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("sets the right cookie", async () => {
|
|
13
|
+
const api = app.test();
|
|
14
|
+
const res = await api.get("/hello");
|
|
15
|
+
expect(res.headers["set-cookie"]).toBe("hello=world");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("can set multiple cookies", async () => {
|
|
19
|
+
const api = app.test();
|
|
20
|
+
const res = await api.get("/multiple");
|
|
21
|
+
expect(res.headers["set-cookie"]).toEqual(["a=b", "c=d"]);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// Takes an object and returns a string with the proper cookie values
|
|
2
2
|
export default function createCookies(cookies) {
|
|
3
|
-
if (!cookies || !Object.keys(cookies).length) return
|
|
4
|
-
return Object.entries(cookies)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
.join(";");
|
|
3
|
+
if (!cookies || !Object.keys(cookies).length) return [];
|
|
4
|
+
return Object.entries(cookies).map(([key, val]) => {
|
|
5
|
+
if (typeof val === "string") {
|
|
6
|
+
val = { value: val, path };
|
|
7
|
+
}
|
|
8
|
+
const { value, path } = val;
|
|
9
|
+
return `${key}=${value}${path ? ";Path=" + path : ""}`;
|
|
10
|
+
});
|
|
13
11
|
}
|
package/src/index.js
CHANGED
|
@@ -196,3 +196,55 @@ server.prototype.router = function (basePath, router) {
|
|
|
196
196
|
}
|
|
197
197
|
return this;
|
|
198
198
|
};
|
|
199
|
+
|
|
200
|
+
server.prototype.test = function () {
|
|
201
|
+
let cookie = "";
|
|
202
|
+
const fetch = async (path, options = {}) => {
|
|
203
|
+
if (!options.headers) options.headers = {};
|
|
204
|
+
if (options.body && typeof options.body !== "string") {
|
|
205
|
+
options.headers["content-type"] = "application/json";
|
|
206
|
+
options.body = JSON.stringify(options.body);
|
|
207
|
+
}
|
|
208
|
+
if (cookie && !options.headers.cookie) {
|
|
209
|
+
options.headers.cookie = cookie;
|
|
210
|
+
}
|
|
211
|
+
const res = await this.fetch(
|
|
212
|
+
new Request("http://localhost:3000" + path, options)
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const headers = {};
|
|
216
|
+
for (const [key, value] of res.headers.entries()) {
|
|
217
|
+
if (headers[key]) {
|
|
218
|
+
if (!Array.isArray(headers[key])) {
|
|
219
|
+
headers[key] = [headers[key]];
|
|
220
|
+
}
|
|
221
|
+
headers[key].push(value);
|
|
222
|
+
} else {
|
|
223
|
+
headers[key] = value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let data;
|
|
227
|
+
if (headers["set-cookie"]) {
|
|
228
|
+
// TODO: this should really be a smart merge of the 2
|
|
229
|
+
cookie = headers["set-cookie"];
|
|
230
|
+
}
|
|
231
|
+
if (headers["content-type"]?.includes("application/json")) {
|
|
232
|
+
data = await res.json();
|
|
233
|
+
} else {
|
|
234
|
+
data = await res.text();
|
|
235
|
+
}
|
|
236
|
+
return { status: res.status, headers, data };
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
get: (path, options) => fetch(path, { method: "get", ...options }),
|
|
240
|
+
head: (path, options) => fetch(path, { method: "head", ...options }),
|
|
241
|
+
post: (path, body, options) =>
|
|
242
|
+
fetch(path, { method: "post", body, ...options }),
|
|
243
|
+
put: (path, body, options) =>
|
|
244
|
+
fetch(path, { method: "put", body, ...options }),
|
|
245
|
+
patch: (path, body, options) =>
|
|
246
|
+
fetch(path, { method: "patch", body, ...options }),
|
|
247
|
+
delete: (path, options) => fetch(path, { method: "delete", ...options }),
|
|
248
|
+
options: (path, options) => fetch(path, { method: "options", ...options }),
|
|
249
|
+
};
|
|
250
|
+
};
|
package/src/index.test.js
CHANGED
|
@@ -1,59 +1,50 @@
|
|
|
1
1
|
import server, { status } from "./index.js";
|
|
2
2
|
|
|
3
3
|
describe("return different types", () => {
|
|
4
|
-
const
|
|
4
|
+
const api = server()
|
|
5
5
|
.get("/", () => "Hello world")
|
|
6
6
|
.get("/text", () => "Hello world")
|
|
7
7
|
.get("/array", () => ["Hello world"])
|
|
8
8
|
.get("/object", () => ({ hello: "world" }))
|
|
9
|
-
.get("/status", () => 201)
|
|
9
|
+
.get("/status", () => 201)
|
|
10
|
+
.test();
|
|
10
11
|
|
|
11
12
|
it("can get the plain text", async () => {
|
|
12
|
-
const
|
|
13
|
-
expect(
|
|
13
|
+
const { data } = await api.get("/text");
|
|
14
|
+
expect(data).toBe("Hello world");
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
it("can get the array", async () => {
|
|
17
|
-
const
|
|
18
|
-
expect(
|
|
18
|
+
const { data } = await api.get("/array");
|
|
19
|
+
expect(data).toEqual(["Hello world"]);
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
it("can get the object", async () => {
|
|
22
|
-
const
|
|
23
|
-
expect(
|
|
23
|
+
const { data } = await api.get("/object");
|
|
24
|
+
expect(data).toEqual({ hello: "world" });
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
it("can get the status", async () => {
|
|
27
|
-
const
|
|
28
|
-
expect(
|
|
28
|
+
const { status } = await api.get("/status");
|
|
29
|
+
expect(status).toBe(201);
|
|
29
30
|
});
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
describe("simple post works", () => {
|
|
33
|
-
const
|
|
34
|
+
const api = server()
|
|
35
|
+
.post("/", (ctx) => status(201).send(ctx.body))
|
|
36
|
+
.test();
|
|
34
37
|
|
|
35
38
|
it("can post new data", async () => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body: "New Data",
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
expect(res.status).toBe(201);
|
|
44
|
-
expect(await res.text()).toBe("New Data");
|
|
39
|
+
const { data, status } = await api.post("/", "New Data");
|
|
40
|
+
expect(status).toBe(201);
|
|
41
|
+
expect(data).toBe("New Data");
|
|
45
42
|
});
|
|
46
43
|
|
|
47
44
|
it("will return JSON", async () => {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
headers: { "content-type": "application/json" },
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
expect(res.status).toBe(201);
|
|
57
|
-
expect(await res.json()).toEqual({ hello: "world" });
|
|
45
|
+
const { data, status, headers } = await api.post("/", { hello: "world" });
|
|
46
|
+
expect(status).toBe(201);
|
|
47
|
+
expect(data).toEqual({ hello: "world" });
|
|
48
|
+
expect(headers["content-type"]).toBe("application/json");
|
|
58
49
|
});
|
|
59
50
|
});
|
package/src/parseResponse.js
CHANGED
|
@@ -61,7 +61,9 @@ export default async function parseResponse(out, ctx) {
|
|
|
61
61
|
// Cookies to headers
|
|
62
62
|
if (ctx.options.cookies) {
|
|
63
63
|
if (Object.keys(ctx.res.cookies).length) {
|
|
64
|
-
|
|
64
|
+
createCookies(ctx.res.cookies).forEach((cookie) => {
|
|
65
|
+
ctx.res.headers.append("set-cookie", cookie);
|
|
66
|
+
});
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
package/src/reply.js
CHANGED
|
@@ -11,8 +11,11 @@ function Reply() {
|
|
|
11
11
|
|
|
12
12
|
// INTERNAL
|
|
13
13
|
Reply.prototype.generateHeaders = function () {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const headers = new Headers(this.res.headers);
|
|
15
|
+
createCookies(this.res.cookies).forEach((cookie) => {
|
|
16
|
+
headers.append("set-cookie", cookie);
|
|
17
|
+
});
|
|
18
|
+
return headers;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
// PARTIAL
|
package/src/router.test.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import server, { router, status } from "./index.js";
|
|
2
2
|
|
|
3
|
-
const url = (path, options = {}) =>
|
|
4
|
-
new Request("http://localhost:3000" + path, options);
|
|
5
|
-
|
|
6
3
|
describe("can route properly", () => {
|
|
7
|
-
const
|
|
4
|
+
const apiRouter = router()
|
|
8
5
|
.get("/hello", (ctx) => "Hello " + ctx.url.pathname)
|
|
9
6
|
.put("/hello", (ctx) => "Hello " + ctx.url.pathname)
|
|
10
7
|
.post("/hello", (ctx) => "Hello " + ctx.url.pathname);
|
|
11
8
|
|
|
12
9
|
const app = server()
|
|
13
|
-
.router("/",
|
|
14
|
-
.router("/api/",
|
|
10
|
+
.router("/", apiRouter)
|
|
11
|
+
.router("/api/", apiRouter)
|
|
15
12
|
.get("/", () => "Fallback");
|
|
13
|
+
const api = app.test();
|
|
16
14
|
|
|
17
15
|
// INTERNAL - so this might change in the future
|
|
18
16
|
it("has the correct structure", () => {
|
|
@@ -21,38 +19,39 @@ describe("can route properly", () => {
|
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
it("can get fallback when nothing matches", async () => {
|
|
24
|
-
const res = await
|
|
25
|
-
expect(
|
|
22
|
+
const res = await api.get("/");
|
|
23
|
+
expect(res.data).toBe("Fallback");
|
|
26
24
|
});
|
|
27
25
|
|
|
28
26
|
it("can get the base get", async () => {
|
|
29
|
-
const res = await
|
|
30
|
-
expect(
|
|
27
|
+
const res = await api.get("/hello");
|
|
28
|
+
expect(res.data).toBe("Hello /hello");
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
it("can get the nested get", async () => {
|
|
34
|
-
const res = await
|
|
35
|
-
expect(
|
|
32
|
+
const res = await api.get("/api/hello");
|
|
33
|
+
expect(res.data).toBe("Hello /api/hello");
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
it("can post to the base get", async () => {
|
|
39
|
-
const res = await
|
|
40
|
-
expect(
|
|
37
|
+
const res = await api.post("/hello");
|
|
38
|
+
expect(res.data).toBe("Hello /hello");
|
|
41
39
|
});
|
|
42
40
|
|
|
43
41
|
it("can post to the nested get", async () => {
|
|
44
|
-
const res = await
|
|
45
|
-
expect(
|
|
42
|
+
const res = await api.post("/api/hello");
|
|
43
|
+
expect(res.data).toBe("Hello /api/hello");
|
|
46
44
|
});
|
|
47
45
|
|
|
48
46
|
it("no status reuse", async () => {
|
|
49
|
-
const
|
|
47
|
+
const api = server()
|
|
50
48
|
.get("/a", () => status(201).send("hello"))
|
|
51
49
|
.get("/b", () => ({ hello: "bye" }))
|
|
52
|
-
.get("/", () => "Fallback")
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
.get("/", () => "Fallback")
|
|
51
|
+
.test();
|
|
52
|
+
const { status: statusA } = await api.get("/a");
|
|
53
|
+
expect(statusA).toBe(201);
|
|
54
|
+
const { status: statusB } = await api.get("/b");
|
|
55
|
+
expect(statusB).toBe(200);
|
|
57
56
|
});
|
|
58
57
|
});
|
package/src/session.test.js
CHANGED
|
@@ -2,64 +2,64 @@ import kv from "polystore";
|
|
|
2
2
|
|
|
3
3
|
import server from "./index.js";
|
|
4
4
|
|
|
5
|
-
const url = (path, options = {}) =>
|
|
6
|
-
new Request("http://localhost:3000" + path, {
|
|
7
|
-
headers: { cookie: "session=REqA2l022l8Q0tuIRtqLOPUy" },
|
|
8
|
-
...options,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
5
|
describe("session", () => {
|
|
12
6
|
const store = kv(new Map());
|
|
13
|
-
const
|
|
7
|
+
const api = server({ store })
|
|
14
8
|
.get("/hello", (ctx) => "Hello " + ctx.session.a)
|
|
15
9
|
.post("/hello", (ctx) => {
|
|
16
10
|
if (!ctx.session.a) ctx.session.a = 0;
|
|
17
11
|
ctx.session.a += 1;
|
|
18
12
|
return "Bye " + ctx.session.a;
|
|
19
13
|
})
|
|
20
|
-
.get("/", () => "Fallback")
|
|
14
|
+
.get("/", () => "Fallback")
|
|
15
|
+
.test();
|
|
21
16
|
|
|
22
17
|
it("can get the nested get", async () => {
|
|
18
|
+
const cookie = "session=REqA2l022l8Q0tuIRtqLOPUy";
|
|
19
|
+
const options = { headers: { cookie } };
|
|
23
20
|
await store.set("session:REqA2l022l8Q0tuIRtqLOPUy", { a: 0 });
|
|
24
21
|
|
|
25
|
-
const res = await
|
|
26
|
-
expect(
|
|
22
|
+
const res = await api.get("/hello", options);
|
|
23
|
+
expect(res.data).toBe("Hello 0");
|
|
27
24
|
|
|
28
|
-
const res2 = await
|
|
29
|
-
expect(
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const res2 = await api.post("/hello", {}, options);
|
|
26
|
+
expect(res2.data).toBe("Bye 1");
|
|
27
|
+
|
|
28
|
+
const res3 = await api.get("/hello", options);
|
|
29
|
+
expect(res3.data).toBe("Hello 1");
|
|
32
30
|
expect(await store.get("session:REqA2l022l8Q0tuIRtqLOPUy")).toEqual({
|
|
33
31
|
a: 1,
|
|
34
32
|
});
|
|
35
33
|
|
|
36
|
-
const res4 = await
|
|
37
|
-
expect(
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const res4 = await api.post("/hello", {}, options);
|
|
35
|
+
expect(res4.data).toBe("Bye 2");
|
|
36
|
+
|
|
37
|
+
const res5 = await api.get("/hello", options);
|
|
38
|
+
expect(res5.data).toBe("Hello 2");
|
|
40
39
|
expect(await store.get("session:REqA2l022l8Q0tuIRtqLOPUy")).toEqual({
|
|
41
40
|
a: 2,
|
|
42
41
|
});
|
|
43
42
|
});
|
|
43
|
+
});
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
describe("missing store", () => {
|
|
46
|
+
const api = server({ store: null })
|
|
46
47
|
.get("/read", (ctx) => "Bye " + ctx.session.a)
|
|
47
48
|
.get("/write", (ctx) => {
|
|
48
49
|
ctx.session.a = "hello";
|
|
49
50
|
return "All good";
|
|
50
|
-
})
|
|
51
|
+
})
|
|
52
|
+
.test();
|
|
51
53
|
|
|
52
54
|
it("cannot read a session without a store", async () => {
|
|
53
|
-
const res = await
|
|
54
|
-
const body = await res.text();
|
|
55
|
+
const res = await api.get("/read");
|
|
55
56
|
expect(res.status).toBe(500);
|
|
56
|
-
expect(
|
|
57
|
+
expect(res.data).toBe("You need a 'store' to read 'ctx.session.a'");
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
it("cannot write a session without a store", async () => {
|
|
60
|
-
const res = await
|
|
61
|
-
const body = await res.text();
|
|
61
|
+
const res = await api.get("/write");
|
|
62
62
|
expect(res.status).toBe(500);
|
|
63
|
-
expect(
|
|
63
|
+
expect(res.data).toBe("You need a 'store' to write 'ctx.session.a'");
|
|
64
64
|
});
|
|
65
65
|
});
|
package/src/url.test.js
CHANGED
|
@@ -2,23 +2,25 @@ import server from "./index.js";
|
|
|
2
2
|
|
|
3
3
|
describe("can match the url", () => {
|
|
4
4
|
it("stops at the first matching route", async () => {
|
|
5
|
-
const
|
|
5
|
+
const api = server()
|
|
6
6
|
.get("/:id", (ctx) => ctx.url.params)
|
|
7
|
-
.get("/*", (ctx) => ctx.url.params)
|
|
7
|
+
.get("/*", (ctx) => ctx.url.params)
|
|
8
|
+
.test();
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
-
expect(
|
|
10
|
+
const { data, headers } = await api.get("/hello");
|
|
11
|
+
expect(data).toEqual({ id: "hello" });
|
|
12
|
+
expect(headers["content-type"]).toEqual("application/json");
|
|
11
13
|
});
|
|
12
14
|
|
|
13
15
|
it("but it doesn't if it's a use", async () => {
|
|
14
|
-
const
|
|
15
|
-
.use(() => {
|
|
16
|
-
// No-op
|
|
17
|
-
})
|
|
16
|
+
const api = server()
|
|
17
|
+
.use(() => {}) // No-op
|
|
18
18
|
.get("/:id", (ctx) => ctx.url.params)
|
|
19
|
-
.get("/*", (ctx) => ctx.url.params)
|
|
19
|
+
.get("/*", (ctx) => ctx.url.params)
|
|
20
|
+
.test();
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
expect(
|
|
22
|
+
const { data, headers, ...rest } = await api.get("/hello");
|
|
23
|
+
expect(data).toEqual({ id: "hello" });
|
|
24
|
+
expect(headers["content-type"]).toEqual("application/json");
|
|
23
25
|
});
|
|
24
26
|
});
|