tstyche 6.0.0-beta.6 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -24
- package/dist/tstyche.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ TSTyche is a type testing tool for TypeScript. It ships with `describe()` and `t
|
|
|
13
13
|
|
|
14
14
|
## Helpers
|
|
15
15
|
|
|
16
|
-
If you are used to
|
|
16
|
+
If you are used to testing, a type test should look familiar:
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
import { expect, test } from "tstyche";
|
|
@@ -30,42 +30,33 @@ test("isSameLength", () => {
|
|
|
30
30
|
});
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
To
|
|
33
|
+
To group and organize tests, TSTyche has:
|
|
34
34
|
|
|
35
35
|
- `test()`, `it()` and `describe()` helpers,
|
|
36
36
|
- with `.only`, `.skip` and `.todo` run mode flags.
|
|
37
37
|
|
|
38
38
|
## Assertions
|
|
39
39
|
|
|
40
|
-
The assertions can
|
|
40
|
+
The `expect` style assertions can check either the inferred type of an expression (as in the example above) or a type directly:
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
import
|
|
44
|
-
import test from "node:test";
|
|
45
|
-
import * as tstyche from "tstyche";
|
|
43
|
+
import { expect } from "tstyche";
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
45
|
+
type AsyncProps<T> = {
|
|
46
|
+
[K in keyof T]+?: T[K] | Promise<T[K]>;
|
|
47
|
+
};
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
test("toMilliseconds", () => {
|
|
56
|
-
const sample = toMilliseconds(10);
|
|
49
|
+
type WithLoading<T> = T & { loading: boolean };
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
tstyche.expect(toMilliseconds).type.not.toBeCallableWith("20");
|
|
63
|
-
});
|
|
51
|
+
expect<WithLoading<AsyncProps<{ query: string }>>>().type.toBe<{
|
|
52
|
+
query?: string | Promise<string>;
|
|
53
|
+
loading: boolean;
|
|
54
|
+
}>();
|
|
64
55
|
```
|
|
65
56
|
|
|
66
57
|
Here is the list of all matchers:
|
|
67
58
|
|
|
68
|
-
- `.toBe()`, `.toBeAssignableFrom()`, `.toBeAssignableTo()` compare types or
|
|
59
|
+
- `.toBe()`, `.toBeAssignableFrom()`, `.toBeAssignableTo()` compare types or type of expressions,
|
|
69
60
|
- `.toAcceptProps()` checks the type of JSX component props,
|
|
70
61
|
- `.toBeApplicable` ensures that the decorator function can be applied,
|
|
71
62
|
- `.toBeCallableWith()` checks whether a function is callable with the given arguments,
|
|
@@ -74,13 +65,23 @@ Here is the list of all matchers:
|
|
|
74
65
|
|
|
75
66
|
## Runner
|
|
76
67
|
|
|
77
|
-
The `tstyche` command is the heart of TSTyche.
|
|
68
|
+
The `tstyche` command is the heart of TSTyche. It allows you to select test files by path, filter tests by name and run them against specific versions of TypeScript:
|
|
78
69
|
|
|
79
70
|
```shell
|
|
80
71
|
tstyche query-params --only multiple --target '>=5.6'
|
|
81
72
|
```
|
|
82
73
|
|
|
83
|
-
|
|
74
|
+
It is that simple! Actually, TSTyche does even more:
|
|
75
|
+
|
|
76
|
+
- checks messages of errors suppressed by `// @ts-expect-error`,
|
|
77
|
+
- generates type tests from a data table,
|
|
78
|
+
- runs tests in watch mode.
|
|
79
|
+
|
|
80
|
+
## Try It Out
|
|
81
|
+
|
|
82
|
+
Try TSTyche online on StackBlitz:
|
|
83
|
+
|
|
84
|
+
[![Open in StackBlitz][starter-badge]][starter-url]
|
|
84
85
|
|
|
85
86
|
## Documentation
|
|
86
87
|
|
|
@@ -98,3 +99,5 @@ Visit [tstyche.org](https://tstyche.org) to view the full documentation.
|
|
|
98
99
|
[install-size-url]: https://packagephobia.com/result?p=tstyche
|
|
99
100
|
[coverage-badge]: https://badgen.net/codacy/coverage/a581ca5c323a455886b7bdd9623c4ec8
|
|
100
101
|
[coverage-url]: https://app.codacy.com/gh/tstyche/tstyche/coverage/dashboard
|
|
102
|
+
[starter-badge]: https://developer.stackblitz.com/img/open_in_stackblitz.svg
|
|
103
|
+
[starter-url]: https://stackblitz.com/fork/github/tstyche/tstyche-starter?file=README.md&title=TSTyche%20Starter%20Project&view=editor
|
package/dist/tstyche.js
CHANGED
|
@@ -4550,9 +4550,9 @@ class ToAcceptProps {
|
|
|
4550
4550
|
}
|
|
4551
4551
|
}
|
|
4552
4552
|
|
|
4553
|
-
function
|
|
4553
|
+
function containsInstantiable(target, compiler) {
|
|
4554
4554
|
return ("types" in target &&
|
|
4555
|
-
target.types.some((type) => type.flags & compiler.TypeFlags.
|
|
4555
|
+
target.types.some((type) => type.flags & compiler.TypeFlags.Instantiable));
|
|
4556
4556
|
}
|
|
4557
4557
|
function getIndexSignatures(type, compiler, typeChecker) {
|
|
4558
4558
|
if (type.flags & compiler.TypeFlags.Intersection) {
|
|
@@ -4713,7 +4713,7 @@ class Structure {
|
|
|
4713
4713
|
return true;
|
|
4714
4714
|
}
|
|
4715
4715
|
}
|
|
4716
|
-
if (
|
|
4716
|
+
if (containsInstantiable(a, this.#compiler) || containsInstantiable(b, this.#compiler)) {
|
|
4717
4717
|
return false;
|
|
4718
4718
|
}
|
|
4719
4719
|
if ((a.flags & b.flags) | this.#compiler.TypeFlags.StructuredType) {
|
|
@@ -5049,8 +5049,8 @@ class Structure {
|
|
|
5049
5049
|
return type.regularType;
|
|
5050
5050
|
}
|
|
5051
5051
|
if (type.flags & this.#compiler.TypeFlags.UnionOrIntersection) {
|
|
5052
|
-
const candidateType =
|
|
5053
|
-
if (type.types.every((t) => this.compare(
|
|
5052
|
+
const candidateType = type.types[0];
|
|
5053
|
+
if (type.types.every((t) => this.compare(t, candidateType))) {
|
|
5054
5054
|
return candidateType;
|
|
5055
5055
|
}
|
|
5056
5056
|
}
|
|
@@ -5912,7 +5912,7 @@ class FileRunner {
|
|
|
5912
5912
|
class Runner {
|
|
5913
5913
|
#eventEmitter = new EventEmitter();
|
|
5914
5914
|
#resolvedConfig;
|
|
5915
|
-
static version = "6.0.0
|
|
5915
|
+
static version = "6.0.0";
|
|
5916
5916
|
constructor(resolvedConfig) {
|
|
5917
5917
|
this.#resolvedConfig = resolvedConfig;
|
|
5918
5918
|
}
|