vest 5.0.0-dev-781e21 → 5.0.0-dev-ec989a

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 (71) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -57
  3. package/dist/cjs/classnames.development.js +37 -17
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/enforce/compose.development.js +1 -54
  6. package/dist/cjs/enforce/compose.production.js +1 -1
  7. package/dist/cjs/enforce/compounds.development.js +18 -84
  8. package/dist/cjs/enforce/compounds.production.js +1 -1
  9. package/dist/cjs/enforce/schema.development.js +18 -84
  10. package/dist/cjs/enforce/schema.production.js +1 -1
  11. package/dist/cjs/parser.development.js +30 -11
  12. package/dist/cjs/parser.production.js +1 -1
  13. package/dist/cjs/promisify.development.js +21 -9
  14. package/dist/cjs/promisify.production.js +1 -1
  15. package/dist/cjs/vest.development.js +1324 -1294
  16. package/dist/cjs/vest.production.js +1 -1
  17. package/dist/es/classnames.development.js +39 -19
  18. package/dist/es/classnames.production.js +1 -1
  19. package/dist/es/enforce/compose.development.js +1 -58
  20. package/dist/es/enforce/compose.production.js +1 -1
  21. package/dist/es/enforce/compounds.development.js +2 -90
  22. package/dist/es/enforce/compounds.production.js +1 -1
  23. package/dist/es/enforce/schema.development.js +2 -88
  24. package/dist/es/enforce/schema.production.js +1 -1
  25. package/dist/es/parser.development.js +31 -10
  26. package/dist/es/parser.production.js +1 -1
  27. package/dist/es/promisify.development.js +22 -10
  28. package/dist/es/promisify.production.js +1 -1
  29. package/dist/es/vest.development.js +1321 -1286
  30. package/dist/es/vest.production.js +1 -1
  31. package/dist/umd/classnames.development.js +40 -20
  32. package/dist/umd/classnames.production.js +1 -1
  33. package/dist/umd/enforce/compose.development.js +6 -60
  34. package/dist/umd/enforce/compose.production.js +1 -1
  35. package/dist/umd/enforce/compounds.development.js +29 -94
  36. package/dist/umd/enforce/compounds.production.js +1 -1
  37. package/dist/umd/enforce/schema.development.js +29 -94
  38. package/dist/umd/enforce/schema.production.js +1 -1
  39. package/dist/umd/parser.development.js +33 -14
  40. package/dist/umd/parser.production.js +1 -1
  41. package/dist/umd/promisify.development.js +24 -12
  42. package/dist/umd/promisify.production.js +1 -1
  43. package/dist/umd/vest.development.js +1327 -1298
  44. package/dist/umd/vest.production.js +1 -1
  45. package/package.json +144 -147
  46. package/testUtils/TVestMock.ts +7 -0
  47. package/testUtils/__tests__/partition.test.ts +4 -4
  48. package/testUtils/asVestTest.ts +9 -0
  49. package/testUtils/mockThrowError.ts +4 -2
  50. package/testUtils/suiteDummy.ts +4 -1
  51. package/testUtils/testDummy.ts +12 -10
  52. package/testUtils/testPromise.ts +3 -0
  53. package/types/classnames.d.ts +141 -12
  54. package/types/classnames.d.ts.map +1 -0
  55. package/types/enforce/compose.d.ts +2 -126
  56. package/types/enforce/compose.d.ts.map +1 -0
  57. package/types/enforce/compounds.d.ts +2 -136
  58. package/types/enforce/compounds.d.ts.map +1 -0
  59. package/types/enforce/schema.d.ts +2 -144
  60. package/types/enforce/schema.d.ts.map +1 -0
  61. package/types/parser.d.ts +147 -18
  62. package/types/parser.d.ts.map +1 -0
  63. package/types/promisify.d.ts +139 -43
  64. package/types/promisify.d.ts.map +1 -0
  65. package/types/vest.d.ts +257 -242
  66. package/types/vest.d.ts.map +1 -0
  67. package/CHANGELOG.md +0 -87
  68. package/testUtils/expandStateRef.ts +0 -8
  69. package/testUtils/runCreateRef.ts +0 -10
  70. package/testUtils/testObjects.ts +0 -6
  71. package/tsconfig.json +0 -8
package/types/vest.d.ts CHANGED
@@ -1,56 +1,58 @@
1
1
  import { enforce } from 'n4s';
