Skip to content

Commit 5c32c5d

Browse files
authored
Migrate type tests to TSTyche (#1988)
* chore: migrate type tests to TSTyche * fix CI * tweak CI * add `empty.ts` * add `es6-collections.ts`
1 parent ac05955 commit 5c32c5d

File tree

10 files changed

+276
-235
lines changed

10 files changed

+276
-235
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ jobs:
5050
- run: npm run type-check
5151
- run: npm run check-git-clean
5252

53-
unit-test:
54-
name: 'Build & Unit Test'
53+
test:
54+
name: 'Build & Unit Test & Type Test'
5555
runs-on: ubuntu-latest
5656
steps:
5757
- uses: actions/checkout@v2
@@ -65,7 +65,8 @@ jobs:
6565
restore-keys: ${{ runner.OS }}-node-
6666
- run: npm ci
6767
- run: npm run build
68-
- run: npm run unit-test
68+
- run: npm run test:unit
69+
- run: npm run test:types -- --target 4.5,5.0,current
6970
- run: npx size-limit
7071
- run: npm run check-git-clean
7172

@@ -90,7 +91,7 @@ jobs:
9091

9192
publish:
9293
name: 'Publish'
93-
needs: [lint, type-check, unit-test, website]
94+
needs: [lint, type-check, test, website]
9495
if: github.ref == 'refs/heads/main'
9596
runs-on: ubuntu-latest
9697
steps:

.prettierignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
dist
22
pages/generated
33
pages/out
4-
type-definitions/ts-tests/
5-
type-definitions/flow-tests/
4+
type-definitions/ts-tests/*.ts
5+
type-definitions/flow-tests/
6+
7+
!type-definitions/ts-tests/covariance.ts
8+
!type-definitions/ts-tests/deepCopy.ts
9+
!type-definitions/ts-tests/empty.ts
10+
!type-definitions/ts-tests/es6-collections.ts

package-lock.json

Lines changed: 31 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
"npm": ">=7.0.0"
5656
},
5757
"scripts": {
58-
"test": "run-s format lint type-check build unit-test",
58+
"test": "run-s format lint type-check build test:*",
59+
"test:unit": "jest",
60+
"test:types": "tstyche",
5961
"format": "npm run lint:format -- --write",
6062
"lint": "run-s lint:*",
6163
"lint:format": "prettier --check \"{__tests__,src,type-definitions,website/src,perf,resources}/**/*{.js,.ts,.tsx,.flow,.css}\"",
@@ -69,7 +71,6 @@
6971
"build:types": "cpy ./type-definitions/immutable.* dist",
7072
"build:prepare": "./resources/prepare-dist.sh",
7173
"build:stats": "node ./resources/dist-stats.mjs",
72-
"unit-test": "jest",
7374
"website:build": "cd website && next build && next-sitemap",
7475
"website:dev": "cd website && next dev",
7576
"check-git-clean": "./resources/check-git-clean.sh",
@@ -127,6 +128,7 @@
127128
"rollup": "3.28.1",
128129
"size-limit": "^8.2.6",
129130
"transducers-js": "0.4.174",
131+
"tstyche": "^1.0.0",
130132
"typescript": "5.1"
131133
},
132134
"size-limit": [

tstyche.config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://tstyche.org/schemas/config.json",
3+
"testFileMatch": [
4+
"**/type-definitions/ts-tests/covariance.ts",
5+
"**/type-definitions/ts-tests/deepCopy.ts",
6+
"**/type-definitions/ts-tests/empty.ts",
7+
"**/type-definitions/ts-tests/es6-collections.ts"
8+
]
9+
}
Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { List, Map, OrderedMap, OrderedSet, Set, Stack } from 'immutable';
1+
import { expect, test } from 'tstyche';
2+
import {
3+
List,
4+
Map,
5+
MapOf,
6+
OrderedMap,
7+
OrderedSet,
8+
Set,
9+
Stack,
10+
} from 'immutable';
211

312
class A {
413
x: number;
@@ -7,6 +16,7 @@ class A {
716
this.x = 1;
817
}
918
}
19+
1020
class B extends A {
1121
y: string;
1222

@@ -15,6 +25,7 @@ class B extends A {
1525
this.y = 'B';
1626
}
1727
}
28+
1829
class C {
1930
z: string;
2031

@@ -23,55 +34,52 @@ class C {
2334
}
2435
}
2536

