vest 4.2.3-dev-87ebfa → 4.3.2-dev-2805e3

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