vest 4.2.2 → 4.3.1
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/cjs/classnames.development.js +76 -28
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +28 -60
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +17 -2
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +1 -1
- package/dist/cjs/parser.development.js +84 -22
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +21 -8
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +297 -294
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +76 -28
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +28 -60
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +17 -2
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +1 -1
- package/dist/es/parser.development.js +84 -22
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +21 -8
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +297 -294
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +76 -28
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +94 -104
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +39 -41
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +40 -42
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +84 -22
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +21 -8
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +264 -283
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/testUtils/mockThrowError.ts +3 -6
- package/testUtils/suiteDummy.ts +5 -1
- package/types/classnames.d.ts +13 -54
- package/types/enforce/compose.d.ts +22 -21
- package/types/enforce/compounds.d.ts +24 -23
- package/types/enforce/schema.d.ts +26 -25
- package/types/parser.d.ts +12 -53
- package/types/promisify.d.ts +19 -15
- package/types/vest.d.ts +66 -61
package/types/promisify.d.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reads the testObjects list and gets full validation result from it.
|
|
3
3
|
*/
|
|
4
|
-
declare function genTestsSummary():
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
declare function genTestsSummary(): SuiteSummary;
|
|
5
|
+
type Groups = Record<string, TestGroup>;
|
|
6
|
+
type SuiteSummary = {
|
|
7
|
+
groups: Groups;
|
|
8
|
+
tests: TestGroup;
|
|
9
|
+
valid: boolean;
|
|
10
|
+
} & SummaryBase;
|
|
11
|
+
type TestGroup = Record<string, SingleTestSummary>;
|
|
12
|
+
type SingleTestSummary = SummaryBase & {
|
|
11
13
|
errors: string[];
|
|
12
14
|
warnings: string[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
valid: boolean;
|
|
16
|
+
};
|
|
17
|
+
type SummaryBase = {
|
|
15
18
|
errorCount: number;
|
|
16
19
|
warnCount: number;
|
|
17
20
|
testCount: number;
|
|
18
21
|
};
|
|
19
|
-
|
|
22
|
+
type FailureMessages = Record<string, string[]>;
|
|
23
|
+
declare function getErrors(): FailureMessages;
|
|
20
24
|
declare function getErrors(fieldName?: string): string[];
|
|
21
|
-
declare function getWarnings():
|
|
25
|
+
declare function getWarnings(): FailureMessages;
|
|
22
26
|
declare function getWarnings(fieldName?: string): string[];
|
|
23
|
-
declare function getErrorsByGroup(groupName: string):
|
|
27
|
+
declare function getErrorsByGroup(groupName: string): FailureMessages;
|
|
24
28
|
declare function getErrorsByGroup(groupName: string, fieldName: string): string[];
|
|
25
|
-
declare function getWarningsByGroup(groupName: string):
|
|
29
|
+
declare function getWarningsByGroup(groupName: string): FailureMessages;
|
|
26
30
|
declare function getWarningsByGroup(groupName: string, fieldName: string): string[];
|
|
27
31
|
declare function hasErrors(fieldName?: string): boolean;
|
|
28
32
|
declare function hasWarnings(fieldName?: string): boolean;
|
|
@@ -45,9 +49,9 @@ type SuiteResult = ReturnType<typeof genTestsSummary> & {
|
|
|
45
49
|
getWarningsByGroup: typeof getWarningsByGroup;
|
|
46
50
|
};
|
|
47
51
|
type SuiteRunResult = SuiteResult & {
|
|
48
|
-
done:
|
|
52
|
+
done: Done;
|
|
49
53
|
};
|
|
50
|
-
interface
|
|
54
|
+
interface Done {
|
|
51
55
|
(...args: [
|
|
52
56
|
cb: (res: SuiteResult) => void
|
|
53
57
|
]): SuiteRunResult;
|
package/types/vest.d.ts
CHANGED
|
@@ -5,20 +5,20 @@ declare enum TestSeverity {
|
|
|
5
5
|
}
|
|
6
6
|
declare class VestTest {
|
|
7
7
|
fieldName: string;
|
|
8
|
-
testFn:
|
|
9
|
-
asyncTest?:
|
|
8
|
+
testFn: TestFn;
|
|
9
|
+
asyncTest?: AsyncTest;
|
|
10
10
|
groupName?: string;
|
|
11
11
|
message?: string;
|
|
12
12
|
key?: null | string;
|
|
13
13
|
id: string;
|
|
14
14
|
severity: TestSeverity;
|
|
15
15
|
status: KStatus;
|
|
16
|
-
constructor(fieldName: string, testFn:
|
|
16
|
+
constructor(fieldName: string, testFn: TestFn, { message, groupName, key }?: {
|
|
17
17
|
message?: string;
|
|
18
18
|
groupName?: string;
|
|
19
19
|
key?: string;
|
|
20
20
|
});
|
|
21
|
-
run():
|
|
21
|
+
run(): TestResult;
|
|
22
22
|
setStatus(status: KStatus): void;
|
|
23
23
|
warns(): boolean;
|
|
24
24
|
setPending(): void;
|
|
@@ -44,35 +44,40 @@ declare class VestTest {
|
|
|
44
44
|
isWarning(): boolean;
|
|
45
45
|
statusEquals(status: KStatus): boolean;
|
|
46
46
|
}
|
|
47
|
-
type
|
|
48
|
-
type
|
|
49
|
-
type
|
|
47
|
+
type AsyncTest = Promise<string | void>;
|
|
48
|
+
type TestResult = AsyncTest | boolean | void;
|
|
49
|
+
type TestFn = () => TestResult;
|
|
50
50
|
type KStatus = "UNTESTED" | "SKIPPED" | "FAILED" | "WARNING" | "PASSING" | "PENDING" | "CANCELED" | "OMITTED";
|
|
51
|
+
type CB = (...args: any[]) => void;
|
|
51
52
|
/**
|
|
52
53
|
* Reads the testObjects list and gets full validation result from it.
|
|
53
54
|
*/
|
|
54
|
-
declare function genTestsSummary():
|
|
55
|
-
type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
declare function genTestsSummary(): SuiteSummary;
|
|
56
|
+
type Groups = Record<string, TestGroup>;
|
|
57
|
+
type SuiteSummary = {
|
|
58
|
+
groups: Groups;
|
|
59
|
+
tests: TestGroup;
|
|
60
|
+
valid: boolean;
|
|
61
|
+
} & SummaryBase;
|
|
62
|
+
type TestGroup = Record<string, SingleTestSummary>;
|
|
63
|
+
type SingleTestSummary = SummaryBase & {
|
|
61
64
|
errors: string[];
|
|
62
65
|
warnings: string[];
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
valid: boolean;
|
|
67
|
+
};
|
|
68
|
+
type SummaryBase = {
|
|
65
69
|
errorCount: number;
|
|
66
70
|
warnCount: number;
|
|
67
71
|
testCount: number;
|
|
68
72
|
};
|
|
69
|
-
|
|
73
|
+
type FailureMessages = Record<string, string[]>;
|
|
74
|
+
declare function getErrors(): FailureMessages;
|
|
70
75
|
declare function getErrors(fieldName?: string): string[];
|
|
71
|
-
declare function getWarnings():
|
|
76
|
+
declare function getWarnings(): FailureMessages;
|
|
72
77
|
declare function getWarnings(fieldName?: string): string[];
|
|
73
|
-
declare function getErrorsByGroup(groupName: string):
|
|
78
|
+
declare function getErrorsByGroup(groupName: string): FailureMessages;
|
|
74
79
|
declare function getErrorsByGroup(groupName: string, fieldName: string): string[];
|
|
75
|
-
declare function getWarningsByGroup(groupName: string):
|
|
80
|
+
declare function getWarningsByGroup(groupName: string): FailureMessages;
|
|
76
81
|
declare function getWarningsByGroup(groupName: string, fieldName: string): string[];
|
|
77
82
|
declare function hasErrors(fieldName?: string): boolean;
|
|
78
83
|
declare function hasWarnings(fieldName?: string): boolean;
|
|
@@ -95,9 +100,9 @@ type SuiteResult = ReturnType<typeof genTestsSummary> & {
|
|
|
95
100
|
getWarningsByGroup: typeof getWarningsByGroup;
|
|
96
101
|
};
|
|
97
102
|
type SuiteRunResult = SuiteResult & {
|
|
98
|
-
done:
|
|
103
|
+
done: Done;
|
|
99
104
|
};
|
|
100
|
-
interface
|
|
105
|
+
interface Done {
|
|
101
106
|
(...args: [
|
|
102
107
|
cb: (res: SuiteResult) => void
|
|
103
108
|
]): SuiteRunResult;
|
|
@@ -112,8 +117,7 @@ type CreateProperties = {
|
|
|
112
117
|
resetField: (fieldName: string) => void;
|
|
113
118
|
remove: (fieldName: string) => void;
|
|
114
119
|
};
|
|
115
|
-
type CB =
|
|
116
|
-
type SuiteReturnType<T extends CB> = {
|
|
120
|
+
type Suite<T extends CB> = {
|
|
117
121
|
(...args: Parameters<T>): SuiteRunResult;
|
|
118
122
|
} & CreateProperties;
|
|
119
123
|
/**
|
|
@@ -127,8 +131,8 @@ type SuiteReturnType<T extends CB> = {
|
|
|
127
131
|
* });
|
|
128
132
|
* });
|
|
129
133
|
*/
|
|
130
|
-
declare function create<T extends CB>(suiteName: string, suiteCallback: T):
|
|
131
|
-
declare function create<T extends CB>(suiteCallback: T):
|
|
134
|
+
declare function create<T extends CB>(suiteName: string, suiteCallback: T): Suite<T>;
|
|
135
|
+
declare function create<T extends CB>(suiteCallback: T): Suite<T>;
|
|
132
136
|
declare function createCursor(): {
|
|
133
137
|
addLevel: () => void;
|
|
134
138
|
cursorAt: () => number;
|
|
@@ -155,35 +159,35 @@ declare enum Modes {
|
|
|
155
159
|
}
|
|
156
160
|
type NestedArray<T> = Array<NestedArray<T> | T>;
|
|
157
161
|
// eslint-disable-next-line max-lines-per-function
|
|
158
|
-
declare function createState(onStateChange?: (...args: unknown[]) => unknown):
|
|
159
|
-
type
|
|
160
|
-
type
|
|
161
|
-
type
|
|
162
|
-
type
|
|
162
|
+
declare function createState(onStateChange?: (...args: unknown[]) => unknown): CreateStateReturn;
|
|
163
|
+
type StateInput<S> = S | ((prevState?: S) => S);
|
|
164
|
+
type SetStateInput<S> = S | ((prevState: S) => S);
|
|
165
|
+
type State = ReturnType<typeof createState>;
|
|
166
|
+
type StateHandlerReturn<S> = [
|
|
163
167
|
S,
|
|
164
|
-
(nextState:
|
|
168
|
+
(nextState: SetStateInput<S>) => void
|
|
165
169
|
];
|
|
166
|
-
type
|
|
170
|
+
type CreateStateReturn = {
|
|
167
171
|
reset: () => void;
|
|
168
|
-
registerStateKey: <S>(initialState?:
|
|
172
|
+
registerStateKey: <S>(initialState?: StateInput<S> | undefined, onUpdate?: (() => void) | undefined) => () => StateHandlerReturn<S>;
|
|
169
173
|
};
|
|
170
|
-
declare function createStateRef(state:
|
|
174
|
+
declare function createStateRef(state: State, { suiteId, suiteName }: {
|
|
171
175
|
suiteId: string;
|
|
172
176
|
suiteName?: void | string;
|
|
173
177
|
}): {
|
|
174
|
-
optionalFields: () =>
|
|
175
|
-
suiteId: () =>
|
|
176
|
-
suiteName: () =>
|
|
177
|
-
testCallbacks: () =>
|
|
178
|
+
optionalFields: () => StateHandlerReturn<Record<string, boolean | (() => boolean)>>;
|
|
179
|
+
suiteId: () => StateHandlerReturn<string>;
|
|
180
|
+
suiteName: () => StateHandlerReturn<string | void>;
|
|
181
|
+
testCallbacks: () => StateHandlerReturn<{
|
|
178
182
|
fieldCallbacks: Record<string, ((res: SuiteResult) => void)[]>;
|
|
179
183
|
doneCallbacks: ((res: SuiteResult) => void)[];
|
|
180
184
|
}>;
|
|
181
|
-
testObjects: () =>
|
|
185
|
+
testObjects: () => StateHandlerReturn<{
|
|
182
186
|
prev: NestedArray<VestTest>;
|
|
183
187
|
current: NestedArray<VestTest>;
|
|
184
188
|
}>;
|
|
185
189
|
};
|
|
186
|
-
type
|
|
190
|
+
type StateRef = ReturnType<typeof createStateRef>;
|
|
187
191
|
declare const _default: {
|
|
188
192
|
run: <R>(ctxRef: Partial<CTXType>, fn: (context: CTXType) => R) => R;
|
|
189
193
|
bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<CTXType>, fn: Fn) => Fn;
|
|
@@ -196,7 +200,7 @@ type CTXType = {
|
|
|
196
200
|
keys: IsolateKeys;
|
|
197
201
|
};
|
|
198
202
|
testCursor: ReturnType<typeof createCursor>;
|
|
199
|
-
stateRef?:
|
|
203
|
+
stateRef?: StateRef;
|
|
200
204
|
exclusion: {
|
|
201
205
|
tests: Record<string, boolean>;
|
|
202
206
|
groups: Record<string, boolean>;
|
|
@@ -210,11 +214,12 @@ type CTXType = {
|
|
|
210
214
|
Modes
|
|
211
215
|
];
|
|
212
216
|
bus?: {
|
|
213
|
-
on: (event: string, handler:
|
|
217
|
+
on: (event: string, handler: CB) => {
|
|
214
218
|
off: () => void;
|
|
215
219
|
};
|
|
216
220
|
emit: (event: string, ...args: any[]) => void;
|
|
217
221
|
};
|
|
222
|
+
summary?: SuiteSummary;
|
|
218
223
|
};
|
|
219
224
|
declare const context: typeof _default;
|
|
220
225
|
/**
|
|
@@ -231,7 +236,7 @@ declare const context: typeof _default;
|
|
|
231
236
|
* })
|
|
232
237
|
*/
|
|
233
238
|
declare function each<T>(list: T[], callback: (arg: T, index: number) => void): void;
|
|
234
|
-
type
|
|
239
|
+
type ExclusionItem = string | string[] | undefined;
|
|
235
240
|
/**
|
|
236
241
|
* Adds a field or a list of fields into the inclusion list
|
|
237
242
|
*
|
|
@@ -239,9 +244,9 @@ type TExclusionItem = string | string[] | undefined;
|
|
|
239
244
|
*
|
|
240
245
|
* only('username');
|
|
241
246
|
*/
|
|
242
|
-
declare function only(item:
|
|
247
|
+
declare function only(item: ExclusionItem): void;
|
|
243
248
|
declare namespace only {
|
|
244
|
-
var group: (item:
|
|
249
|
+
var group: (item: ExclusionItem) => void;
|
|
245
250
|
}
|
|
246
251
|
/**
|
|
247
252
|
* Adds a field or a list of fields into the exclusion list
|
|
@@ -250,9 +255,9 @@ declare namespace only {
|
|
|
250
255
|
*
|
|
251
256
|
* skip('username');
|
|
252
257
|
*/
|
|
253
|
-
declare function skip(item:
|
|
258
|
+
declare function skip(item: ExclusionItem): void;
|
|
254
259
|
declare namespace skip {
|
|
255
|
-
var group: (item:
|
|
260
|
+
var group: (item: ExclusionItem) => void;
|
|
256
261
|
}
|
|
257
262
|
/**
|
|
258
263
|
* Runs tests within a group so that they can be controlled or queried separately.
|
|
@@ -296,7 +301,7 @@ declare function eager(): void;
|
|
|
296
301
|
* test('username', 'User already taken', async () => await doesUserExist(username)
|
|
297
302
|
* });
|
|
298
303
|
*/
|
|
299
|
-
declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback:
|
|
304
|
+
declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
|
|
300
305
|
/**
|
|
301
306
|
* Marks a field as optional, either just by name, or by a given condition.
|
|
302
307
|
*
|
|
@@ -308,9 +313,9 @@ declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolea
|
|
|
308
313
|
* username: () => allowUsernameEmpty,
|
|
309
314
|
* });
|
|
310
315
|
*/
|
|
311
|
-
declare function optional(optionals:
|
|
312
|
-
type
|
|
313
|
-
type
|
|
316
|
+
declare function optional(optionals: OptionalsInput): void;
|
|
317
|
+
type OptionalsInput = string | string[] | OptionalsObject;
|
|
318
|
+
type OptionalsObject = Record<string, () => boolean>;
|
|
314
319
|
/**
|
|
315
320
|
* Conditionally skips running tests within the callback.
|
|
316
321
|
*
|
|
@@ -320,11 +325,11 @@ type TOptionalsObject = Record<string, () => boolean>;
|
|
|
320
325
|
* test('username', 'User already taken', async () => await doesUserExist(username)
|
|
321
326
|
* });
|
|
322
327
|
*/
|
|
323
|
-
declare function skipWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback:
|
|
324
|
-
declare function testBase(fieldName: string, message: string, cb:
|
|
325
|
-
declare function testBase(fieldName: string, cb:
|
|
326
|
-
declare function testBase(fieldName: string, message: string, cb:
|
|
327
|
-
declare function testBase(fieldName: string, cb:
|
|
328
|
+
declare function skipWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
|
|
329
|
+
declare function testBase(fieldName: string, message: string, cb: TestFn): VestTest;
|
|
330
|
+
declare function testBase(fieldName: string, cb: TestFn): VestTest;
|
|
331
|
+
declare function testBase(fieldName: string, message: string, cb: TestFn, key: string): VestTest;
|
|
332
|
+
declare function testBase(fieldName: string, cb: TestFn, key: string): VestTest;
|
|
328
333
|
/**
|
|
329
334
|
* Represents a single case in a validation suite.
|
|
330
335
|
*
|
|
@@ -336,14 +341,14 @@ declare function testBase(fieldName: string, cb: TTestFn, key: string): VestTest
|
|
|
336
341
|
*/
|
|
337
342
|
declare const test: typeof testBase & {
|
|
338
343
|
memo: {
|
|
339
|
-
(fieldName: string, test:
|
|
340
|
-
(fieldName: string, message: string, test:
|
|
344
|
+
(fieldName: string, test: TestFn, deps: unknown[]): VestTest;
|
|
345
|
+
(fieldName: string, message: string, test: TestFn, deps: unknown[]): VestTest;
|
|
341
346
|
};
|
|
342
347
|
};
|
|
343
348
|
/**
|
|
344
349
|
* Sets a running test to warn only mode.
|
|
345
350
|
*/
|
|
346
351
|
declare function warn(): void;
|
|
347
|
-
declare const VERSION = "4.
|
|
352
|
+
declare const VERSION = "4.3.1";
|
|
348
353
|
export { test, create, each, only, skip, warn, group, optional, skipWhen, omitWhen, enforce, VERSION, context, include, eager };
|
|
349
|
-
export type { SuiteResult, SuiteRunResult, VestTest };
|
|
354
|
+
export type { SuiteResult, SuiteRunResult, SuiteSummary, VestTest, Suite };
|