26-
// List covariance
27-
let listOfB: List<B> = List<B>();
28-
let listOfA: List<A> = listOfB;
29-
30-
// $ExpectType List<B>
31-
listOfA = List([new B()]);
32-
33-
// $ExpectError
34-
let listOfC: List<C> = listOfB;
35-
36-
// Map covariance
37-
declare let mapOfB: Map<string, B>;
38-
let mapOfA: Map<string, A> = mapOfB;
39-
40-
// $ExpectType MapOf<{ b: B; }>
41-
mapOfA = Map({ b: new B() });
42-
43-
// $ExpectError
44-
let mapOfC: Map<string, C> = mapOfB;
45-
46-
// Set covariance
47-
declare let setOfB: Set<B>;
48-
let setOfA: Set<A> = setOfB;
49-
50-
// $ExpectType Set<B>
51-
setOfA = Set([new B()]);
52-
// $ExpectError
53-
let setOfC: Set<C> = setOfB;
54-
55-
// Stack covariance
56-
declare let stackOfB: Stack<B>;
57-
let stackOfA: Stack<A> = stackOfB;
58-
// $ExpectType Stack<B>
59-
stackOfA = Stack([new B()]);
60-
// $ExpectError
61-
let stackOfC: Stack<C> = stackOfB;
62-
63-
// OrderedMap covariance
64-
declare let orderedMapOfB: OrderedMap<string, B>;
65-
let orderedMapOfA: OrderedMap<string, A> = orderedMapOfB;
66-
// $ExpectType OrderedMap<string, B>
67-
orderedMapOfA = OrderedMap({ b: new B() });
68-
// $ExpectError
69-
let orderedMapOfC: OrderedMap<string, C> = orderedMapOfB;
70-
71-
// OrderedSet covariance
72-
declare let orderedSetOfB: OrderedSet<B>;
73-
let orderedSetOfA: OrderedSet<A> = orderedSetOfB;
74-
// $ExpectType OrderedSet<B>
75-
orderedSetOfA = OrderedSet([new B()]);
76-
// $ExpectError
77-
let orderedSetOfC: OrderedSet<C> = orderedSetOfB;
37+
test('List covariance', () => {
38+
expect<List<A>>().type.toBeAssignable(List<B>());
39+
40+
expect(List([new B()])).type.toEqual<List<B>>();
41+
42+
expect<List<C>>().type.not.toBeAssignable(List<B>());
43+
});
44+
45+
test('Map covariance', () => {
46+
expect<Map<string, A>>().type.toBeAssignable<Map<string, B>>();
47+
48+
expect(Map({ b: new B() })).type.toEqual<MapOf<{ b: B }>>();
49+
50+
expect<Map<string, C>>().type.not.toBeAssignable<Map<string, B>>();
51+
});
52+
53+
test('Set covariance', () => {
54+
expect<Set<A>>().type.toBeAssignable<Set<B>>();
55+
56+
expect(Set([new B()])).type.toEqual<Set<B>>();
57+
58+
expect<Set<C>>().type.not.toBeAssignable<Set<B>>();
59+
});
60+
61+
test('Stack covariance', () => {
62+
expect<Stack<A>>().type.toBeAssignable<Stack<B>>();
63+
64+
expect(Stack([new B()])).type.toEqual<Stack<B>>();
65+
66+
expect<Stack<C>>().type.not.toBeAssignable<Stack<B>>();
67+
});
68+
69+
test('OrderedMap covariance', () => {
70+
expect<OrderedMap<string, A>>().type.toBeAssignable<OrderedMap<string, B>>();
71+
72+
expect(OrderedMap({ b: new B() })).type.toEqual<OrderedMap<string, B>>();
73+
74+
expect<OrderedMap<string, C>>().type.not.toBeAssignable<
75+
OrderedMap<string, B>
76+
>();
77+
});
78+
79+
test('OrderedSet covariance', () => {
80+
expect<OrderedSet<A>>().type.toBeAssignable<OrderedSet<B>>();
81+
82+
expect(OrderedSet([new B()])).type.toEqual<OrderedSet<B>>();
83+
84+
expect<OrderedSet<C>>().type.not.toBeAssignable<OrderedSet<B>>();
85+
});

0 commit comments

Comments
 (0)