vest 5.0.0-dev-781e21 → 5.0.2-dev-d315d9

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 (182) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -57
  3. package/dist/cjs/classnames.development.js +18 -16
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/enforce/compose.development.js +5 -54
  6. package/dist/cjs/enforce/compose.production.js +1 -1
  7. package/dist/cjs/enforce/compounds.development.js +20 -83
  8. package/dist/cjs/enforce/compounds.production.js +1 -1
  9. package/dist/cjs/enforce/schema.development.js +19 -82
  10. package/dist/cjs/enforce/schema.production.js +1 -1
  11. package/dist/cjs/parser.development.js +12 -9
  12. package/dist/cjs/parser.production.js +1 -1
  13. package/dist/cjs/promisify.development.js +4 -8
  14. package/dist/cjs/promisify.production.js +1 -1
  15. package/dist/cjs/vest.development.js +1287 -1153
  16. package/dist/cjs/vest.production.js +1 -1
  17. package/dist/es/classnames.development.js +20 -18
  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 +12 -9
  26. package/dist/es/parser.production.js +1 -1
  27. package/dist/es/promisify.development.js +5 -9
  28. package/dist/es/promisify.production.js +1 -1
  29. package/dist/es/vest.development.js +1286 -1148
  30. package/dist/es/vest.production.js +1 -1
  31. package/dist/umd/classnames.development.js +21 -19
  32. package/dist/umd/classnames.production.js +1 -1
  33. package/dist/umd/enforce/compose.development.js +9 -57
  34. package/dist/umd/enforce/compose.production.js +1 -1
  35. package/dist/umd/enforce/compounds.development.js +32 -94
  36. package/dist/umd/enforce/compounds.production.js +1 -1
  37. package/dist/umd/enforce/schema.development.js +32 -94
  38. package/dist/umd/enforce/schema.production.js +1 -1
  39. package/dist/umd/parser.development.js +16 -13
  40. package/dist/umd/parser.production.js +1 -1
  41. package/dist/umd/promisify.development.js +7 -11
  42. package/dist/umd/promisify.production.js +1 -1
  43. package/dist/umd/vest.development.js +1289 -1155
  44. package/dist/umd/vest.production.js +1 -1
  45. package/package.json +12 -16
  46. package/src/__tests__/__snapshots__/integration.async-tests.test.ts.snap +71 -0
  47. package/src/__tests__/__snapshots__/integration.base.test.ts.snap +71 -0
  48. package/src/__tests__/__snapshots__/integration.stateful-async.test.ts.snap +243 -0
  49. package/src/__tests__/__snapshots__/integration.stateful-tests.test.ts.snap +376 -0
  50. package/src/__tests__/integration.async-tests.test.ts +90 -0
  51. package/src/__tests__/integration.base.test.ts +45 -0
  52. package/src/__tests__/integration.exclusive.test.ts +88 -0
  53. package/src/__tests__/integration.stateful-async.test.ts +137 -0
  54. package/src/__tests__/integration.stateful-tests.test.ts +155 -0
  55. package/src/__tests__/isolate.test.ts +288 -0
  56. package/src/__tests__/state_refill.test.ts +41 -0
  57. package/src/core/SuiteWalker/SuiteWalker.ts +64 -0
  58. package/src/core/SuiteWalker/__tests__/hasRemainingTests.test.ts +130 -0
  59. package/src/core/VestBus/VestBus.ts +78 -0
  60. package/src/core/context/PersistedContext.ts +243 -0
  61. package/src/core/context/SuiteContext.ts +74 -0
  62. package/src/core/isolate/IsolateTest/IsolateTest.ts +213 -0
  63. package/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +156 -0
  64. package/src/core/isolate/IsolateTest/IsolateTestStateMachine.ts +69 -0
  65. package/src/core/isolate/IsolateTest/SimpleStateMachine.ts +43 -0
  66. package/src/core/isolate/IsolateTest/TestWalker.ts +77 -0
  67. package/src/core/isolate/IsolateTypes.ts +10 -0
  68. package/src/core/isolate/isIsolate.ts +6 -0
  69. package/src/core/isolate/isolate.ts +110 -0
  70. package/src/core/isolate/reconciler/Reconciler/Reconciler.ts +123 -0
  71. package/src/core/isolate/reconciler/cancelOverriddenPendingTest.ts +15 -0
  72. package/src/core/isolate/reconciler/isSameProfileTest.ts +12 -0
  73. package/src/core/isolate/walker.ts +127 -0
  74. package/src/core/test/TestTypes.ts +3 -0
  75. package/src/core/test/__tests__/IsolateTest.test.ts +152 -0
  76. package/src/core/test/__tests__/__snapshots__/IsolateTest.test.ts.snap +39 -0
  77. package/src/core/test/__tests__/__snapshots__/memo.test.ts.snap +101 -0
  78. package/src/core/test/__tests__/__snapshots__/test.test.ts.snap +231 -0
  79. package/src/core/test/__tests__/key.test.ts +195 -0
  80. package/src/core/test/__tests__/memo.test.ts +218 -0
  81. package/src/core/test/__tests__/merging_of_previous_test_runs.test.ts +341 -0
  82. package/src/core/test/__tests__/runAsyncTest.test.ts +175 -0
  83. package/src/core/test/__tests__/test.test.ts +226 -0
  84. package/src/core/test/helpers/__tests__/nonMatchingSeverityProfile.test.ts +52 -0
  85. package/src/core/test/helpers/asVestTest.ts +9 -0
  86. package/src/core/test/helpers/matchingFieldName.ts +16 -0
  87. package/src/core/test/helpers/matchingGroupName.ts +12 -0
  88. package/src/core/test/helpers/nonMatchingSeverityProfile.ts +14 -0
  89. package/src/core/test/helpers/shouldUseErrorMessage.ts +9 -0
  90. package/src/core/test/test.memo.ts +81 -0
  91. package/src/core/test/test.ts +64 -0
  92. package/src/core/test/testLevelFlowControl/runTest.ts +86 -0
  93. package/src/core/test/testLevelFlowControl/verifyTestRun.ts +32 -0
  94. package/src/core/test/testObjectIsolate.ts +11 -0
  95. package/src/errors/ErrorStrings.ts +4 -0
  96. package/src/exports/__tests__/classnames.test.ts +92 -0
  97. package/src/exports/__tests__/parser.test.ts +441 -0
  98. package/src/exports/__tests__/promisify.test.ts +77 -0
  99. package/src/exports/classnames.ts +35 -0
  100. package/src/exports/enforce@compose.ts +1 -0
  101. package/src/exports/enforce@compounds.ts +1 -0
  102. package/src/exports/enforce@schema.ts +1 -0
  103. package/src/exports/parser.ts +63 -0
  104. package/src/exports/promisify.ts +18 -0
  105. package/src/hooks/__tests__/__snapshots__/include.test.ts.snap +794 -0
  106. package/src/hooks/__tests__/eager.test.ts +130 -0
  107. package/src/hooks/__tests__/exclusive.test.ts +578 -0
  108. package/src/hooks/__tests__/include.test.ts +431 -0
  109. package/src/hooks/__tests__/optional.test.ts +83 -0
  110. package/src/hooks/__tests__/warn.test.ts +42 -0
  111. package/src/hooks/exclusive.ts +179 -0
  112. package/src/hooks/include.ts +54 -0
  113. package/src/hooks/mode.ts +47 -0
  114. package/src/hooks/optional/OptionalTypes.ts +31 -0
  115. package/src/hooks/optional/optional.ts +69 -0
  116. package/src/hooks/warn.ts +19 -0
  117. package/src/isolates/__tests__/__snapshots__/each.test.ts.snap +3 -0
  118. package/src/isolates/__tests__/__snapshots__/group.test.ts.snap +114 -0
  119. package/src/isolates/__tests__/__snapshots__/omitWhen.test.ts.snap +443 -0
  120. package/src/isolates/__tests__/__snapshots__/skipWhen.test.ts.snap +99 -0
  121. package/src/isolates/__tests__/each.test.ts +35 -0
  122. package/src/isolates/__tests__/group.test.ts +362 -0
  123. package/src/isolates/__tests__/omitWhen.test.ts +246 -0
  124. package/src/isolates/__tests__/skipWhen.test.ts +163 -0
  125. package/src/isolates/each.ts +30 -0
  126. package/src/isolates/group.ts +9 -0
  127. package/src/isolates/omitWhen.ts +41 -0
  128. package/src/isolates/skipWhen.ts +42 -0
  129. package/src/suite/__tests__/__snapshots__/create.test.ts.snap +67 -0
  130. package/src/suite/__tests__/create.test.ts +109 -0
  131. package/src/suite/__tests__/remove.test.ts +50 -0
  132. package/src/suite/__tests__/resetField.test.ts +74 -0
  133. package/src/suite/createSuite.ts +94 -0
  134. package/src/suite/runCallbacks.ts +28 -0
  135. package/src/suiteResult/Severity.ts +15 -0
  136. package/src/suiteResult/SuiteResultTypes.ts +42 -0
  137. package/src/suiteResult/__tests__/done.test.ts +334 -0
  138. package/src/suiteResult/__tests__/produce.test.ts +163 -0
  139. package/src/suiteResult/done/deferDoneCallback.ts +28 -0
  140. package/src/suiteResult/done/shouldSkipDoneRegistration.ts +20 -0
  141. package/src/suiteResult/selectors/__tests__/__snapshots__/collectFailureMessages.test.ts.snap +89 -0
  142. package/src/suiteResult/selectors/__tests__/collectFailureMessages.test.ts +124 -0
  143. package/src/suiteResult/selectors/__tests__/getFailures.test.ts +158 -0
  144. package/src/suiteResult/selectors/__tests__/getFailuresByGroup.test.ts +199 -0
  145. package/src/suiteResult/selectors/__tests__/hasFailures.test.ts +141 -0
  146. package/src/suiteResult/selectors/__tests__/hasFailuresByGroup.test.ts +185 -0
  147. package/src/suiteResult/selectors/__tests__/hasFailuresByTestObject.test.ts +88 -0
  148. package/src/suiteResult/selectors/__tests__/isValid.test.ts +359 -0
  149. package/src/suiteResult/selectors/__tests__/isValidByGroup.test.ts +480 -0
  150. package/src/suiteResult/selectors/collectFailures.ts +43 -0
  151. package/src/suiteResult/selectors/hasFailuresByTestObjects.ts +62 -0
  152. package/src/suiteResult/selectors/produceSuiteSummary.ts +135 -0
  153. package/src/suiteResult/selectors/shouldAddValidProperty.ts +148 -0
  154. package/src/suiteResult/selectors/suiteSelectors.ts +199 -0
  155. package/src/suiteResult/suiteResult.ts +15 -0
  156. package/src/suiteResult/suiteRunResult.ts +43 -0
  157. package/src/vest.ts +36 -0
  158. package/testUtils/TVestMock.ts +5 -0
  159. package/testUtils/__tests__/partition.test.ts +4 -4
  160. package/testUtils/mockThrowError.ts +4 -2
  161. package/testUtils/suiteDummy.ts +2 -1
  162. package/testUtils/testDummy.ts +12 -10
  163. package/testUtils/testPromise.ts +3 -0
  164. package/tsconfig.json +84 -2
  165. package/types/classnames.d.ts +39 -4
  166. package/types/classnames.d.ts.map +1 -0
  167. package/types/enforce/compose.d.ts +2 -126
  168. package/types/enforce/compose.d.ts.map +1 -0
  169. package/types/enforce/compounds.d.ts +2 -136
  170. package/types/enforce/compounds.d.ts.map +1 -0
  171. package/types/enforce/schema.d.ts +2 -144
  172. package/types/enforce/schema.d.ts.map +1 -0
  173. package/types/parser.d.ts +45 -10
  174. package/types/parser.d.ts.map +1 -0
  175. package/types/promisify.d.ts +36 -34
  176. package/types/promisify.d.ts.map +1 -0
  177. package/types/vest.d.ts +169 -224
  178. package/types/vest.d.ts.map +1 -0
  179. package/CHANGELOG.md +0 -87
  180. package/testUtils/expandStateRef.ts +0 -8
  181. package/testUtils/runCreateRef.ts +0 -10
  182. package/testUtils/testObjects.ts +0 -6
