tstyche 6.0.0-beta.3 → 6.0.0-beta.5
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/dist/index.cjs +20 -0
- package/dist/index.d.cts +255 -0
- package/dist/tstyche.js +55 -27
- package/package.json +6 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function noop() {
|
|
4
|
+
}
|
|
5
|
+
const noopChain = new Proxy(noop, {
|
|
6
|
+
apply() {
|
|
7
|
+
return noopChain;
|
|
8
|
+
},
|
|
9
|
+
get() {
|
|
10
|
+
return noopChain;
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
exports.describe = noopChain;
|
|
15
|
+
exports.expect = noopChain;
|
|
16
|
+
exports.it = noopChain;
|
|
17
|
+
exports.omit = noop;
|
|
18
|
+
exports.pick = noop;
|
|
19
|
+
exports.test = noopChain;
|
|
20
|
+
exports.when = noopChain;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
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 JSX component accepts props of the given type.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
*
|
|
67
|
+
* This is a work in progress feature. Generic components are not yet supported.
|
|
68
|
+
*/
|
|
69
|
+
toAcceptProps: {
|
|
70
|
+
/**
|
|
71
|
+
* Checks if the JSX component accepts props of the given type.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
*
|
|
75
|
+
* This is a work in progress feature. Generic components are not yet supported.
|
|
76
|
+
*/
|
|
77
|
+
<Target>(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the JSX component accepts the given props.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
*
|
|
83
|
+
* This is a work in progress feature. Generic components are not yet supported.
|
|
84
|
+
*/
|
|
85
|
+
(target: unknown): void;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Checks if the source type is the same as the target type.
|
|
89
|
+
*/
|
|
90
|
+
toBe: {
|
|
91
|
+
/**
|
|
92
|
+
* Checks if the source type is the same as the target type.
|
|
93
|
+
*/
|
|
94
|
+
<Target>(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if the source type is the same as type of the target expression.
|
|
97
|
+
*/
|
|
98
|
+
(target: unknown): void;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the decorator function can be applied.
|
|
102
|
+
*/
|
|
103
|
+
toBeApplicable: (target: unknown, context: DecoratorContext) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the source type is assignable from the target type.
|
|
106
|
+
*/
|
|
107
|
+
toBeAssignableFrom: {
|
|
108
|
+
/**
|
|
109
|
+
* Checks if the source type is assignable from the target type.
|
|
110
|
+
*/
|
|
111
|
+
<Target>(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Checks if the source type is assignable from type of the target expression.
|
|
114
|
+
*/
|
|
115
|
+
(target: unknown): void;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Checks if the source type is assignable to the target type.
|
|
119
|
+
*/
|
|
120
|
+
toBeAssignableTo: {
|
|
121
|
+
/**
|
|
122
|
+
* Checks if the source type is assignable to the target type.
|
|
123
|
+
*/
|
|
124
|
+
<Target>(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Checks if the source type is assignable to type of the target expression.
|
|
127
|
+
*/
|
|
128
|
+
(target: unknown): void;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Checks if the source type is callable with the given arguments.
|
|
132
|
+
*/
|
|
133
|
+
toBeCallableWith: (...args: Array<unknown>) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Checks if the source type is constructable with the given arguments.
|
|
136
|
+
*/
|
|
137
|
+
toBeConstructableWith: (...args: Array<unknown>) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a property key exists on the source type.
|
|
140
|
+
*/
|
|
141
|
+
toHaveProperty: (key: string | number | symbol) => void;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if the source type raises an error.
|
|
144
|
+
*/
|
|
145
|
+
toRaiseError: (...target: Array<string | number | RegExp>) => void;
|
|
146
|
+
}
|
|
147
|
+
interface Modifier {
|
|
148
|
+
/**
|
|
149
|
+
* Indicates a type-level assertion.
|
|
150
|
+
*/
|
|
151
|
+
type: Matchers & {
|
|
152
|
+
/**
|
|
153
|
+
* Negates the assertion.
|
|
154
|
+
*/
|
|
155
|
+
not: Matchers;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
interface Expect {
|
|
159
|
+
/**
|
|
160
|
+
* Builds an assertion.
|
|
161
|
+
*
|
|
162
|
+
* @template Source - The type which is checked.
|
|
163
|
+
*/
|
|
164
|
+
<Source>(): Modifier;
|
|
165
|
+
/**
|
|
166
|
+
* Builds an assertion.
|
|
167
|
+
*
|
|
168
|
+
* @param source - The expression whose type is checked.
|
|
169
|
+
*/
|
|
170
|
+
(source: unknown): Modifier;
|
|
171
|
+
/**
|
|
172
|
+
* Marks an assertion as focused.
|
|
173
|
+
*/
|
|
174
|
+
only: {
|
|
175
|
+
/**
|
|
176
|
+
* Marks an assertion as focused.
|
|
177
|
+
*
|
|
178
|
+
* @template Source - The type which is checked.
|
|
179
|
+
*/
|
|
180
|
+
<Source>(): Modifier;
|
|
181
|
+
/**
|
|
182
|
+
* Marks an assertion as focused.
|
|
183
|
+
*
|
|
184
|
+
* @param source - The expression whose type is checked.
|
|
185
|
+
*/
|
|
186
|
+
(source: unknown): Modifier;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Marks an assertion as skipped.
|
|
190
|
+
*/
|
|
191
|
+
skip: {
|
|
192
|
+
/**
|
|
193
|
+
* Marks an assertion as skipped.
|
|
194
|
+
*
|
|
195
|
+
* @template Source - The type which is checked.
|
|
196
|
+
*/
|
|
197
|
+
<Source>(): Modifier;
|
|
198
|
+
/**
|
|
199
|
+
* Marks an assertion as skipped.
|
|
200
|
+
*
|
|
201
|
+
* @param source - The expression whose type is checked.
|
|
202
|
+
*/
|
|
203
|
+
(source: unknown): Modifier;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Builds an assertion.
|
|
208
|
+
*/
|
|
209
|
+
declare const expect: Expect;
|
|
210
|
+
/**
|
|
211
|
+
* Reshapes type of the given object by removing the specified keys.
|
|
212
|
+
*/
|
|
213
|
+
declare function omit<T, K extends PropertyKey>(object: T, ...keys: [K, ...Array<K>]): Omit<T, K>;
|
|
214
|
+
/**
|
|
215
|
+
* Reshapes type of the given object by keeping only the specified keys.
|
|
216
|
+
*/
|
|
217
|
+
declare function pick<T, K extends keyof T>(object: T, ...keys: [K, ...Array<K>]): Pick<T, K>;
|
|
218
|
+
/**
|
|
219
|
+
* Defines a test group.
|
|
220
|
+
*/
|
|
221
|
+
declare const describe: Describe;
|
|
222
|
+
/**
|
|
223
|
+
* Defines a single test.
|
|
224
|
+
*/
|
|
225
|
+
declare const it: Test;
|
|
226
|
+
/**
|
|
227
|
+
* Defines a single test.
|
|
228
|
+
*/
|
|
229
|
+
declare const test: Test;
|
|
230
|
+
interface Actions {
|
|
231
|
+
/**
|
|
232
|
+
* Calls the given function with the provided arguments.
|
|
233
|
+
*/
|
|
234
|
+
isCalledWith: (...args: Array<unknown>) => void;
|
|
235
|
+
}
|
|
236
|
+
interface When {
|
|
237
|
+
/**
|
|
238
|
+
* Creates a test plan.
|
|
239
|
+
*
|
|
240
|
+
* @template Target - The type upon which an action is performed.
|
|
241
|
+
*/
|
|
242
|
+
<Target>(): Actions;
|
|
243
|
+
/**
|
|
244
|
+
* Creates a test plan.
|
|
245
|
+
*
|
|
246
|
+
* @param target - The expression upon which an action is performed.
|
|
247
|
+
*/
|
|
248
|
+
(target: unknown): Actions;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates a test plan.
|
|
252
|
+
*/
|
|
253
|
+
declare const when: When;
|
|
254
|
+
|
|
255
|
+
export { describe, expect, it, omit, pick, test, when };
|
package/dist/tstyche.js
CHANGED
|
@@ -4550,9 +4550,6 @@ class ToAcceptProps {
|
|
|
4550
4550
|
}
|
|
4551
4551
|
}
|
|
4552
4552
|
|
|
4553
|
-
function ensureArray(input) {
|
|
4554
|
-
return input ?? [];
|
|
4555
|
-
}
|
|
4556
4553
|
function getIndexSignatures(type, compiler, typeChecker) {
|
|
4557
4554
|
if (type.flags & compiler.TypeFlags.Intersection) {
|
|
4558
4555
|
return type.types.flatMap((type) => getIndexSignatures(type, compiler, typeChecker));
|
|
@@ -4565,6 +4562,12 @@ function getSignatures(type, kind, compiler, typeChecker) {
|
|
|
4565
4562
|
}
|
|
4566
4563
|
return typeChecker.getSignaturesOfType(type, kind);
|
|
4567
4564
|
}
|
|
4565
|
+
function getThisTypeOfSignature(signature, typeChecker) {
|
|
4566
|
+
return signature.thisParameter && typeChecker.getTypeOfSymbol(signature.thisParameter);
|
|
4567
|
+
}
|
|
4568
|
+
function getTypeParametersOfSignature(signature) {
|
|
4569
|
+
return signature.typeParameters ?? [];
|
|
4570
|
+
}
|
|
4568
4571
|
function getTypeParameterModifiers(typeParameter, compiler) {
|
|
4569
4572
|
if (!typeParameter.symbol.declarations) {
|
|
4570
4573
|
return compiler.ModifierFlags.None;
|
|
@@ -4583,9 +4586,6 @@ function isCheckFlagSet(symbol, flag, compiler) {
|
|
|
4583
4586
|
function isSymbolFromDefaultLibrary(symbol, program) {
|
|
4584
4587
|
return !!symbol.declarations?.every((declaration) => program.isSourceFileDefaultLibrary(declaration.getSourceFile()));
|
|
4585
4588
|
}
|
|
4586
|
-
function length(array) {
|
|
4587
|
-
return array?.length ?? 0;
|
|
4588
|
-
}
|
|
4589
4589
|
|
|
4590
4590
|
function getParameterFactsFromTuple(type, position, compiler) {
|
|
4591
4591
|
return {
|
|
@@ -4688,11 +4688,6 @@ class Structure {
|
|
|
4688
4688
|
}
|
|
4689
4689
|
return !a && !b;
|
|
4690
4690
|
}
|
|
4691
|
-
#compareTypeOfSymbol(a, b) {
|
|
4692
|
-
const aTypeOfSymbol = a && this.#typeChecker.getTypeOfSymbol(a);
|
|
4693
|
-
const bTypeOfSymbol = b && this.#typeChecker.getTypeOfSymbol(b);
|
|
4694
|
-
return this.#compareMaybeNullish(aTypeOfSymbol, bTypeOfSymbol);
|
|
4695
|
-
}
|
|
4696
4691
|
compare(a, b) {
|
|
4697
4692
|
a = this.#normalize(a);
|
|
4698
4693
|
b = this.#normalize(b);
|
|
@@ -4756,6 +4751,18 @@ class Structure {
|
|
|
4756
4751
|
}
|
|
4757
4752
|
return false;
|
|
4758
4753
|
}
|
|
4754
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.TemplateLiteral) {
|
|
4755
|
+
if (a.flags & b.flags & this.#compiler.TypeFlags.TemplateLiteral) {
|
|
4756
|
+
return this.compareTemplateLiteralTypes(a, b);
|
|
4757
|
+
}
|
|
4758
|
+
return false;
|
|
4759
|
+
}
|
|
4760
|
+
if ((a.flags | b.flags) & this.#compiler.TypeFlags.StringMapping) {
|
|
4761
|
+
if (a.flags & b.flags & this.#compiler.TypeFlags.StringMapping) {
|
|
4762
|
+
return this.compareStringMappingTypes(a, b);
|
|
4763
|
+
}
|
|
4764
|
+
return false;
|
|
4765
|
+
}
|
|
4759
4766
|
return false;
|
|
4760
4767
|
}
|
|
4761
4768
|
compareIntersections(a, b) {
|
|
@@ -4789,16 +4796,18 @@ class Structure {
|
|
|
4789
4796
|
if ((a.objectFlags | b.objectFlags) & this.#compiler.ObjectFlags.Class) {
|
|
4790
4797
|
return this.compareStructuredTypes(a, b);
|
|
4791
4798
|
}
|
|
4792
|
-
if (
|
|
4799
|
+
if (a.symbol !== b.symbol) {
|
|
4793
4800
|
if (isSymbolFromDefaultLibrary(a.symbol, this.#program) || isSymbolFromDefaultLibrary(b.symbol, this.#program)) {
|
|
4794
4801
|
return false;
|
|
4795
4802
|
}
|
|
4796
4803
|
return;
|
|
4797
4804
|
}
|
|
4798
|
-
|
|
4805
|
+
const aTypeArguments = this.#typeChecker.getTypeArguments(a);
|
|
4806
|
+
const bTypeArguments = this.#typeChecker.getTypeArguments(b);
|
|
4807
|
+
if (aTypeArguments.length !== bTypeArguments.length) {
|
|
4799
4808
|
return false;
|
|
4800
4809
|
}
|
|
4801
|
-
return
|
|
4810
|
+
return aTypeArguments.every((type, i) => this.compare(type, bTypeArguments[i]));
|
|
4802
4811
|
}
|
|
4803
4812
|
compareTuples(a, b) {
|
|
4804
4813
|
if (a.target.readonly !== b.target.readonly) {
|
|
@@ -4806,7 +4815,7 @@ class Structure {
|
|
|
4806
4815
|
}
|
|
4807
4816
|
const aTypeArguments = this.#typeChecker.getTypeArguments(a);
|
|
4808
4817
|
const bTypeArguments = this.#typeChecker.getTypeArguments(b);
|
|
4809
|
-
if (length
|
|
4818
|
+
if (aTypeArguments.length !== bTypeArguments.length) {
|
|
4810
4819
|
return false;
|
|
4811
4820
|
}
|
|
4812
4821
|
for (let i = 0; i < aTypeArguments.length; i++) {
|
|
@@ -4888,17 +4897,17 @@ class Structure {
|
|
|
4888
4897
|
return true;
|
|
4889
4898
|
}
|
|
4890
4899
|
#compareSignature(a, b) {
|
|
4891
|
-
|
|
4900
|
+
const aTypeParameters = getTypeParametersOfSignature(a);
|
|
4901
|
+
const bTypeParameters = getTypeParametersOfSignature(b);
|
|
4902
|
+
if (aTypeParameters.length !== bTypeParameters.length) {
|
|
4892
4903
|
return false;
|
|
4893
4904
|
}
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
return false;
|
|
4898
|
-
}
|
|
4905
|
+
for (let i = 0; i < aTypeParameters.length; i++) {
|
|
4906
|
+
if (!this.compareTypeParameters(aTypeParameters[i], bTypeParameters[i])) {
|
|
4907
|
+
return false;
|
|
4899
4908
|
}
|
|
4900
4909
|
}
|
|
4901
|
-
if (!this.#
|
|
4910
|
+
if (!this.#compareMaybeNullish(getThisTypeOfSignature(a, this.#typeChecker), getThisTypeOfSignature(b, this.#typeChecker))) {
|
|
4902
4911
|
return false;
|
|
4903
4912
|
}
|
|
4904
4913
|
if (!this.compareParameters(a, b)) {
|
|
@@ -5000,14 +5009,33 @@ class Structure {
|
|
|
5000
5009
|
}
|
|
5001
5010
|
return true;
|
|
5002
5011
|
}
|
|
5012
|
+
compareTemplateLiteralTypes(a, b) {
|
|
5013
|
+
if (a.texts.length !== b.texts.length) {
|
|
5014
|
+
return false;
|
|
5015
|
+
}
|
|
5016
|
+
for (let i = 0; i < a.texts.length; i++) {
|
|
5017
|
+
if (a.texts[i] !== b.texts[i]) {
|
|
5018
|
+
return false;
|
|
5019
|
+
}
|
|
5020
|
+
if (!this.#compareMaybeNullish(a.types[i], b.types[i])) {
|
|
5021
|
+
return false;
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
return true;
|
|
5025
|
+
}
|
|
5026
|
+
compareStringMappingTypes(a, b) {
|
|
5027
|
+
if (a.symbol !== b.symbol) {
|
|
5028
|
+
return false;
|
|
5029
|
+
}
|
|
5030
|
+
if (!this.compare(a.type, b.type)) {
|
|
5031
|
+
return false;
|
|
5032
|
+
}
|
|
5033
|
+
return true;
|
|
5034
|
+
}
|
|
5003
5035
|
#normalize(type) {
|
|
5004
5036
|
if (type.flags & this.#compiler.TypeFlags.Freshable && type.freshType === type) {
|
|
5005
5037
|
return type.regularType;
|
|
5006
5038
|
}
|
|
5007
|
-
if (type.flags & this.#compiler.TypeFlags.Substitution &&
|
|
5008
|
-
type.constraint.flags & this.#compiler.TypeFlags.Unknown) {
|
|
5009
|
-
return type.baseType;
|
|
5010
|
-
}
|
|
5011
5039
|
if (type.flags & this.#compiler.TypeFlags.UnionOrIntersection) {
|
|
5012
5040
|
const candidateType = this.#normalize(type.types[0]);
|
|
5013
5041
|
if (type.types.every((t) => this.compare(this.#normalize(t), candidateType))) {
|
|
@@ -5872,7 +5900,7 @@ class FileRunner {
|
|
|
5872
5900
|
class Runner {
|
|
5873
5901
|
#eventEmitter = new EventEmitter();
|
|
5874
5902
|
#resolvedConfig;
|
|
5875
|
-
static version = "6.0.0-beta.
|
|
5903
|
+
static version = "6.0.0-beta.5";
|
|
5876
5904
|
constructor(resolvedConfig) {
|
|
5877
5905
|
this.#resolvedConfig = resolvedConfig;
|
|
5878
5906
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tstyche",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.5",
|
|
4
4
|
"description": "Everything You Need for Type Testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -21,11 +21,15 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"type": "module",
|
|
23
23
|
"exports": {
|
|
24
|
-
".":
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
|
+
},
|
|
25
28
|
"./tstyche": "./dist/tstyche.js",
|
|
26
29
|
"./package.json": "./package.json"
|
|
27
30
|
},
|
|
28
31
|
"main": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
29
33
|
"bin": "./dist/bin.js",
|
|
30
34
|
"peerDependencies": {
|
|
31
35
|
"typescript": ">=5.4"
|