Skip to content

Commit f4090b0

Browse files
authored
Merge pull request #1432 from mrazauskas/use-tstyche
chore: use TSTyche for type testing
2 parents b05de47 + 7e20f41 commit f4090b0

File tree

43 files changed

+516
-1761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+516
-1761
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test:sast:sandworm": "sandworm-audit --skip-all --show-tips false",
2424
"test:sast:semgrep": "semgrep scan --config auto",
2525
"test:sast:trufflehog": "trufflehog filesystem --only-verified --log-level=-1 ./",
26-
"test:types": "ls packages | xargs -I {} tsd packages/{}",
26+
"test:types": "tstyche",
2727
"test:perf": "node --test ./**/*.perf.js",
2828
"test:dast": "npm run test:dast:fuzz",
2929
"test:dast:fuzz": "node --test ./**/*.fuzz.js",
@@ -70,7 +70,7 @@
7070
"fast-check": "^4.0.0",
7171
"husky": "^9.0.0",
7272
"tinybench": "^4.0.0",
73-
"tsd": "^0.33.0",
73+
"tstyche": "^4.3.0",
7474
"typescript": "^5.0.0"
7575
},
7676
"workspaces": [

packages/appconfig/index.test-d.ts

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import middy from "@middy/core";
33
import { getInternal } from "@middy/util";
44
import type { Context as LambdaContext } from "aws-lambda";
55
import { captureAWSv3Client } from "aws-xray-sdk";
6-
import { expectType } from "tsd";
6+
import { expect } from "tstyche";
77
import appConfig, { appConfigReq, type Context } from "./index.js";
88

99
const options = {
@@ -21,28 +21,20 @@ const options = {
2121
cacheKey: "some-key",
2222
cacheExpiry: 60 * 60 * 5,
2323
setToContext: false,
24-
} as const;
24+
};
2525

2626
// use with default options
27-
expectType<middy.MiddlewareObj<unknown, any, Error, LambdaContext>>(
28-
appConfig(),
29-
);
27+
expect(appConfig()).type.toBe<
28+
middy.MiddlewareObj<unknown, any, Error, LambdaContext>
29+
>();
3030

3131
// use with all options
32-
expectType<middy.MiddlewareObj<unknown, any, Error, Context<typeof options>>>(
33-
appConfig(options),
34-
);
32+
expect(appConfig(options)).type.toBe<
33+
middy.MiddlewareObj<unknown, any, Error, Context<typeof options>>
34+
>();
3535

3636
// use with setToContext: false
37-
expectType<
38-
middy.MiddlewareObj<
39-
unknown,
40-
any,
41-
Error,
42-
LambdaContext,
43-
Record<"config", unknown>
44-
>
45-
>(
37+
expect(
4638
appConfig({
4739
...options,
4840
fetchData: {
@@ -54,18 +46,18 @@ expectType<
5446
},
5547
setToContext: false,
5648
}),
57-
);
58-
59-
// use with setToContext: true
60-
expectType<
49+
).type.toBe<
6150
middy.MiddlewareObj<
6251
unknown,
6352
any,
6453
Error,
65-
LambdaContext & Record<"config", unknown>,
54+
LambdaContext,
6655
Record<"config", unknown>
6756
>
68-
>(
57+
>();
58+
59+
// use with setToContext: true
60+
expect(
6961
appConfig({
7062
...options,
7163
fetchData: {
@@ -77,30 +69,36 @@ expectType<
7769
},
7870
setToContext: true,
7971
}),
80-
);
72+
).type.toBe<
73+
middy.MiddlewareObj<
74+
unknown,
75+
any,
76+
Error,
77+
LambdaContext & Record<"config", unknown>,
78+
Record<"config", unknown>
79+
>
80+
>();
8181

82-
// @ts-expect-error - fetchData must be an object
83-
appConfig({ ...options, fetchData: "not-an-object" });
82+
expect(appConfig).type.not.toBeCallableWith({
83+
...options,
84+
fetchData: "not-an-object", // fetchData must be an object
85+
});
8486

85-
appConfig({
87+
expect(appConfig).type.not.toBeCallableWith({
8688
...options,
8789
fetchData: {
8890
config: {
89-
// @ts-expect-error - Application must be a string
90-
ApplicationIdentifier: 123,
91-
// @ts-expect-error - Configuration must be a string
92-
ConfigurationProfileIdentifier: 123,
93-
// @ts-expect-error - Environment must be a string
94-
EnvironmentIdentifier: 123,
91+
ApplicationIdentifier: 123, // Application must be a string
92+
ConfigurationProfileIdentifier: 123, // Configuration must be a string
93+
EnvironmentIdentifier: 123, // Environment must be a string
9594
},
9695
},
9796
});
9897

99-
appConfig({
98+
expect(appConfig).type.not.toBeCallableWith({
10099
...options,
101100
fetchData: {
102-
// @ts-expect-error - config must contain Application, ClientId, Configuration and Environment
103-
config: {},
101+
config: {}, // config must contain Application, ClientId, Configuration and Environment
104102
},
105103
});
106104

@@ -126,12 +124,14 @@ handler
126124
}),
127125
)
128126
.before(async (request) => {
129-
expectType<{ config1: string; config2: string; config3: number }>(
130-
request.context.config,
131-
);
127+
expect(request.context.config).type.toBe<{
128+
config1: string;
129+
config2: string;
130+
config3: number;
131+
}>();
132132

133133
const data = await getInternal("config", request);
134-
expectType<string>(data.config.config1);
134+
expect(data.config.config1).type.toBe<string>();
135135
});
136136

137137
handler
@@ -153,7 +153,9 @@ handler
153153
)
154154
.before(async (request) => {
155155
const data = await getInternal("config", request);
156-
expectType<{ config1: string; config2: string; config3: number }>(
157-
data.config,
158-
);
156+
expect(data.config).type.toBe<{
157+
config1: string;
158+
config2: string;
159+
config3: number;
160+
}>();
159161
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type middy from "@middy/core";
2-
import { expectType } from "tsd";
2+
import { expect } from "tstyche";
33

44
import cloudformationResponse from "./index.js";
55

66
// use with default options
77
const middleware = cloudformationResponse();
8-
expectType<middy.MiddlewareObj>(middleware);
8+
expect(middleware).type.toBe<middy.MiddlewareObj>();

packages/cloudformation-router/index.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type middy from "@middy/core";
2-
// import { CloudFormationCustomResourceHandler } from 'aws-lambda'
3-
import { expectType } from "tsd";
2+
// import { CloudFormationCustomResourceHandler } from "aws-lambda";
3+
import { expect } from "tstyche";
44
import cloudformationRouterHandler from "./index.js";
55

66
const createLambdaHandler: any = async () => {
@@ -25,4 +25,4 @@ const middleware = cloudformationRouterHandler([
2525
handler: deleteLambdaHandler,
2626
},
2727
]);
28-
expectType<middy.MiddyfiedHandler>(middleware);
28+
expect(middleware).type.toBe<middy.MiddyfiedHandler>();
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import type middy from "@middy/core";
2-
import { expectType } from "tsd";
2+
import { expect } from "tstyche";
33
import cloudwatchMetrics, { type Context } from "./index.js";
44

55
// use with default options
66
let middleware = cloudwatchMetrics();
7-
expectType<middy.MiddlewareObj<unknown, any, Error, Context>>(middleware);
7+
expect(middleware).type.toBe<
8+
middy.MiddlewareObj<unknown, any, Error, Context>
9+
>();
810

911
// use with all options
1012
middleware = cloudwatchMetrics({
1113
namespace: "myApp",
1214
dimensions: [{ Action: "Buy" }],
1315
});
14-
expectType<middy.MiddlewareObj<unknown, any, Error, Context>>(middleware);
16+
expect(middleware).type.toBe<
17+
middy.MiddlewareObj<unknown, any, Error, Context>
18+
>();

0 commit comments

Comments
 (0)