@@ -0,0 +1,179 @@
1
+ import {
2
+ isStringValue,
3
+ asArray,
4
+ hasOwnProperty,
5
+ optionalFunctionValue,
6
+ } from 'vest-utils';
7
+
8
+ import { ErrorStrings } from 'ErrorStrings';
9
+ import { IsolateTest } from 'IsolateTest';
10
+ import { useExclusion, useInclusion } from 'SuiteContext';
11
+ import { TFieldName } from 'SuiteResultTypes';
12
+ import { isExcludedIndividually } from 'skipWhen';
13
+
14
+ type ExclusionItem = string | string[] | undefined;
15
+ type FieldExclusion<F extends TFieldName> = F | F[] | undefined;
16
+
17
+ /**
18
+ * Adds a field or a list of fields into the inclusion list
19
+ *
20
+ * @example
21
+ *
22
+ * only('username');
23
+ */
24
+ export function only<F extends TFieldName>(item: FieldExclusion<F>): void {
25
+ return addTo(ExclusionGroup.ONLY, 'tests', item);
26
+ }
27
+
28
+ only.group = (item: ExclusionItem) =>
29
+ addTo(ExclusionGroup.ONLY, 'groups', item);
30
+
31
+ /**
32
+ * Adds a field or a list of fields into the exclusion list
33
+ *
34
+ * @example
35
+ *
36
+ * skip('username');
37
+ */
38
+ export function skip<F extends TFieldName>(item: FieldExclusion<F>): void {
39
+ return addTo(ExclusionGroup.SKIP, 'tests', item);
40
+ }
41
+
42
+ skip.group = (item: ExclusionItem) =>
43
+ addTo(ExclusionGroup.SKIP, 'groups', item);
44
+
45
+ //Checks whether a certain test profile excluded by any of the exclusion groups.
46
+
47
+ // eslint-disable-next-line complexity, max-statements
48
+ export function isExcluded(testObject: IsolateTest): boolean {
49
+ const { fieldName, groupName } = testObject;
50
+
51
+ if (isExcludedIndividually()) return true;
52
+
53
+ const exclusion = useExclusion();
54
+ const inclusion = useInclusion();
55
+ const keyTests = exclusion.tests;
56
+ const testValue = keyTests[fieldName];
57
+
58
+ // if test is skipped
59
+ // no need to proceed
60
+ if (testValue === false) return true;
61
+
62
+ const isTestIncluded = testValue === true;
63
+
64
+ // If inside a group
65
+ if (groupName) {
66
+ if (isGroupExcluded(groupName)) {
67
+ return true; // field excluded by group
68
+
69
+ // if group is `only`ed
70
+ } else if (exclusion.groups[groupName] === true) {
71
+ if (isTestIncluded) return false;
72
+
73
+ // If there is _ANY_ `only`ed test (and we already know this one isn't)
74
+ if (hasIncludedTests(keyTests)) return true; // Excluded implicitly
75
+
76
+ return keyTests[fieldName] === false;
77
+ }
78
+ }
79
+
80
+ if (isTopLevelWhenThereIsAnIncludedGroup(groupName)) {
81
+ return true;
82
+ }
83
+
84
+ // if field is only'ed
85
+ if (isTestIncluded) return false;
86
+
87
+ // If there is _ANY_ `only`ed test (and we already know this one isn't) return true
88
+ if (hasIncludedTests(keyTests)) {
89
+ // Check if inclusion rules for this field (`include` hook)
90
+ // TODO: Check if this may need to be moved outside of the condition.
91
+ // What if there are no included tests? This shouldn't run then?
92
+ return !optionalFunctionValue(inclusion[fieldName]);
93
+ }
94
+
95
+ // We're done here. This field is not excluded
96
+ return false;
97
+ }
98
+
99
+ /**
100
+ * Checks whether a given group is excluded from running.
101
+ */
102
+ export function isGroupExcluded(groupName: string): boolean {
103
+ const exclusion = useExclusion();
104
+ const keyGroups = exclusion.groups;
105
+
106
+ const groupPresent = hasOwnProperty(keyGroups, groupName);
107
+
108
+ // When group is either only'ed or skipped
109
+ if (groupPresent) {
110
+ // Return true if group is skipped and false if only'ed
111
+ return keyGroups[groupName] === false;
112
+ }
113
+
114
+ // Group is not present
115
+
116
+ // Return whether other groups are included
117
+ return hasIncludedGroups();
118
+ }
119
+
120
+ /**
121
+ * Adds fields to a specified exclusion group.
122
+ */
123
+ function addTo(
124
+ exclusionGroup: ExclusionGroup,
125
+ itemType: 'tests' | 'groups',
126
+ item: ExclusionItem
127
+ ) {
128
+ const exclusion = useExclusion(ErrorStrings.HOOK_CALLED_OUTSIDE);
129
+
130
+ if (!item) {
131
+ return;
132
+ }
133
+
134
+ asArray(item).forEach((itemName: string): void => {
135
+ if (!isStringValue(itemName)) {
136
+ return;
137
+ }
138
+
139
+ exclusion[itemType][itemName] = exclusionGroup === ExclusionGroup.ONLY;
140
+ });
141
+ }
142
+
143
+ /**
144
+ * Checks if context has included tests
145
+ */
146
+ function hasIncludedTests(keyTests: Record<string, boolean>): boolean {
147
+ for (const test in keyTests) {
148
+ if (keyTests[test] === true) {
149
+ return true; // excluded implicitly
150
+ }
151
+ }
152
+ return false;
153
+ }
154
+
155
+ // are we not in a group and there is an included group?
156
+ function isTopLevelWhenThereIsAnIncludedGroup(groupName?: string): boolean {
157
+ if (!hasIncludedGroups()) {
158
+ return false;
159
+ }
160
+
161
+ // Return whether there's an included group, and we're not inside a group
162
+ return !groupName;
163
+ }
164
+
165
+ function hasIncludedGroups(): boolean {
166
+ const exclusion = useExclusion();
167
+
168
+ for (const group in exclusion.groups) {
169
+ if (exclusion.groups[group]) {
170
+ return true;
171
+ }
172
+ }
173
+ return false;
174
+ }
175
+
176
+ const enum ExclusionGroup {
177
+ ONLY,
178
+ SKIP,
179
+ }
@@ -0,0 +1,54 @@
1
+ import {
2
+ isStringValue,
3
+ defaultTo,
4
+ hasOwnProperty,
5
+ invariant,
6
+ optionalFunctionValue,
7
+ } from 'vest-utils';
8
+
9
+ import { useExclusion, useInclusion } from 'SuiteContext';
10
+ import { SuiteResult, TFieldName } from 'SuiteResultTypes';
11
+ import { createSuiteResult } from 'suiteResult';
12
+
13
+ export function include<F extends TFieldName>(
14
+ fieldName: F
15
+ ): {
16
+ when: (
17
+ condition: F | TFieldName | boolean | ((draft: SuiteResult<F>) => boolean)
18
+ ) => void;
19
+ } {
20
+ const inclusion = useInclusion();
21
+ const exclusion = useExclusion();
22
+
23
+ invariant(isStringValue(fieldName));
24
+
25
+ inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
26
+
27
+ return { when };
28
+
29
+ function when(
30
+ condition: F | TFieldName | ((draft: SuiteResult<F>) => boolean) | boolean
31
+ ): void {
32
+ const inclusion = useInclusion();
33
+ const exclusion = useExclusion();
34
+
35
+ // This callback will run as part of the "isExcluded" series of checks
36
+ inclusion[fieldName] = (): boolean => {
37
+ if (hasOwnProperty(exclusion.tests, fieldName)) {
38
+ // I suspect this code is technically unreachable because
39
+ // if there are any skip/only rules applied to the current
40
+ // field, the "isExcluded" function will have already bailed
41
+ return defaultTo(exclusion.tests[fieldName], true);
42
+ }
43
+
44
+ if (isStringValue(condition)) {
45
+ return Boolean(exclusion.tests[condition]);
46
+ }
47
+
48
+ return optionalFunctionValue(
49
+ condition,
50
+ optionalFunctionValue(createSuiteResult)
51
+ );
52
+ };
53
+ }
54
+ }
@@ -0,0 +1,47 @@
1
+ import { IsolateTest } from 'IsolateTest';
2
+ import { useMode } from 'SuiteContext';
3
+ import { hasErrorsByTestObjects } from 'hasFailuresByTestObjects';
4
+
5
+ export enum Modes {
6
+ ALL,
7
+ EAGER,
8
+ }
9
+
10
+ /**
11
+ * Sets the suite to "eager" (fail fast) mode.
12
+ * Eager mode will skip running subsequent tests of a failing fields.
13
+ *
14
+ * @example
15
+ * // in the following example, the second test of username will not run
16
+ * // if the first test of username failed.
17
+ * const suite = create((data) => {
18
+ * eager();
19
+ *
20
+ * test('username', 'username is required', () => {
21
+ * enforce(data.username).isNotBlank();
22
+ * });
23
+ *
24
+ * test('username', 'username is too short', () => {
25
+ * enforce(data.username).longerThan(2);
26
+ * });
27
+ * });
28
+ */
29
+ export function eager() {
30
+ const [, setMode] = useMode();
31
+
32
+ setMode(Modes.EAGER);
33
+ }
34
+
35
+ function isMode(mode: Modes): boolean {
36
+ const [currentMode] = useMode();
37
+
38
+ return currentMode === mode;
39
+ }
40
+
41
+ function isEager(): boolean {
42
+ return isMode(Modes.EAGER);
43
+ }
44
+
45
+ export function shouldSkipBasedOnMode(testObject: IsolateTest): boolean {
46
+ return isEager() && hasErrorsByTestObjects(testObject.fieldName);
47
+ }
@@ -0,0 +1,31 @@
1
+ import { TFieldName } from 'SuiteResultTypes';
2
+
3
+ export type OptionalFields = Record<string, OptionalFieldDeclaration>;
4
+
5
+ export type OptionalsInput<F extends TFieldName> = F | F[] | OptionalsObject<F>;
6
+
7
+ type OptionalsObject<F extends TFieldName> = Record<
8
+ F,
9
+ (() => boolean) | boolean
10
+ >;
11
+
12
+ type ImmediateOptionalFieldDeclaration = {
13
+ type: OptionalFieldTypes.Immediate;
14
+ rule: boolean | (() => boolean);
15
+ applied: boolean;
16
+ };
17
+
18
+ type DelayedOptionalFieldDeclaration = {
19
+ type: OptionalFieldTypes.Delayed;
20
+ applied: boolean;
21
+ rule: null;
22
+ };
23
+
24
+ export type OptionalFieldDeclaration =
25
+ | ImmediateOptionalFieldDeclaration
26
+ | DelayedOptionalFieldDeclaration;
27
+
28
+ export enum OptionalFieldTypes {
29
+ Immediate,
30
+ Delayed,
31
+ }
@@ -0,0 +1,69 @@
1
+ import {
2
+ isArray,
3
+ isStringValue,
4
+ asArray,
5
+ optionalFunctionValue,
6
+ assign,
7
+ } from 'vest-utils';
8
+
9
+ import {
10
+ OptionalFieldDeclaration,
11
+ OptionalFieldTypes,
12
+ OptionalsInput,
13
+ } from 'OptionalTypes';
14
+ import { useOptionalField, useOptionalFields } from 'PersistedContext';
15
+ import { TFieldName } from 'SuiteResultTypes';
16
+
17
+ export function optional<F extends TFieldName>(
18
+ optionals: OptionalsInput<F>
19
+ ): void {
20
+ // There are two types of optional field declarations:
21
+
22
+ // 1. Delayed: A string, which is the name of the field to be optional.
23
+ // We will only determine whether to omit the test after the suite is done running
24
+ //
25
+ // 2. Immediate: Either a boolean or a function, which is used to determine
26
+ // if the field should be optional.
27
+
28
+ // Delayed case (field name)
29
+ if (isArray(optionals) || isStringValue(optionals)) {
30
+ asArray(optionals).forEach(optionalField => {
31
+ useSetOptionalField(optionalField, () => ({
32
+ type: OptionalFieldTypes.Delayed,
33
+ applied: false,
34
+ rule: null,
35
+ }));
36
+ });
37
+ } else {
38
+ // Immediately case (function or boolean)
39
+ for (const field in optionals) {
40
+ const value = optionals[field];
41
+
42
+ useSetOptionalField(field, () => ({
43
+ type: OptionalFieldTypes.Immediate,
44
+ rule: value,
45
+ applied: optionalFunctionValue(value),
46
+ }));
47
+ }
48
+ }
49
+ }
50
+
51
+ export function isOptionalFiedApplied(fieldName?: TFieldName) {
52
+ if (!fieldName) {
53
+ return false;
54
+ }
55
+
56
+ return useOptionalField(fieldName).applied;
57
+ }
58
+
59
+ function useSetOptionalField(
60
+ fieldName: TFieldName,
61
+ setter: (current: OptionalFieldDeclaration) => OptionalFieldDeclaration
62
+ ): void {
63
+ const current = useOptionalFields();
64
+ const currentField = useOptionalField(fieldName);
65
+
66
+ assign(current, {
67
+ [fieldName]: assign({}, currentField, setter(currentField)),
68
+ });
69
+ }
@@ -0,0 +1,19 @@
1
+ import { invariant } from 'vest-utils';
2
+
3
+ import { ErrorStrings } from 'ErrorStrings';
4
+ import { useCurrentTest } from 'SuiteContext';
5
+
6
+ const ERROR_OUTSIDE_OF_TEST = __DEV__
7
+ ? "warn hook called outside of a test callback. It won't have an effect."
8
+ : 'warn called outside of a test.';
9
+
10
+ /**
11
+ * Sets a running test to warn only mode.
12
+ */
13
+ export function warn(): void {
14
+ const currentTest = useCurrentTest(ErrorStrings.HOOK_CALLED_OUTSIDE);
15
+
16
+ invariant(currentTest, ERROR_OUTSIDE_OF_TEST);
17
+
18
+ currentTest.warn();
19
+ }
@@ -0,0 +1,3 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`each When callback is not a function should throw 1`] = `"each callback must be a function"`;
@@ -0,0 +1,114 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`group: base case Group validity 1`] = `
4
+ {
5
+ "done": [Function],
6
+ "errorCount": 4,
7
+ "getErrors": [Function],
8
+ "getErrorsByGroup": [Function],
9
+ "getWarnings": [Function],
10
+ "getWarningsByGroup": [Function],
11
+ "groups": {
12
+ "group_1": {
13
+ "field_1": {
14
+ "errorCount": 0,
15
+ "errors": [],
16
+ "testCount": 1,
17
+ "valid": true,
18
+ "warnCount": 0,
19
+ "warnings": [],
20
+ },
21
+ "field_2": {
22
+ "errorCount": 1,
23
+ "errors": [],
24
+ "testCount": 2,
25
+ "valid": false,
26
+ "warnCount": 0,
27
+ "warnings": [],
28
+ },
29
+ },
30
+ "group_2": {
31
+ "field_1": {
32
+ "errorCount": 1,
33
+ "errors": [],
34
+ "testCount": 1,
35
+ "valid": false,
36
+ "warnCount": 0,
37
+ "warnings": [],
38
+ },
39
+ "field_2": {
40
+ "errorCount": 0,
41
+ "errors": [],
42
+ "testCount": 1,
43
+ "valid": true,
44
+ "warnCount": 0,
45
+ "warnings": [],
46
+ },
47
+ },
48
+ "group_3": {
49
+ "field_1": {
50
+ "errorCount": 1,
51
+ "errors": [],
52
+ "testCount": 1,
53
+ "valid": false,
54
+ "warnCount": 0,
55
+ "warnings": [],
56
+ },
57
+ "field_2": {
58
+ "errorCount": 1,
59
+ "errors": [],
60
+ "testCount": 1,
61
+ "valid": false,
62
+ "warnCount": 0,
63
+ "warnings": [],
64
+ },
65
+ },
66
+ "group_4": {
67
+ "field_1": {
68
+ "errorCount": 0,
69
+ "errors": [],
70
+ "testCount": 1,
71
+ "valid": true,
72
+ "warnCount": 0,
73
+ "warnings": [],
74
+ },
75
+ "field_2": {
76
+ "errorCount": 0,
77
+ "errors": [],
78
+ "testCount": 1,
79
+ "valid": true,
80
+ "warnCount": 0,
81
+ "warnings": [],
82
+ },
83
+ },
84
+ },
85
+ "hasErrors": [Function],
86
+ "hasErrorsByGroup": [Function],
87
+ "hasWarnings": [Function],
88
+ "hasWarningsByGroup": [Function],
89
+ "isValid": [Function],
90
+ "isValidByGroup": [Function],
91
+ "suiteName": undefined,
92
+ "testCount": 9,
93
+ "tests": {
94
+ "field_1": {
95
+ "errorCount": 2,
96
+ "errors": [],
97
+ "testCount": 4,
98
+ "valid": false,
99
+ "warnCount": 0,
100
+ "warnings": [],
101
+ },
102
+ "field_2": {
103
+ "errorCount": 2,
104
+ "errors": [],
105
+ "testCount": 5,
106
+ "valid": false,
107
+ "warnCount": 0,
108
+ "warnings": [],
109
+ },
110
+ },
111
+ "valid": false,
112
+ "warnCount": 0,
113
+ }
114
+ `;