Skip to content

Commit fcc2983

Browse files
authored
chore: use TSTyche for type testing (#2234)
1 parent cea7d7d commit fcc2983

File tree

25 files changed

+208
-413
lines changed

25 files changed

+208
-413
lines changed

.github/workflows/main-suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: yarn test:ci:coverage
7373

7474
- name: Test Public Typings
75-
run: yarn test:tsd
75+
run: yarn test:types
7676

7777
- name: E2E Testing
7878
run: yarn test:e2e

jest.config.types.js

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

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"test:ci": "jest --ci --runInBand",
1313
"test:ci:coverage": "yarn test:ci --coverage",
1414
"test:e2e": "yarn workspaces foreach -p run test:e2e",
15-
"test:tsd": "jest -c jest.config.types.js",
16-
"test:all": "yarn test && yarn test:e2e && yarn test:tsd",
15+
"test:types": "tstyche",
16+
"test:all": "yarn test && yarn test:e2e && yarn test:types",
1717
"lint:types": "tsc",
1818
"lint:eslint": "eslint ./packages",
1919
"lint:all": "yarn lint:eslint && yarn lint:types",
@@ -43,7 +43,6 @@
4343
"@eslint/js": "^9.17.0",
4444
"@size-limit/preset-small-lib": "^11.1.6",
4545
"@swc/core": "^1.3.26",
46-
"@tsd/typescript": "^4.9.5",
4746
"@types/jest": "^29.4.0",
4847
"@types/mock-fs": "^4.13.1",
4948
"@types/node": "20.14.8",
@@ -57,7 +56,6 @@
5756
"jest": "^29.7.0",
5857
"jest-environment-jsdom": "^29.7.0",
5958
"jest-environment-node-single-context": "^29.4.0",
60-
"jest-runner-tsd": "^4.0.0",
6159
"lerna": "^8.1.9",
6260
"lint-staged": "^13.1.0",
6361
"memory-fs": "^0.5.0",
@@ -72,6 +70,7 @@
7270
"strip-ansi": "^6.0.1",
7371
"swc-node": "^1.0.0",
7472
"ts-jest": "^29.2.4",
73+
"tstyche": "^4.0.0-rc.0",
7574
"typescript": "^5.7.2",
7675
"typescript-eslint": "^8.18.1"
7776
},

packages/conf/__typetests__/index.test-d.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
FallbackLocales,
55
LinguiConfig,
66
} from "@lingui/conf"
7-
import { expectAssignable } from "tsd"
7+
import { expect } from "tstyche"
88

99
// only required props
10-
expectAssignable<LinguiConfig>({
10+
expect({
1111
locales: ["en", "pl"],
12-
})
12+
}).type.toBeAssignableTo<LinguiConfig>()
1313

