Skip to content

Commit da3f398

Browse files
authored
refactor(type-test): use new runner for types tests (#1690)
* refactor(type-test): use new runner for types tests * fix(ci): update ci
1 parent 529d5db commit da3f398

File tree

7 files changed

+163
-210
lines changed

7 files changed

+163
-210
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,22 @@ jobs:
5353
- run: pnpm run build
5454
- run: pnpm run test:coverage
5555
- uses: codecov/[email protected]
56+
57+
test-types:
58+
runs-on: ubuntu-22.04
59+
strategy:
60+
matrix:
61+
node: ['20']
62+
steps:
63+
- uses: actions/[email protected]
64+
- uses: pnpm/[email protected]
65+
- name: Use Node.js
66+
uses: actions/[email protected]
67+
with:
68+
node-version: ${{ matrix.node }}
69+
check-latest: true
70+
cache: 'pnpm'
71+
- run: pnpm install
72+
- run: pnpm run build
73+
- run: pnpm run test:types
74+

jest.config.tsd.mjs

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

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"@scaleway/tsconfig": "workspace:*",
2929
"@testing-library/jest-dom": "6.4.2",
3030
"@testing-library/react": "14.2.2",
31-
"@tsd/typescript": "5.3.3",
3231
"@types/jest": "29.5.12",
3332
"@types/node": "20.11.30",
3433
"@types/react": "18.2.67",
@@ -41,7 +40,6 @@
4140
"jest-environment-jsdom": "29.7.0",
4241
"jest-junit": "16.0.0",
4342
"jest-localstorage-mock": "2.4.26",
44-
"jest-runner-tsd": "6.0.0",
4543
"lint-staged": "15.2.2",
4644
"mockdate": "3.0.5",
4745
"prettier": "3.2.5",
@@ -52,7 +50,7 @@
5250
"rollup-plugin-dts": "6.1.0",
5351
"rollup-plugin-preserve-shebangs": "0.2.0",
5452
"rollup-plugin-visualizer": "5.12.0",
55-
"tsd-lite": "0.8.2",
53+
"tstyche": "1.1.0 ",
5654
"typescript": "5.4.3",
5755
"wait-for-expect": "3.0.2"
5856
},
@@ -66,7 +64,7 @@
6664
"test": "TZ=UTC jest",
6765
"test:watch": "pnpm run test --watch",
6866
"test:coverage": "pnpm run test --coverage",
69-
"test:types": "jest -c jest.config.tsd.mjs",
67+
"test:types": "tstyche",
7068
"release": "pnpm build && pnpm changeset publish",
7169
"prepare": "husky install"
7270
},
Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,69 @@
11
/* eslint-disable react-hooks/rules-of-hooks */
2-
import { expectError, expectType } from 'tsd-lite'
2+
import { expect, test } from 'tstyche'
33
import { useI18n } from '../usei18n'
44

5-
const { namespaceTranslation } = useI18n<{
6-
hello: 'world'
7-
'doe.john': 'John Doe'
8-
'doe.jane': 'Jane Doe'
9-
'doe.child': 'Child is {name}'
10-
'describe.john': '{name} is {age} years old'
11-
}>()
12-
13-
// Single key
14-
expectError(namespaceTranslation('hello'))
15-
16-
// Multiple keys
17-
expectError(namespaceTranslation('doe.john'))
18-
const scopedT1 = namespaceTranslation('doe')
19-
expectType<string>(scopedT1('john'))
20-
expectError(scopedT1('doesnotexists'))
21-
22-
// With a param
23-
const scopedT2 = namespaceTranslation('doe')
24-
expectError(scopedT2('child'))
25-
expectType<string>(
26-
scopedT2('child', {
27-
name: 'Name',
28-
}),
29-
)
30-
expectError(
31-
scopedT2('doesnotexists', {
32-
name: 'Name',
33-
}),
34-
)
35-
expectError(
36-
scopedT2('child', {
37-
doesnotexists: 'Name',
38-
}),
39-
)
40-
expectError(scopedT2('child', {}))
41-
expectError(scopedT2('child'))
42-
43-
// With multiple params
44-
const scopedT3 = namespaceTranslation('describe')
45-
expectType<string>(
46-
scopedT3('john', {
47-
age: '30',
48-
name: 'John',
49-
}),
50-
)
51-
expectError(scopedT3('john', {}))
52-
expectError(scopedT3('john'))
53-
54-
// Required generic
55-
const { namespaceTranslation: namespaceTranslation2 } = useI18n()
56-
expectError(namespaceTranslation2('test'))
5+
test('i18n - namespaceTranslation', () => {
6+
const { namespaceTranslation } = useI18n<{
7+
hello: 'world'
8+
'doe.john': 'John Doe'
9+
'doe.jane': 'Jane Doe'
10+
'doe.child': 'Child is {name}'
11+
'describe.john': '{name} is {age} years old'
12+
}>()
13+
14+
// Single key
15+
expect(namespaceTranslation('hello')).type.toRaiseError(
16+
`Argument of type '"hello"' is not assignable to parameter of type '"doe" | "describe"'`,
17+
)
18+
19+
// Multiple keys
20+
expect(namespaceTranslation('doe.john')).type.toRaiseError(
21+
`Argument of type '"doe.john"' is not assignable to parameter of type '"doe" | "describe"'`,
22+
)
23+
24+
expect(namespaceTranslation('doe')('john')).type.toEqual<string>()
25+
26+
expect(namespaceTranslation('doe')('doesnotexists')).type.toRaiseError(
27+
`Expected 2 arguments, but got 1.`,
28+
)
29+
30+
// With a param
31+
expect(namespaceTranslation('doe')('child')).type.toRaiseError(
32+
`Expected 2 arguments, but got 1.`,
33+
)
34+
expect(
35+
namespaceTranslation('doe')('child', {
36+
name: 'Name',
37+
}),
38+
).type.toEqual<string>()
39+
expect(
40+
namespaceTranslation('doe')('doesnotexists', {
41+
name: 'Name',
42+
}),
43+
).type.toRaiseError()
44+
expect(
45+
namespaceTranslation('doe')('child', {
46+
doesnotexists: 'Name',
47+
}),
48+
).type.toRaiseError()
49+
50+
expect(namespaceTranslation('doe')('child', {})).type.toRaiseError()
51+
expect(namespaceTranslation('doe')('child')).type.toRaiseError()
52+
53+
// With multiple params
54+
expect(
55+
namespaceTranslation('describe')('john', {
56+
age: '30',
57+
name: 'John',
58+
}),
59+
).type.toEqual<string>()
60+
61+
expect(namespaceTranslation('describe')('john', {})).type.toRaiseError()
62+
expect(namespaceTranslation('describe')('john')).type.toRaiseError()
63+
64+
// Required generic
65+
const { namespaceTranslation: namespaceTranslation2 } = useI18n()
66+
expect(namespaceTranslation2('test')).type.toRaiseError(
67+
`Argument of type '"test"' is not assignable to parameter of type`,
68+
)
69+
})
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint-disable react-hooks/rules-of-hooks */
2-
import { expectError, expectType } from 'tsd-lite'
3-
import { useI18n, useTranslation } from '../usei18n'
1+
import { expect, test } from 'tstyche'
2+
import { useI18n } from '../usei18n'
43

