Skip to content

Commit 2a553c2

Browse files
authored
Add test and rewrite asAsync (#66)
* Add qs * Add express middleware test * Reorganize middleware test * Add express integration test * Rewrite asAsync and add test
1 parent e2cee87 commit 2a553c2

File tree

9 files changed

+744
-70
lines changed

9 files changed

+744
-70
lines changed

package-lock.json

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

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"license": "ISC",
1919
"devDependencies": {
2020
"@types/express": "^4.17.21",
21+
"@types/qs": "^6.9.15",
22+
"@types/supertest": "^6.0.2",
2123
"@typescript-eslint/eslint-plugin": "^7.0.0",
2224
"@typescript-eslint/parser": "^7.0.0",
2325
"@vitest/coverage-v8": "^2.0.0",
@@ -27,11 +29,12 @@
2729
"express": "^4.19.2",
2830
"npm-run-all2": "^6.0.0",
2931
"prettier": "^3.0.0",
32+
"supertest": "^7.0.0",
3033
"tsup": "^8.0.0",
3134
"tsx": "^4.0.0",
3235
"typescript": "^5.4.5",
33-
"zod": "^3.23.8",
34-
"vitest": "^2.0.0"
36+
"vitest": "^2.0.0",
37+
"zod": "^3.23.8"
3538
},
3639
"files": [
3740
"dist",

src/common/spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ export const Method = [
2424
] as const;
2525
export type Method = (typeof Method)[number];
2626
export type CaseInsensitiveMethod = Method | Uppercase<Method>;
27+
export const isMethod = (x: unknown): x is Method =>
28+
Method.includes(x as Method);
2729

2830
export type ApiEndpoint = Partial<Record<Method, ApiSpec>>;
31+
export type AnyApiEndpoint = Partial<Record<Method, AnyApiSpec>>;
2932
type AsJsonApiEndpoint<AE extends ApiEndpoint> = {
3033
// FIXME: NonNullableでいいんだっけ?
3134
[M in keyof AE & Method]: AsJsonApiSpec<NonNullable<AE[M]>>;
3235
};
3336
export type ApiEndpoints = { [Path in string]: ApiEndpoint };
37+
export type AnyApiEndpoints = { [Path in string]: AnyApiEndpoint };
3438

3539
export interface ApiSpec<
3640
ParamKeys extends string = string,
@@ -56,6 +60,8 @@ export interface ApiSpec<
5660
headers?: RequestHeaders;
5761
resHeaders?: ResponseHeaders;
5862
}
63+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64+
export type AnyApiSpec = ApiSpec<string, any, any, any, any, any, any>;
5965

6066
type JsonHeader = {
6167
"Content-Type": "application/json";

0 commit comments

Comments
 (0)