2
- type SuiteSummary = {
3
- groups: Groups;
4
- tests: Tests;
5
- valid: boolean;
6
- } & SummaryBase;
7
- type GroupTestSummary = SingleTestSummary;
8
- type Groups = Record<string, Group>;
9
- type Group = Record<string, GroupTestSummary>;
10
- type Tests = Record<string, SingleTestSummary>;
11
- type SingleTestSummary = SummaryBase & {
12
- errors: string[];
13
- warnings: string[];
14
- valid: boolean;
15
- };
16
- type SummaryBase = {
17
- errorCount: number;
18
- warnCount: number;
19
- testCount: number;
20
- };
21
- type FailureMessages = Record<string, string[]>;
2
+ import { Isolate, IsolateKey } from "vest-runtime";
3
+ import { CB } from "vest-utils";
4
+ declare enum Severity {
5
+ WARNINGS = "warnings",
6
+ ERRORS = "errors"
7
+ }
22
8
  declare enum TestSeverity {
23
9
  Error = "error",
24
10
  Warning = "warning"
25
11
  }
26
- declare class VestTest {
27
- fieldName: string;
28
- testFn: TestFn;
29
- asyncTest?: AsyncTest;
12
+ // @vx-allow use-use
13
+ declare function IsolateTestReconciler(currentNode: Isolate, historyNode: Isolate | null): Isolate;
14
+ declare enum TestStatus {
15
+ UNTESTED = "UNTESTED",
16
+ SKIPPED = "SKIPPED",
17
+ FAILED = "FAILED",
18
+ WARNING = "WARNING",
19
+ PASSING = "PASSING",
20
+ PENDING = "PENDING",
21
+ CANCELED = "CANCELED",
22
+ OMITTED = "OMITTED"
23
+ }
24
+ type TestFn = () => TestResult;
25
+ type AsyncTest = Promise<string | void | false>;
26
+ type TestResult = AsyncTest | boolean | void;
27
+ type WithFieldName<F extends TFieldName = TFieldName> = {
28
+ fieldName: F;
29
+ };
30
+ type IsolateTestInput = {
31
+ message?: string;
30
32
  groupName?: string;
33
+ fieldName: TFieldName;
34
+ testFn: TestFn;
35
+ key?: IsolateKey;
36
+ };
37
+ declare class IsolateTest<F extends TFieldName = TFieldName, G extends TGroupName = TGroupName> extends Isolate {
38
+ children: null;
39
+ fieldName: F;
40
+ testFn: TestFn;
41
+ groupName?: G;
31
42
  message?: string;
32
- key?: null | string;
43
+ asyncTest?: AsyncTest;
33
44
  id: string;
34
45
  severity: TestSeverity;
35
- status: KStatus;
36
- constructor(fieldName: string, testFn: TestFn, { message, groupName, key }?: {
37
- message?: string;
38
- groupName?: string;
39
- key?: string;
40
- });
46
+ private stateMachine;
47
+ static reconciler: typeof IsolateTestReconciler;
48
+ constructor({ fieldName, testFn, message, groupName, key }: IsolateTestInput);
49
+ static create<Callback extends CB = CB>(callback: Callback, data: IsolateTestInput): IsolateTest;
50
+ static cast<F extends TFieldName = TFieldName, G extends TGroupName = TGroupName>(isolate: Isolate): IsolateTest<F, G>;
51
+ get status(): TestStatus;
52
+ setStatus(status: TestStatus, payload?: any): void;
41
53
  run(): TestResult;
42
- setStatus(status: KStatus): void;
54
+ // Selectors
43
55
  warns(): boolean;
44
- setPending(): void;
45
- fail(): void;
46
- done(): void;
47
- warn(): void;
48
- isFinalStatus(): boolean;
49
- skip(force?: boolean): void;
50
- cancel(): void;
51
- reset(): void;
52
- omit(): void;
53
- valueOf(): boolean;
54
56
  isPending(): boolean;
55
57
  isOmitted(): boolean;
56
58
  isUntested(): boolean;
@@ -63,172 +65,173 @@ declare class VestTest {
63
65
  isNonActionable(): boolean;
64
66
  isTested(): boolean;
65
67
  awaitsResolution(): boolean;
66
- statusEquals(status: KStatus): boolean;
68
+ statusEquals(status: TestStatus): boolean;
69
+ // State modifiers
70
+ setPending(): void;
71
+ fail(): void;
72
+ pass(): void;
73
+ warn(): void;
74
+ skip(force?: boolean): void;
75
+ cancel(): void;
76
+ reset(): void;
77
+ omit(): void;
78
+ valueOf(): boolean;
79
+ isAsyncTest(): boolean;
80
+ static is(value: any): value is IsolateTest;
81
+ static isX(value: any): asserts value is IsolateTest;
82
+ }
83
+ declare class SummaryFailure<F extends TFieldName, G extends TGroupName> implements WithFieldName<F> {
84
+ fieldName: F;
85
+ message: string | undefined;
86
+ groupName: G | undefined;
87
+ constructor(fieldName: F, message: string | undefined, groupName: G | undefined);
88
+ static fromTestObject<F extends TFieldName, G extends TGroupName>(testObject: IsolateTest<F, G>): SummaryFailure<F, G>;
89
+ toString(): string;
90
+ }
91
+ interface Done<F extends TFieldName, G extends TGroupName> {
92
+ (...args: [
93
+ cb: (res: SuiteResult<F, G>) => void
94
+ ]): SuiteRunResult<F, G>;
95
+ (...args: [
96
+ fieldName: F,
97
+ cb: (res: SuiteResult<F, G>) => void
98
+ ]): SuiteRunResult<F, G>;
67
99
  }
68
- type AsyncTest = Promise<string | void>;
69
- type TestResult = AsyncTest | boolean | void;
70
- type TestFn = () => TestResult;
71
- type KStatus = "UNTESTED" | "SKIPPED" | "FAILED" | "WARNING" | "PASSING" | "PENDING" | "CANCELED" | "OMITTED";
72
- type CB = (...args: any[]) => any;
73
100
  // eslint-disable-next-line max-lines-per-function, max-statements
74
- declare function suiteSelectors(summary: SuiteSummary): SuiteSelectors;
75
- interface SuiteSelectors {
76
- getErrors(fieldName: string): string[];
101
+ declare function suiteSelectors<F extends TFieldName, G extends TGroupName>(summary: SuiteSummary<F, G>): SuiteSelectors<F, G>;
102
+ interface SuiteSelectors<F extends TFieldName, G extends TGroupName> {
103
+ getWarning(fieldName?: F): void | string | SummaryFailure<F, G>;
104
+ getError(fieldName?: F): void | string | SummaryFailure<F, G>;
105
+ getErrors(fieldName: F): string[];
77
106
  getErrors(): FailureMessages;
78
107
  getWarnings(): FailureMessages;
79
- getWarnings(fieldName: string): string[];
80
- getErrorsByGroup(groupName: string, fieldName: string): string[];
81
- getErrorsByGroup(groupName: string): FailureMessages;
82
- getWarningsByGroup(groupName: string): FailureMessages;
83
- getWarningsByGroup(groupName: string, fieldName: string): string[];
84
- hasErrors(fieldName?: string): boolean;
85
- hasWarnings(fieldName?: string): boolean;
86
- hasErrorsByGroup(groupName: string, fieldName?: string): boolean;
87
- hasWarningsByGroup(groupName: string, fieldName?: string): boolean;
88
- isValid(fieldName?: string): boolean;
89
- isValidByGroup(groupName: string, fieldName?: string): boolean;
108
+ getWarnings(fieldName: F): string[];
109
+ getErrorsByGroup(groupName: G, fieldName: F): string[];
110
+ getErrorsByGroup(groupName: G): FailureMessages;
111
+ getWarningsByGroup(groupName: G): FailureMessages;
112
+ getWarningsByGroup(groupName: G, fieldName: F): string[];
113
+ hasErrors(fieldName?: F): boolean;
114
+ hasWarnings(fieldName?: F): boolean;
115
+ hasErrorsByGroup(groupName: G, fieldName?: F): boolean;
116
+ hasWarningsByGroup(groupName: G, fieldName?: F): boolean;
117
+ isValid(fieldName?: F): boolean;
118
+ isValidByGroup(groupName: G, fieldName?: F): boolean;
90
119
  }
91
- type SuiteResult = SuiteSummary & SuiteSelectors & {
92
- suiteName: SuiteName;
120
+ declare class SummaryBase {
121
+ errorCount: number;
122
+ warnCount: number;
123
+ testCount: number;
124
+ }
125
+ declare class SuiteSummary<F extends TFieldName, G extends TGroupName> extends SummaryBase {
126
+ [Severity.ERRORS]: SummaryFailure<F, G>[];
127
+ [Severity.WARNINGS]: SummaryFailure<F, G>[];
128
+ groups: Groups<G, F>;
129
+ tests: Tests<F>;
130
+ valid: boolean;
131
+ }
132
+ type GroupTestSummary = SingleTestSummary;
133
+ type Groups<G extends TGroupName, F extends TFieldName> = Record<G, Group<F>>;
134
+ type Group<F extends TFieldName> = Record<F, GroupTestSummary>;
135
+ type Tests<F extends TFieldName> = Record<F, SingleTestSummary>;
136
+ type SingleTestSummary = SummaryBase & {
137
+ errors: string[];
138
+ warnings: string[];
139
+ valid: boolean;
93
140
  };
94
- type SuiteRunResult = SuiteResult & {
95
- done: Done;
141
+ type FailureMessages = Record<string, string[]>;
142
+ type SuiteResult<F extends TFieldName, G extends TGroupName> = SuiteSummary<F, G> & SuiteSelectors<F, G> & {
143
+ suiteName: SuiteName;
96
144
  };
97
- interface Done {
98
- (...args: [
99
- cb: (res: SuiteResult) => void
100
- ]): SuiteRunResult;
101
- (...args: [
102
- fieldName: string,
103
- cb: (res: SuiteResult) => void
104
- ]): SuiteRunResult;
105
- }
106
- type CreateProperties = {
107
- get: () => SuiteResult;
108
- reset: () => void;
109
- resetField: (fieldName: string) => void;
110
- remove: (fieldName: string) => void;
145
+ type SuiteRunResult<F extends TFieldName, G extends TGroupName> = SuiteResult<F, G> & {
146
+ done: Done<F, G>;
111
147
  };
112
- type Suite<T extends CB> = {
113
- (...args: Parameters<T>): SuiteRunResult;
114
- } & CreateProperties;
148
+ type SuiteName = string | undefined;
149
+ type TFieldName<T extends string = string> = T;
150
+ type TGroupName<G extends string = string> = G;
151
+ type OptionalsInput<F extends TFieldName> = F | F[] | OptionalsObject<F>;
152
+ type OptionalsObject<F extends TFieldName> = Record<F, (() => boolean) | boolean>;
153
+ // @vx-allow use-use
154
+ declare function optional<F extends TFieldName>(optionals: OptionalsInput<F>): void;
155
+ type FieldExclusion<F extends TFieldName> = F | F[] | undefined;
156
+ type GroupExclusion<G extends TGroupName> = G | G[] | undefined;
115
157
  /**
116
- * Creates a new validation suite
158
+ * Adds a field or a list of fields into the inclusion list
117
159
  *
118
160
  * @example
119
161
  *
120
- * const suite = create((data = {}) => {
121
- * test("username", "Username is required", () => {
122
- * enforce(data.username).isNotBlank();
123
- * });
124
- * });
162
+ * only('username');
125
163
  */
126
- declare function create<T extends CB>(suiteName: SuiteName, suiteCallback: T): Suite<T>;
127
- declare function create<T extends CB>(suiteCallback: T): Suite<T>;
128
- type SuiteName = string | void;
129
- type IsolateCursor = {
130
- current: () => number;
131
- next: () => void;
132
- };
133
- declare enum IsolateTypes {
134
- DEFAULT = 0,
135
- SUITE = 1,
136
- EACH = 2,
137
- SKIP_WHEN = 3,
138
- OMIT_WHEN = 4,
139
- GROUP = 5
140
- }
141
- type IsolateKeys = {
142
- current: Record<string, VestTest>;
143
- prev: Record<string, VestTest>;
144
- };
145
- type Isolate = {
146
- type: IsolateTypes;
147
- keys: IsolateKeys;
148
- path: number[];
149
- cursor: IsolateCursor;
150
- };
151
- declare enum Modes {
152
- ALL = 0,
153
- EAGER = 1
164
+ // @vx-allow use-use
165
+ declare function only<F extends TFieldName>(item: FieldExclusion<F>): void;
166
+ declare namespace only {
167
+ var group: <G extends string>(item: GroupExclusion<G>) => void;
154
168
  }
155
- type NestedArray<T> = Array<NestedArray<T> | T>;
156
- type SetStateInput<S> = S | ((prevState: S) => S);
157
- type StateHandlerReturn<S> = [
158
- S,
159
- (nextState: SetStateInput<S>) => void
160
- ];
161
- type UseState<S> = () => StateHandlerReturn<S>;
162
169
  /**
163
- * Marks a field as optional, either just by name, or by a given condition.
170
+ * Adds a field or a list of fields into the exclusion list
164
171
  *
165
172
  * @example
166
173
  *
167
- * optional('field_name');
168
- *
169
- * optional({
170
- * username: () => allowUsernameEmpty,
171
- * });
174
+ * skip('username');
172
175
  */
173
- declare function optional(optionals: OptionalsInput): void;
174
- type OptionalsInput = string | string[] | OptionalsObject;
175
- type OptionalsObject = Record<string, (() => boolean) | boolean>;
176
- type ImmediateOptionalFieldDeclaration = {
177
- type: OptionalFieldTypes.Immediate;
178
- rule: boolean | (() => boolean);
179
- applied: boolean;
180
- };
181
- type DelayedOptionalFieldDeclaration = {
182
- type: OptionalFieldTypes.Delayed;
183
- applied: boolean;
184
- rule: null;
185
- };
186
- type OptionalFieldDeclaration = ImmediateOptionalFieldDeclaration | DelayedOptionalFieldDeclaration;
187
- declare enum OptionalFieldTypes {
188
- Immediate = 0,
189
- Delayed = 1
176
+ // @vx-allow use-use
177
+ declare function skip<F extends TFieldName>(item: FieldExclusion<F>): void;
178
+ declare namespace skip {
179
+ var group: <G extends string>(item: GroupExclusion<G>) => void;
190
180
  }
191
- type StateRef = {
192
- optionalFields: UseState<OptionalFields>;
193
- suiteId: UseState<string>;
194
- suiteName: UseState<SuiteName>;
195
- testCallbacks: UseState<TestCallbacks>;
196
- testObjects: UseState<TestObjects>;
197
- };
198
- type OptionalFields = Record<string, OptionalFieldDeclaration>;
199
- type TestCallbacks = {
200
- fieldCallbacks: Record<string, Array<(res: SuiteResult) => void>>;
201
- doneCallbacks: Array<(res: SuiteResult) => void>;
181
+ declare function vestTest<F extends TFieldName>(fieldName: F, message: string, cb: TestFn): IsolateTest;
182
+ declare function vestTest<F extends TFieldName>(fieldName: F, cb: TestFn): IsolateTest;
183
+ declare function vestTest<F extends TFieldName>(fieldName: F, message: string, cb: TestFn, key: IsolateKey): IsolateTest;
184
+ declare function vestTest<F extends TFieldName>(fieldName: F, cb: TestFn, key: IsolateKey): IsolateTest;
185
+ declare const test: typeof vestTest & {
186
+ memo: TestMemo<string>;
202
187
  };
203
- type TestObjects = {
204
- prev: VestTests;
205
- current: VestTests;
188
+ type TestMemo<F extends TFieldName> = {
189
+ (fieldName: F, ...args: ParametersWithoutMessage): IsolateTest;
190
+ (fieldName: F, ...args: ParametersWithMessage): IsolateTest;
206
191
  };
207
- type VestTests = NestedArray<VestTest>;
208
- declare const _default: import("context").CtxCascadeApi<CTXType>;
209
- type CTXType = {
210
- isolate: Isolate;
211
- stateRef?: StateRef;
212
- exclusion: {
213
- tests: Record<string, boolean>;
214
- groups: Record<string, boolean>;
192
+ type ParametersWithoutMessage = [
193
+ test: TestFn,
194
+ dependencies: unknown[]
195
+ ];
196
+ type ParametersWithMessage = [
197
+ message: string,
198
+ test: TestFn,
199
+ dependencies: unknown[]
200
+ ];
201
+ type TTypedMethods<F extends TFieldName, G extends TGroupName> = {
202
+ include: (fieldName: F) => {
203
+ when: (condition: boolean | F | ((draft: SuiteResult<F, G>) => boolean)) => void;
215
204
  };
216
- inclusion: Record<string, boolean | (() => boolean)>;
217
- currentTest?: VestTest;
218
- groupName?: string;
219
- skipped?: boolean;
220
- omitted?: boolean;
221
- mode: [
222
- Modes
223
- ];
224
- bus?: {
225
- on: (event: string, handler: CB) => {
226
- off: () => void;
227
- };
228
- emit: (event: string, ...args: any[]) => void;
205
+ omitWhen: (conditional: boolean | ((draft: SuiteResult<F, G>) => boolean), callback: CB) => void;
206
+ only: {
207
+ (item: FieldExclusion<F>): void;
208
+ group(item: GroupExclusion<G>): void;
209
+ };
210
+ optional: (optionals: OptionalsInput<F>) => void;
211
+ skip: {
212
+ (item: FieldExclusion<F>): void;
213
+ group(item: GroupExclusion<G>): void;
214
+ };
215
+ skipWhen: (condition: boolean | ((draft: SuiteResult<F, G>) => boolean), callback: CB) => void;
216
+ test: {
217
+ (fieldName: F, message: string, cb: TestFn): IsolateTest;
218
+ (fieldName: F, cb: TestFn): IsolateTest;
219
+ (fieldName: F, message: string, cb: TestFn, key: IsolateKey): IsolateTest;
220
+ (fieldName: F, cb: TestFn, key: IsolateKey): IsolateTest;
221
+ } & {
222
+ memo: TestMemo<F>;
229
223
  };
224
+ group: (groupName: G, callback: () => void) => Isolate;
230
225
  };
231
- declare const context: typeof _default;
226
+ type Suite<F extends TFieldName, G extends TGroupName, T extends CB = CB> = ((...args: Parameters<T>) => SuiteRunResult<F, G>) & SuiteMethods<F, G>;
227
+ type SuiteMethods<F extends TFieldName, G extends TGroupName> = {
228
+ get: () => SuiteResult<F, G>;
229
+ reset: () => void;
230
+ remove: (fieldName: F) => void;
231
+ resetField: (fieldName: F) => void;
232
+ } & TTypedMethods<F, G> & SuiteSelectors<F, G>;
233
+ declare function createSuite<F extends TFieldName = string, G extends TGroupName = string, T extends CB = CB>(suiteName: SuiteName, suiteCallback: T): Suite<F, G, T>;
234
+ declare function createSuite<F extends TFieldName = string, G extends TGroupName = string, T extends CB = CB>(suiteCallback: T): Suite<F, G, T>;
232
235
  /**
233
236
  * Iterates over an array of items, allowing to run tests individually per item.
234
237
  *
@@ -243,62 +246,56 @@ declare const context: typeof _default;
243
246
  * })
244
247
  */
245
248
  declare function each<T>(list: T[], callback: (arg: T, index: number) => void): void;
246
- type ExclusionItem = string | string[] | undefined;
249
+ declare function group<G extends TGroupName>(groupName: G, callback: () => void): Isolate;
247
250
  /**
248
- * Adds a field or a list of fields into the inclusion list
251
+ * Conditionally includes a field for testing, based on specified criteria.
249
252
  *
250
- * @example
251
- *
252
- * only('username');
253
- */
254
- declare function only(item: ExclusionItem): void;
255
- declare namespace only {
256
- var group: (item: ExclusionItem) => void;
257
- }
258
- /**
259
- * Adds a field or a list of fields into the exclusion list
253
+ * @param {string} fieldName - The name of the field to include for testing.
260
254
  *
261
255
  * @example
256
+ * include('confirm').when('password');
257
+ * // Includes the "confirm" field for testing when the "password" field is included
262
258
  *
263
- * skip('username');
264
- */
265
- declare function skip(item: ExclusionItem): void;
266
- declare namespace skip {
267
- var group: (item: ExclusionItem) => void;
268
- }
269
- /**
270
- * Runs tests within a group so that they can be controlled or queried separately.
259
+ * include('confirm').when(someValue);
260
+ * // Includes the "confirm" field for testing when the value of `someValue` is true
271
261
  *
272
- * @example
262
+ * include('confirm').when(() => someValue);
263
+ * // Includes the "confirm" field for testing when the callback function returns true
273
264
  *
274
- * group('group_name', () => {
275
- * // Tests go here
276
- * });
265
+ * include('username').when(result => result.hasErrors('username'));
266
+ * // Includes the "username" field for testing when there are errors associated with it in the current suite result
277
267
  */
278
- declare function group(groupName: string, tests: () => void): void;
279
- declare function include(fieldName: string): {
280
- when: (condition: string | boolean | ((draft: SuiteResult) => boolean)) => void;
268
+ // @vx-allow use-use
269
+ declare function include<F extends TFieldName, G extends TGroupName>(fieldName: F): {
270
+ when: (condition: F | TFieldName | boolean | ((draft: SuiteResult<F, G>) => boolean)) => void;
281
271
  };
272
+ declare enum Modes {
273
+ EAGER = "EAGER",
274
+ ALL = "ALL",
275
+ ONE = "ONE"
276
+ }
282
277
  /**
283
- * Sets the suite to "eager" (fail fast) mode.
284
- * Eager mode will skip running subsequent tests of a failing fields.
278
+ * Sets the current execution mode for the current suite.
279
+ *
280
+ * Supported modes:
281
+ * - `EAGER` - (default) Runs all tests, but stops on first failure for each given field.
282
+ * - `ALL` - Runs all tests, regardless of failures.
283
+ * - `ONE` - Stops suite execution on first failure of any field.
285
284
  *
286
285
  * @example
287
- * // in the following example, the second test of username will not run
288
- * // if the first test of username failed.
289
- * const suite = create((data) => {
290
- * eager();
286
+ * ```js
287
+ * import {Modes, create} from 'vest';
291
288
  *
292
- * test('username', 'username is required', () => {
293
- * enforce(data.username).isNotBlank();
294
- * });
289
+ * const suite = create('suite_name', () => {
290
+ * vest.mode(Modes.ALL);
295
291
  *
296
- * test('username', 'username is too short', () => {
297
- * enforce(data.username).longerThan(2);
298
- * });
292
+ * // ...
299
293
  * });
294
+ * ```
295
+ * @param 'ALL' | 'EAGER' | 'ONE' mode - The mode to set.
300
296
  */
301
- declare function eager(): void;
297
+ // @vx-allow use-use
298
+ declare function mode(mode: Modes): void;
302
299
  /**
303
300
  * Conditionally omits tests from the suite.
304
301
  *
@@ -308,7 +305,8 @@ declare function eager(): void;
308
305
  * test('username', 'User already taken', async () => await doesUserExist(username)
309
306
  * });
310
307
  */
311
- declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
308
+ // @vx-allow use-use
309
+ declare function omitWhen<F extends TFieldName, G extends TGroupName>(conditional: boolean | ((draft: SuiteResult<F, G>) => boolean), callback: CB): void;
312
310
  /**
313
311
  * Conditionally skips running tests within the callback.
314
312
  *
@@ -318,30 +316,47 @@ declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolea
318
316
  * test('username', 'User already taken', async () => await doesUserExist(username)
319
317
  * });
320
318
  */
321
- declare function skipWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
322
- declare function testBase(fieldName: string, message: string, cb: TestFn): VestTest;
323
- declare function testBase(fieldName: string, cb: TestFn): VestTest;
324
- declare function testBase(fieldName: string, message: string, cb: TestFn, key: string): VestTest;
325
- declare function testBase(fieldName: string, cb: TestFn, key: string): VestTest;
319
+ // @vx-allow use-use
320
+ declare function skipWhen<F extends TFieldName, G extends TGroupName>(condition: boolean | ((draft: SuiteResult<F, G>) => boolean), callback: CB): void;
326
321
  /**
327
- * Represents a single case in a validation suite.
322
+ * Creates a static suite for server-side validation.
323
+ *
324
+ * @param {Function} validationFn - The validation function that defines the suite's tests.
325
+ * @returns {Function} - A function that runs the validations defined in the suite.
328
326
  *
329
327
  * @example
328
+ * import { staticSuite, test, enforce } from 'vest';
330
329
  *
331
- * test("username", "Username is required", () => {
332
- * enforce(data.username).isNotBlank();
330
+ * const suite = staticSuite(data => {
331
+ * test('username', 'username is required', () => {
332
+ * enforce(data.username).isNotEmpty();
333
+ * });
333
334
  * });
335
+ *
336
+ * suite(data);
334
337
  */
335
- declare const test: typeof testBase & {
336
- memo: {
337
- (fieldName: string, test: TestFn, deps: unknown[]): VestTest;
338
- (fieldName: string, message: string, test: TestFn, deps: unknown[]): VestTest;
339
- };
340
- };
338
+ declare function staticSuite<F extends TFieldName = string, G extends TGroupName = string, T extends CB = CB>(suiteCallback: T): StaticSuite<F, G, T>;
339
+ type StaticSuite<F extends TFieldName = string, G extends TGroupName = string, T extends CB = CB> = ((...args: Parameters<T>) => SuiteRunResult<F, G>) & TTypedMethods<F, G>;
341
340
  /**
342
- * Sets a running test to warn only mode.
341
+ * Sets the severity level of a test to `warn`, allowing it to fail without marking the suite as invalid.
342
+ * Use this function within the body of a test to create warn-only tests.
343
+ *
344
+ * @returns {void}
345
+ *
346
+ * @example
347
+ * test('password', 'Your password strength is: WEAK', () => {
348
+ * warn();
349
+ *
350
+ * enforce(data.password).matches(/0-9/);
351
+ * });
352
+ *
353
+ * @limitations
354
+ * - The `warn` function should only be used within the body of a `test` function.
355
+ * - When using `warn()` in an async test, it should be called in the synchronous portion of the test, not after an `await` call or in the Promise body.
356
+ * - It is recommended to call `warn()` at the top of the test function.
343
357
  */
358
+ // @vx-allow use-use
344
359
  declare function warn(): void;
345
- declare const VERSION = "5.0.0-dev-781e21";
346
- export { suiteSelectors, test, create, each, only, skip, warn, group, optional, skipWhen, omitWhen, enforce, VERSION, context, include, eager };
347
- export type { SuiteResult, SuiteRunResult, SuiteSummary, VestTest, Suite };
360
+ export { createSuite as create, test, group, optional, enforce, skip, skipWhen, omitWhen, only, warn, include, suiteSelectors, each, mode, staticSuite, Modes };
361
+ export type { SuiteResult, SuiteRunResult, SuiteSummary, IsolateTest, Suite };
362
+ //# sourceMappingURL=vest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vest.d.ts","sourceRoot":"","sources":["../src/vest.ts","../src/suiteResult/Severity.ts","../src/errors/ErrorStrings.ts","../src/core/test/TestTypes.ts","../src/core/test/helpers/matchingFieldName.ts","../src/core/isolate/IsolateTest/isSameProfileTest.ts","../src/core/isolate/IsolateTest/cancelOverriddenPendingTest.ts","../src/core/isolate/IsolateTest/TestWalker.ts","../src/core/test/helpers/matchingGroupName.ts","../src/core/test/helpers/nonMatchingSeverityProfile.ts","../src/suiteResult/selectors/hasFailuresByTestObjects.ts","../src/hooks/mode.ts","../src/core/context/SuiteContext.ts","../src/core/Runtime.ts","../src/suiteResult/selectors/shouldAddValidProperty.ts","../src/suiteResult/selectors/produceSuiteSummary.ts","../src/suiteResult/selectors/collectFailures.ts","../src/suiteResult/selectors/suiteSelectors.ts","../src/suiteResult/suiteResult.ts","../src/isolates/skipWhen.ts","../src/hooks/exclusive.ts","../src/isolates/omitWhen.ts","../src/core/test/testLevelFlowControl/verifyTestRun.ts","../src/core/isolate/IsolateTest/IsolateTestReconciler.ts","../src/core/isolate/IsolateTest/IsolateTestStateMachine.ts","../src/core/test/helpers/shouldUseErrorMessage.ts","../src/core/isolate/IsolateTest/IsolateTest.ts","../src/suiteResult/SummaryFailure.ts","../src/suiteResult/done/deferDoneCallback.ts","../src/suiteResult/done/shouldSkipDoneRegistration.ts","../src/suiteResult/suiteRunResult.ts","../src/suiteResult/SuiteResultTypes.ts","../src/hooks/optional/OptionalTypes.ts","../src/core/isolate/IsolateSuite/IsolateSuite.ts","../src/hooks/optional/optional.ts","../src/hooks/include.ts","../src/core/VestBus/BusEvents.ts","../src/core/test/testLevelFlowControl/runTest.ts","../src/core/test/test.memo.ts","../src/core/test/test.ts","../src/suite/getTypedMethods.ts","../src/suite/SuiteTypes.ts","../src/hooks/optional/omitOptionalFields.ts","../src/suite/runCallbacks.ts","../src/core/VestBus/VestBus.ts","../src/suite/validateParams/validateSuiteParams.ts","../src/suite/createSuite.ts","../src/core/isolate/IsolateEach/IsolateEach.ts","../src/isolates/each.ts","../src/isolates/group.ts","../src/suite/staticSuite.ts","../src/hooks/warn.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwB9B,OAAO,wJAiBN,CAAC;AAEF,YAAY,iEAAiE,CAAC"}