1414
// all props
15-
expectAssignable<LinguiConfig>({
15+
expect({
1616
catalogs: [
1717
{
1818
path: "<rootDir>/locale/{locale}/messages",
@@ -33,19 +33,19 @@ expectAssignable<LinguiConfig>({
3333
tsExperimentalDecorators: false,
3434
},
3535
fallbackLocales: {} as FallbackLocales,
36-
format: "po",
36+
format: "po" as const,
3737
formatOptions: { origins: true, lineNumbers: true },
3838
locales: [],
39-
orderBy: "messageId",
39+
orderBy: "messageId" as const,
4040
pseudoLocale: "",
4141
rootDir: ".",
42-
runtimeConfigModule: ["@lingui/core", "i18n"],
42+
runtimeConfigModule: ["@lingui/core", "i18n"] as [string, string],
4343
sourceLocale: "",
4444
service: { name: "", apiKey: "" },
45-
})
45+
}).type.toBeAssignableTo<LinguiConfig>()
4646

4747
// custom extractors
48-
expectAssignable<LinguiConfig>({
48+
expect({
4949
locales: ["en", "pl"],
5050
extractors: [
5151
{
@@ -58,18 +58,18 @@ expectAssignable<LinguiConfig>({
5858
) => {},
5959
},
6060
],
61-
})
61+
}).type.toBeAssignableTo<LinguiConfig>()
6262

6363
// runtimeConfigModule
64-
expectAssignable<LinguiConfig>({
64+
expect({
6565
locales: ["en", "pl"],
66-
runtimeConfigModule: ["./custom-i18n-config", "i18n"],
67-
})
66+
runtimeConfigModule: ["./custom-i18n-config", "i18n"] as [string, string],
67+
}).type.toBeAssignableTo<LinguiConfig>()
6868

69-
expectAssignable<LinguiConfig>({
69+
expect({
7070
locales: ["en", "pl"],
7171
runtimeConfigModule: {
72-
i18n: ["./custom-config", "i18n"],
73-
Trans: ["./custom-config", "Trans"],
72+
i18n: ["./custom-config", "i18n"] as [string, string],
73+
Trans: ["./custom-config", "Trans"] as [string, string],
7474
},
75-
})
75+
}).type.toBeAssignableTo<LinguiConfig>()

packages/conf/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
],
3939
"devDependencies": {
4040
"@lingui/jest-mocks": "*",
41-
"tsd": "^0.26.1",
4241
"unbuild": "^2.0.0"
4342
}
4443
}
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
1-
import { expectType } from "tsd"
21
import { i18n } from "@lingui/core"
2+
import { expect } from "tstyche"
33

4-
expectType<string>(i18n._("message.id"))
5-
expectType<string>(
4+
expect(i18n._("message.id")).type.toBe<string>()
5+
expect(
66
i18n._({
77
id: "message.id",
88
message: "Message",
99
})
10-
)
11-
expectType<string>(
10+
).type.toBe<string>()
11+
expect(
1212
i18n._(
1313
"message.id",
1414
{ name: "Tim" },
1515
{ message: "Hello {name}", comment: "", formats: {} }
1616
)
17-
)
18-
expectType<string>(
19-
i18n._(
20-
// @ts-expect-error you could not use message descriptor together with rest of params
21-
{
22-
id: "message.id",
23-
message: "Message",
24-
},
25-
{ name: "Tim" },
26-
{ message: "Hello {name}", comment: "", formats: {} }
27-
)
17+
).type.toBe<string>()
18+
expect(i18n._).type.not.toBeCallableWith(
19+
// cannot use message descriptor together with rest of params
20+
{
21+
id: "message.id",
22+
message: "Message",
23+
},
24+
{ name: "Tim" },
25+
{ message: "Hello {name}", comment: "", formats: {} }
2826
)
2927

30-
expectType<string>(i18n.t("message.id"))
31-
expectType<string>(
28+
expect(i18n.t("message.id")).type.toBe<string>()
29+
expect(
3230
i18n.t({
3331
id: "message.id",
3432
message: "Message",
3533
})
36-
)
34+
).type.toBe<string>()
3735

38-
expectType<string>(
36+
expect(
3937
i18n.t(
4038
"message.id",
4139
{ name: "Tim" },
4240
{ message: "Hello {name}", comment: "", formats: {} }
4341
)
44-
)
42+
).type.toBe<string>()
4543

46-
expectType<string>(
47-
i18n.t(
48-
// @ts-expect-error you could not use message descriptor together with rest of params
49-
{
50-
id: "message.id",
51-
message: "Message",
52-
},
53-
{ name: "Tim" },
54-
{ message: "Hello {name}", comment: "", formats: {} }
55-
)
44+
expect(i18n.t).type.not.toBeCallableWith(
45+
// cannot use message descriptor together with rest of params
46+
{
47+
id: "message.id",
48+
message: "Message",
49+
},
50+
{ name: "Tim" },
51+
{ message: "Hello {name}", comment: "", formats: {} }
5652
)
5753

58-
i18n.load("cs", {})
59-
i18n.load({ cs: {} })
60-
// @ts-expect-error this is an invalid call
61-
i18n.load({ cs: {} }, {})
54+
expect(i18n.load).type.toBeCallableWith("cs", {})
55+
expect(i18n.load).type.toBeCallableWith({ cs: {} })
56+
expect(i18n.load).type.not.toBeCallableWith({ cs: {} }, {})

0 commit comments

Comments
 (0)