54
const { t } = useI18n<{
65
hello: 'world'
@@ -10,55 +9,56 @@ const { t } = useI18n<{
109
'describe.john': '{name} is {age} years old'
1110
}>()
1211

13-
// Single key
14-
expectType<string>(t('hello'))
15-
expectError(t('keydoesnotexists'))
12+
test('i18n - t', () => {
13+
expect(t('hello')).type.toEqual<string>()
14+
// Single key
15+
expect(t('keydoesnotexists')).type.toRaiseError()
1616

17-
// Multiple keys
18-
expectType<string>(t('doe.john'))
19-
expectError(t('doe.doesnotexists'))
17+
// Multiple keys
18+
expect(t('doe.john')).type.toEqual<string>()
19+
expect(t('doe.doesnotexists')).type.toRaiseError()
2020

21-
// With a param
22-
expectError(t('doe.child'))
23-
expectType<string>(
24-
t('doe.child', {
25-
name: 'Name',
26-
}),
27-
)
28-
expectError(
29-
t('doe.doesnotexists', {
30-
name: 'Name',
31-
}),
32-
)
33-
expectError(
34-
t('doe.child', {
35-
doesnotexists: 'Name',
36-
}),
37-
)
38-
expectError(t('doe.child', {}))
39-
expectError(t('doe.child'))
21+
// With a param
22+
expect(
23+
t('doe.child', {
24+
name: 'Name',
25+
}),
26+
).type.toEqual<string>()
27+
expect(
28+
t('doe.doesnotexists', {
29+
name: 'Name',
30+
}),
31+
).type.toRaiseError()
4032

41-
// With multiple params
42-
expectType<string>(
43-
t('describe.john', {
44-
age: '30',
45-
name: 'John',
46-
}),
47-
)
48-
expectError(t('describe.john', {}))
49-
expectError(t('describe.john'))
33+
expect(t('doe.child', {})).type.toRaiseError(
34+
"Argument of type '{}' is not assignable to parameter of type",
35+
)
5036

51-
// With react components as param value
52-
expectType<string>(
53-
t('doe.child', {
54-
name: (
55-
<p>
56-
My name is<b>John</b>
57-
</p>
58-
),
59-
}),
60-
)
37+
expect(t('doe.child')).type.toRaiseError('Expected 2 arguments, but got 1')
6138

62-
// Required generic
63-
const { t: t2 } = useI18n()
64-
expectError(t2('test'))
39+
// With multiple params
40+
expect(
41+
t('describe.john', {
42+
age: '30',
43+
name: 'John',
44+
}),
45+
).type.toEqual<string>()
46+
47+
expect(t('describe.john', {})).type.toRaiseError()
48+
expect(t('describe.john')).type.toRaiseError()
49+
50+
// With react components as param value
51+
expect(
52+
t('doe.child', {
53+
name: (
54+
<p>
55+
My name is<b>John</b>
56+
</p>
57+
),
58+
}),
59+
).type.toEqual<string>()
60+
61+
// Required generic
62+
const { t: t2 } = useI18n()
63+
expect(t2('test')).type.toRaiseError()
64+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../../../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"strict": true,
6+
"types": []
7+
},
8+
"include": ["./"],
9+
"exclude": []
10+
}

0 commit comments

Comments
 (0)