tstyche 1.0.0-beta.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/LICENSE.md +10 -0
- package/README.md +80 -0
- package/build/bin.js +5 -0
- package/build/index.d.ts +276 -0
- package/build/index.js +12 -0
- package/build/tstyche.d.ts +679 -0
- package/build/tstyche.js +3550 -0
- package/lib/schema.json +47 -0
- package/package.json +128 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2023-present TSTyche
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
10
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# TSTyche
|
|
2
|
+
|
|
3
|
+
[![license][license-src]][license-href]
|
|
4
|
+
|
|
5
|
+
The Essential Type Testing Tool.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
TSTyche is a type testing tool for TypeScript. It ships with `describe()` and `test()` helpers, `expect` style assertions and a mighty test runner.
|
|
10
|
+
|
|
11
|
+
## Helpers
|
|
12
|
+
|
|
13
|
+
If you are used to test JavaScript, a simple type test file should look familiar:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { expect, test } from "tstyche";
|
|
17
|
+
|
|
18
|
+
function firstItem<T>(target: Array<T>): T | undefined {
|
|
19
|
+
return target[0];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
test("firstItem", () => {
|
|
23
|
+
expect(firstItem(["a", "b", "c"])).type.toEqual<string | undefined>();
|
|
24
|
+
|
|
25
|
+
expect(firstItem()).type.toRaiseError("Expected 1 argument");
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To organize, debug and plan tests TSTyche has:
|
|
30
|
+
|
|
31
|
+
- `test()`, `it()`, `describe()` and `context()` helpers;
|
|
32
|
+
- with `.only`, `.skip` and `.todo` run mode flags.
|
|
33
|
+
|
|
34
|
+
## Assertions
|
|
35
|
+
|
|
36
|
+
The assertions can be used to write type tests (like in the above example) or mixed in your functional tests:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import * as tstyche from "tstyche";
|
|
40
|
+
|
|
41
|
+
function secondItem<T>(target: Array<T>): T | undefined {
|
|
42
|
+
return target[1];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("secondItem", () => {
|
|
46
|
+
it("should handle numbers", () => {
|
|
47
|
+
expect(secondItem([1, 2, 3])).toBe(1);
|
|
48
|
+
|
|
49
|
+
tstyche.expect(secondItem([1, 2, 3])).type.toEqual<number | undefined>();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Here is the list of all matchers:
|
|
55
|
+
|
|
56
|
+
- `.toBeAssignable()`, `.toEqual()`, `.toMatch()` compares types or types of expression;
|
|
57
|
+
- `.toRaiseError()` captures the error message or code;
|
|
58
|
+
- `.toBeString()`, `.toBeNumber()`, `.toBeVoid()` and 9 more checks for primitive types.
|
|
59
|
+
|
|
60
|
+
## Runner
|
|
61
|
+
|
|
62
|
+
The `tstyche` command is the heart of TSTyche. For example, it can select test files by path, filter tests by name and pass them through TypeScript `4.8` and `latest`:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
tstyche JsonObject --only external --target 4.8,latest
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This simple!
|
|
69
|
+
|
|
70
|
+
## Documentation
|
|
71
|
+
|
|
72
|
+
Visit [https://tstyche.org][documentation-href] to view the full documentation.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[MIT][license-href] © TSTyche
|
|
77
|
+
|
|
78
|
+
[documentation-href]: https://tstyche.org
|
|
79
|
+
[license-src]: https://badgen.net/github/license/tstyche/tstyche
|
|
80
|
+
[license-href]: https://github.com/tstyche/tstyche/blob/main/LICENSE.md
|
package/build/bin.js
ADDED
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
interface Describe {
|
|
2
|
+
/**
|
|
3
|
+
* Defines a group of tests.
|
|
4
|
+
*
|
|
5
|
+
* @param name - The name of the group.
|
|
6
|
+
* @param callback - The function to create a scope for a group of tests.
|
|
7
|
+
*/
|
|
8
|
+
(name: string, callback: () => void | Promise<void>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Marks a group of tests as focused.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The name of the group.
|
|
13
|
+
* @param callback - The function to create a scope for a group of tests.
|
|
14
|
+
*/
|
|
15
|
+
only: (name: string, callback: () => void | Promise<void>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Marks a group of tests as skipped.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The name of the group.
|
|
20
|
+
* @param callback - The function to create a scope for a group of tests.
|
|
21
|
+
*/
|
|
22
|
+
skip: (name: string, callback: () => void | Promise<void>) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Marks a group of tests as yet to be implemented.
|
|
25
|
+
*
|
|
26
|
+
* @param name - The name of the group.
|
|
27
|
+
* @param callback - The function to create a scope for a group of tests.
|
|
28
|
+
*/
|
|
29
|
+
todo: (name: string, callback?: () => void | Promise<void>) => void;
|
|
30
|
+
}
|
|
31
|
+
interface Test {
|
|
32
|
+
/**
|
|
33
|
+
* Defines a single test.
|
|
34
|
+
*
|
|
35
|
+
* @param name - The name of the test.
|
|
36
|
+
* @param callback - The function with a code snippet and assertions.
|
|
37
|
+
*/
|
|
38
|
+
(name: string, callback: () => void | Promise<void>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Marks a test as focused.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The name of the test.
|
|
43
|
+
* @param callback - The function with a code snippet and assertions.
|
|
44
|
+
*/
|
|
45
|
+
only: (name: string, callback: () => void | Promise<void>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Marks a test as skipped.
|
|
48
|
+
*
|
|
49
|
+
* @param name - The name of the test.
|
|
50
|
+
* @param callback - The function with a code snippet and assertions.
|
|
51
|
+
*/
|
|
52
|
+
skip: (name: string, callback: () => void | Promise<void>) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Marks a test as yet to be implemented.
|
|
55
|
+
*
|
|
56
|
+
* @param name - The name of the test.
|
|
57
|
+
* @param callback - The function with a code snippet and assertions.
|
|
58
|
+
*/
|
|
59
|
+
todo: (name: string, callback?: () => void | Promise<void>) => void;
|
|
60
|
+
}
|
|
61
|
+
interface Matchers {
|
|
62
|
+
/**
|
|
63
|
+
* Checks if the source type is `any`.
|
|
64
|
+
*/
|
|
65
|
+
toBeAny: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the target type is assignable to the source type.
|
|
68
|
+
*/
|
|
69
|
+
toBeAssignable: {
|
|
70
|
+
/**
|
|
71
|
+
* Checks if the target type is assignable to the source type.
|
|
72
|
+
*/
|
|
73
|
+
<Target>(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if type of the target expression is assignable to the source type.
|
|
76
|
+
*/
|
|
77
|
+
(target: unknown): void;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the source type is `bigint`.
|
|
81
|
+
*/
|
|
82
|
+
toBeBigInt: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the source type is `boolean`.
|
|
85
|
+
*/
|
|
86
|
+
toBeBoolean: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the source type is `never`.
|
|
89
|
+
*/
|
|
90
|
+
toBeNever: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if the source type is `null`.
|
|
93
|
+
*/
|
|
94
|
+
toBeNull: () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if the source type is `number`.
|
|
97
|
+
*/
|
|
98
|
+
toBeNumber: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the source type is `string`.
|
|
101
|
+
*/
|
|
102
|
+
toBeString: () => void;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if the source type is `symbol`.
|
|
105
|
+
*/
|
|
106
|
+
toBeSymbol: () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if the source type is `undefined`.
|
|
109
|
+
*/
|
|
110
|
+
toBeUndefined: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Checks if the source type is `unique symbol`.
|
|
113
|
+
*/
|
|
114
|
+
toBeUniqueSymbol: () => void;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the source type is `unknown`.
|
|
117
|
+
*/
|
|
118
|
+
toBeUnknown: () => void;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if the source type is `void`.
|
|
121
|
+
*/
|
|
122
|
+
toBeVoid: () => void;
|
|
123
|
+
/**
|
|
124
|
+
* Check if the target type is identical to the source type.
|
|
125
|
+
*/
|
|
126
|
+
toEqual: {
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the target type is identical to the source type.
|
|
129
|
+
*/
|
|
130
|
+
<Target>(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if type of the target expression is identical to the source type.
|
|
133
|
+
*/
|
|
134
|
+
(target: unknown): void;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Checks if the target type is a subtype the source type.
|
|
138
|
+
*/
|
|
139
|
+
toMatch: {
|
|
140
|
+
/**
|
|
141
|
+
* Checks if the target type is a subtype the source type.
|
|
142
|
+
*/
|
|
143
|
+
<Target>(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if type of the target expression is a subtype the source type.
|
|
146
|
+
*/
|
|
147
|
+
(target: unknown): void;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Checks if the source type raises an error.
|
|
151
|
+
*/
|
|
152
|
+
toRaiseError: (...target: Array<string | number>) => void;
|
|
153
|
+
}
|
|
154
|
+
interface Modifier {
|
|
155
|
+
/**
|
|
156
|
+
* Passes the source type to the matcher.
|
|
157
|
+
*/
|
|
158
|
+
type: Matchers & {
|
|
159
|
+
/**
|
|
160
|
+
* Negates the assertion.
|
|
161
|
+
*/
|
|
162
|
+
not: Matchers;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
interface Expect {
|
|
166
|
+
/**
|
|
167
|
+
* Builds an assertion.
|
|
168
|
+
*
|
|
169
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
170
|
+
*/
|
|
171
|
+
<Source>(): Modifier;
|
|
172
|
+
/**
|
|
173
|
+
* Builds an assertion.
|
|
174
|
+
*
|
|
175
|
+
* @param source - The expression against which type the assertion will be made.
|
|
176
|
+
*/
|
|
177
|
+
(source: unknown): Modifier;
|
|
178
|
+
fail: {
|
|
179
|
+
/**
|
|
180
|
+
* Mark an assertion as supposed to fail.
|
|
181
|
+
*
|
|
182
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
183
|
+
*/
|
|
184
|
+
<Source>(): Modifier;
|
|
185
|
+
/**
|
|
186
|
+
* Mark an assertion as supposed to fail.
|
|
187
|
+
*
|
|
188
|
+
* @param source - The expression against which type the assertion will be made.
|
|
189
|
+
*/
|
|
190
|
+
(source: unknown): Modifier;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Marks an assertion as focused.
|
|
194
|
+
*/
|
|
195
|
+
only: {
|
|
196
|
+
/**
|
|
197
|
+
* Marks an assertion as focused.
|
|
198
|
+
*
|
|
199
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
200
|
+
*/
|
|
201
|
+
<Source>(): Modifier;
|
|
202
|
+
/**
|
|
203
|
+
* Marks an assertion as focused.
|
|
204
|
+
*
|
|
205
|
+
* @param source - The expression against which type the assertion will be made.
|
|
206
|
+
*/
|
|
207
|
+
(source: unknown): Modifier;
|
|
208
|
+
fail: {
|
|
209
|
+
/**
|
|
210
|
+
* Mark an assertion as supposed to fail.
|
|
211
|
+
*
|
|
212
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
213
|
+
*/
|
|
214
|
+
<Source>(): Modifier;
|
|
215
|
+
/**
|
|
216
|
+
* Mark an assertion as supposed to fail.
|
|
217
|
+
*
|
|
218
|
+
* @param source - The expression against which type the assertion will be made.
|
|
219
|
+
*/
|
|
220
|
+
(source: unknown): Modifier;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Marks an assertion as skipped.
|
|
225
|
+
*/
|
|
226
|
+
skip: {
|
|
227
|
+
/**
|
|
228
|
+
* Marks an assertion as skipped.
|
|
229
|
+
*
|
|
230
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
231
|
+
*/
|
|
232
|
+
<Source>(): Modifier;
|
|
233
|
+
/**
|
|
234
|
+
* Marks an assertion as skipped.
|
|
235
|
+
*
|
|
236
|
+
* @param source - The expression against which type the assertion will be made.
|
|
237
|
+
*/
|
|
238
|
+
(source: unknown): Modifier;
|
|
239
|
+
fail: {
|
|
240
|
+
/**
|
|
241
|
+
* Marks an assertion as supposed to fail.
|
|
242
|
+
*
|
|
243
|
+
* @typeParam Source - The type against which the assertion will be made.
|
|
244
|
+
*/
|
|
245
|
+
<Source>(): Modifier;
|
|
246
|
+
/**
|
|
247
|
+
* Marks an assertion as supposed to fail.
|
|
248
|
+
*
|
|
249
|
+
* @param source - The expression against which type the assertion will be made.
|
|
250
|
+
*/
|
|
251
|
+
(source: unknown): Modifier;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Defines a test group.
|
|
257
|
+
*/
|
|
258
|
+
declare const describe: Describe;
|
|
259
|
+
/**
|
|
260
|
+
* Defines a test group.
|
|
261
|
+
*/
|
|
262
|
+
declare const context: Describe;
|
|
263
|
+
/**
|
|
264
|
+
* Defines a single test.
|
|
265
|
+
*/
|
|
266
|
+
declare const test: Test;
|
|
267
|
+
/**
|
|
268
|
+
* Defines a single test.
|
|
269
|
+
*/
|
|
270
|
+
declare const it: Test;
|
|
271
|
+
/**
|
|
272
|
+
* Builds an assertion.
|
|
273
|
+
*/
|
|
274
|
+
declare const expect: Expect;
|
|
275
|
+
|
|
276
|
+
export { context, describe, expect, it, test };
|
package/build/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function doNothing() {
|
|
2
|
+
}
|
|
3
|
+
const noopChain = new Proxy(doNothing, {
|
|
4
|
+
apply() {
|
|
5
|
+
return noopChain;
|
|
6
|
+
},
|
|
7
|
+
get() {
|
|
8
|
+
return noopChain;
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { noopChain as context, noopChain as describe, noopChain as expect, noopChain as it, noopChain as test };
|