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,148 @@
1
+ import { isOptionalFiedApplied } from 'optional';
2
+
3
+ import { IsolateTest } from 'IsolateTest';
4
+ import { OptionalFieldTypes } from 'OptionalTypes';
5
+ import { useOptionalField } from 'PersistedContext';
6
+ import { Severity } from 'Severity';
7
+ import { TFieldName } from 'SuiteResultTypes';
8
+ import { TestWalker } from 'TestWalker';
9
+ import {
10
+ hasErrorsByTestObjects,
11
+ hasGroupFailuresByTestObjects,
12
+ } from 'hasFailuresByTestObjects';
13
+ import { nonMatchingFieldName } from 'matchingFieldName';
14
+ import { nonMatchingGroupName } from 'matchingGroupName';
15
+
16
+ export function shouldAddValidProperty(fieldName?: TFieldName): boolean {
17
+ // Is the field optional, and the optional condition is applied
18
+ if (isOptionalFiedApplied(fieldName)) {
19
+ return true;
20
+ }
21
+
22
+ // Are there no tests?
23
+ if (TestWalker.hasNoTests()) {
24
+ return false;
25
+ }
26
+
27
+ // // Does the field have any tests with errors?
28
+ if (hasErrorsByTestObjects(fieldName)) {
29
+ return false;
30
+ }
31
+
32
+ // Does the given field have any pending tests that are not optional?
33
+ if (hasNonOptionalIncomplete(fieldName)) {
34
+ return false;
35
+ }
36
+
37
+ // Does the field have no missing tests?
38
+ return noMissingTests(fieldName);
39
+ }
40
+
41
+ export function shouldAddValidPropertyInGroup(
42
+ groupName: string,
43
+ fieldName: TFieldName
44
+ ): boolean {
45
+ if (isOptionalFiedApplied(fieldName)) {
46
+ return true;
47
+ }
48
+
49
+ if (hasGroupFailuresByTestObjects(Severity.ERRORS, groupName, fieldName)) {
50
+ return false;
51
+ }
52
+
53
+ // Do the given group/field have any pending tests that are not optional?
54
+ if (hasNonOptionalIncompleteByGroup(groupName, fieldName)) {
55
+ return false;
56
+ }
57
+
58
+ return noMissingTestsByGroup(groupName, fieldName);
59
+ }
60
+
61
+ // Does the given field have any pending tests that are not optional?
62
+ function hasNonOptionalIncomplete(fieldName?: TFieldName) {
63
+ return TestWalker.someIncompleteTests(testObject => {
64
+ return isTestObjectOptional(testObject, fieldName);
65
+ });
66
+ }
67
+
68
+ // Do the given group/field have any pending tests that are not optional?
69
+ function hasNonOptionalIncompleteByGroup(
70
+ groupName: string,
71
+ fieldName: TFieldName
72
+ ): boolean {
73
+ return TestWalker.someIncompleteTests(testObject => {
74
+ if (nonMatchingGroupName(testObject, groupName)) {
75
+ return false;
76
+ }
77
+
78
+ return isTestObjectOptional(testObject, fieldName);
79
+ });
80
+ }
81
+
82
+ function isTestObjectOptional(
83
+ testObject: IsolateTest,
84
+ fieldName?: TFieldName
85
+ ): boolean {
86
+ if (nonMatchingFieldName(testObject, fieldName)) {
87
+ return false;
88
+ }
89
+
90
+ return isOptionalFiedApplied(fieldName);
91
+ }
92
+
93
+ // Did all of the tests for the provided field run/omit?
94
+ // This makes sure that the fields are not skipped or pending.
95
+ function noMissingTests(fieldName?: string): boolean {
96
+ return TestWalker.everyTest(testObject => {
97
+ return noMissingTestsLogic(testObject, fieldName);
98
+ });
99
+ }
100
+
101
+ // Does the group have no missing tests?
102
+ function noMissingTestsByGroup(
103
+ groupName: string,
104
+ fieldName?: TFieldName
105
+ ): boolean {
106
+ return TestWalker.everyTest(testObject => {
107
+ if (nonMatchingGroupName(testObject, groupName)) {
108
+ return true;
109
+ }
110
+
111
+ return noMissingTestsLogic(testObject, fieldName);
112
+ });
113
+ }
114
+
115
+ function noMissingTestsLogic(
116
+ testObject: IsolateTest,
117
+ fieldName?: TFieldName
118
+ ): boolean {
119
+ if (nonMatchingFieldName(testObject, fieldName)) {
120
+ return true;
121
+ }
122
+
123
+ /**
124
+ * The reason we're checking for the optional field here and not in "omitOptionalFields"
125
+ * is because that unlike the bool/function check we do there, here it only depends on
126
+ * whether the field was tested alredy or not.
127
+ *
128
+ * We qualify the test as not missing only if it was already run, if it is omitted,
129
+ * or if it is marked as optional, even if the optional check did not apply yet -
130
+ * but the test did not reach its final state.
131
+ */
132
+
133
+ return (
134
+ optionalTestAwaitsResolution(testObject) ||
135
+ testObject.isTested() ||
136
+ testObject.isOmitted()
137
+ );
138
+ }
139
+
140
+ function optionalTestAwaitsResolution(testObject: IsolateTest): boolean {
141
+ // Does the test belong to an optional field,
142
+ // and the test itself is still in an indeterminate state?
143
+
144
+ return (
145
+ useOptionalField(testObject.fieldName).type ===
146
+ OptionalFieldTypes.Delayed && testObject.awaitsResolution()
147
+ );
148
+ }
@@ -0,0 +1,199 @@
1
+ import { isPositive } from 'vest-utils';
2
+
3
+ import { Severity, SeverityCount } from 'Severity';
4
+ import {
5
+ FailureMessages,
6
+ GetFailuresResponse,
7
+ SuiteSummary,
8
+ TFieldName,
9
+ TestsContainer,
10
+ } from 'SuiteResultTypes';
11
+ import { gatherFailures } from 'collectFailures';
12
+
13
+ // eslint-disable-next-line max-lines-per-function, max-statements
14
+ export function suiteSelectors<F extends TFieldName>(
15
+ summary: SuiteSummary<F>
16
+ ): SuiteSelectors<F> {
17
+ const selectors = {
18
+ getErrors,
19
+ getErrorsByGroup,
20
+ getWarnings,
21
+ getWarningsByGroup,
22
+ hasErrors,
23
+ hasErrorsByGroup,
24
+ hasWarnings,
25
+ hasWarningsByGroup,
26
+ isValid,
27
+ isValidByGroup,
28
+ };
29
+
30
+ return selectors;
31
+
32
+ // Booleans
33
+
34
+ function isValid(fieldName?: F): boolean {
35
+ return fieldName ? Boolean(summary.tests[fieldName]?.valid) : summary.valid;
36
+ }
37
+
38
+ function isValidByGroup(groupName: string, fieldName?: F): boolean {
39
+ const group = summary.groups[groupName];
40
+
41
+ if (!group) {
42
+ return false;
43
+ }
44
+
45
+ if (fieldName) {
46
+ return isFieldValid(group, fieldName);
47
+ }
48
+ for (const fieldName in group) {
49
+ if (!isFieldValid(group, fieldName)) {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ return true;
55
+ }
56
+
57
+ function hasWarnings(fieldName?: F): boolean {
58
+ return hasFailures(summary, SeverityCount.WARN_COUNT, fieldName);
59
+ }
60
+
61
+ function hasErrors(fieldName?: F): boolean {
62
+ return hasFailures(summary, SeverityCount.ERROR_COUNT, fieldName);
63
+ }
64
+
65
+ function hasWarningsByGroup(groupName: string, fieldName?: F): boolean {
66
+ return hasFailuresByGroup(
67
+ summary,
68
+ SeverityCount.WARN_COUNT,
69
+ groupName,
70
+ fieldName
71
+ );
72
+ }
73
+
74
+ function hasErrorsByGroup(groupName: string, fieldName?: F): boolean {
75
+ return hasFailuresByGroup(
76
+ summary,
77
+ SeverityCount.ERROR_COUNT,
78
+ groupName,
79
+ fieldName
80
+ );
81
+ }
82
+
83
+ // Responses
84
+
85
+ function getWarnings(): FailureMessages;
86
+ function getWarnings(fieldName: F): string[];
87
+ function getWarnings(fieldName?: F): GetFailuresResponse {
88
+ return getFailures(summary, Severity.WARNINGS, fieldName);
89
+ }
90
+
91
+ function getErrors(): FailureMessages;
92
+ function getErrors(fieldName: F): string[];
93
+ function getErrors(fieldName?: F): GetFailuresResponse {
94
+ return getFailures(summary, Severity.ERRORS, fieldName);
95
+ }
96
+ function getErrorsByGroup(groupName: string): FailureMessages;
97
+ function getErrorsByGroup(groupName: string, fieldName: F): string[];
98
+ function getErrorsByGroup(
99
+ groupName: string,
100
+ fieldName?: F
101
+ ): GetFailuresResponse {
102
+ return getFailuresByGroup(summary, Severity.ERRORS, groupName, fieldName);
103
+ }
104
+
105
+ function getWarningsByGroup(groupName: string): FailureMessages;
106
+ function getWarningsByGroup(groupName: string, fieldName: F): string[];
107
+ function getWarningsByGroup(
108
+ groupName: string,
109
+ fieldName?: F
110
+ ): GetFailuresResponse {
111
+ return getFailuresByGroup(summary, Severity.WARNINGS, groupName, fieldName);
112
+ }
113
+ }
114
+
115
+ export interface SuiteSelectors<F extends TFieldName> {
116
+ getErrors(fieldName: F): string[];
117
+ getErrors(): FailureMessages;
118
+ getWarnings(): FailureMessages;
119
+ getWarnings(fieldName: F): string[];
120
+ getErrorsByGroup(groupName: string, fieldName: F): string[];
121
+ getErrorsByGroup(groupName: string): FailureMessages;
122
+ getWarningsByGroup(groupName: string): FailureMessages;
123
+ getWarningsByGroup(groupName: string, fieldName: F): string[];
124
+ hasErrors(fieldName?: F): boolean;
125
+ hasWarnings(fieldName?: F): boolean;
126
+ hasErrorsByGroup(groupName: string, fieldName?: F): boolean;
127
+ hasWarningsByGroup(groupName: string, fieldName?: F): boolean;
128
+ isValid(fieldName?: F): boolean;
129
+ isValidByGroup(groupName: string, fieldName?: F): boolean;
130
+ }
131
+
132
+ // Gathers all failures of a given severity
133
+ // With a fieldName, it will only gather failures for that field
134
+ function getFailures(
135
+ summary: SuiteSummary<TFieldName>,
136
+ severityKey: Severity,
137
+ fieldName?: TFieldName
138
+ ): GetFailuresResponse {
139
+ return gatherFailures(summary.tests, severityKey, fieldName);
140
+ }
141
+
142
+ // Gathers all failures of a given severity within a group
143
+ // With a fieldName, it will only gather failures for that field
144
+ function getFailuresByGroup(
145
+ summary: SuiteSummary<TFieldName>,
146
+ severityKey: Severity,
147
+ groupName: string,
148
+ fieldName?: TFieldName
149
+ ): GetFailuresResponse {
150
+ return gatherFailures(summary.groups[groupName], severityKey, fieldName);
151
+ }
152
+ // Checks if a field is valid within a container object - can be within a group or top level
153
+ function isFieldValid(
154
+ testContainer: TestsContainer<TFieldName>,
155
+ fieldName: TFieldName
156
+ ): boolean {
157
+ return !!testContainer[fieldName]?.valid;
158
+ }
159
+
160
+ // Checks if a there are any failures of a given severity within a group
161
+ // If a fieldName is provided, it will only check for failures within that field
162
+ function hasFailuresByGroup(
163
+ summary: SuiteSummary<TFieldName>,
164
+ severityCount: SeverityCount,
165
+ groupName: string,
166
+ fieldName?: TFieldName
167
+ ): boolean {
168
+ const group = summary.groups[groupName];
169
+
170
+ if (!group) {
171
+ return false;
172
+ }
173
+
174
+ if (fieldName) {
175
+ return isPositive(group[fieldName]?.[severityCount]);
176
+ }
177
+
178
+ for (const field in group) {
179
+ if (isPositive(group[field]?.[severityCount])) {
180
+ return true;
181
+ }
182
+ }
183
+
184
+ return false;
185
+ }
186
+
187
+ // Checks if there are any failures of a given severity
188
+ // If a fieldName is provided, it will only check for failures within that field
189
+ function hasFailures(
190
+ summary: SuiteSummary<TFieldName>,
191
+ countKey: SeverityCount,
192
+ fieldName?: TFieldName
193
+ ): boolean {
194
+ const failureCount = fieldName
195
+ ? summary.tests[fieldName]?.[countKey]
196
+ : summary[countKey] || 0;
197
+
198
+ return isPositive(failureCount);
199
+ }
@@ -0,0 +1,15 @@
1
+ import { assign } from 'vest-utils';
2
+
3
+ import { useSuiteName, useSuiteResultCache } from 'PersistedContext';
4
+ import { SuiteResult, TFieldName } from 'SuiteResultTypes';
5
+ import { produceSuiteSummary } from 'produceSuiteSummary';
6
+ import { suiteSelectors } from 'suiteSelectors';
7
+
8
+ export function createSuiteResult<F extends TFieldName>(): SuiteResult<F> {
9
+ const summary = produceSuiteSummary();
10
+ const suiteName = useSuiteName();
11
+
12
+ return useSuiteResultCache(() =>
13
+ assign(summary, suiteSelectors(summary), { suiteName })
14
+ );
15
+ }
@@ -0,0 +1,43 @@
1
+ import { assign } from 'vest-utils';
2
+
3
+ import { persist } from 'PersistedContext';
4
+ import { SuiteResult, SuiteRunResult, TFieldName } from 'SuiteResultTypes';
5
+ import { TestWalker } from 'TestWalker';
6
+ import { deferDoneCallback } from 'deferDoneCallback';
7
+ import { shouldSkipDoneRegistration } from 'shouldSkipDoneRegistration';
8
+ import { createSuiteResult } from 'suiteResult';
9
+
10
+ export function suiteRunResult<F extends TFieldName>(): SuiteRunResult<F> {
11
+ return assign({}, createSuiteResult(), {
12
+ done: persist(done),
13
+ });
14
+ }
15
+
16
+ /**
17
+ * Registers done callbacks.
18
+ * @register {Object} Vest output object.
19
+ */
20
+ function done<F extends TFieldName>(...args: any[]): SuiteRunResult<F> {
21
+ const [callback, fieldName] = args.reverse() as [
22
+ (res: SuiteResult<F>) => void,
23
+ string
24
+ ];
25
+ const output = suiteRunResult();
26
+ if (shouldSkipDoneRegistration(callback, fieldName, output)) {
27
+ return output;
28
+ }
29
+ const doneCallback = () => callback(createSuiteResult());
30
+ if (!TestWalker.hasRemainingTests(fieldName)) {
31
+ doneCallback();
32
+ return output;
33
+ }
34
+ deferDoneCallback(doneCallback, fieldName);
35
+ return output;
36
+ }
37
+
38
+ export interface Done<F extends TFieldName> {
39
+ (...args: [cb: (res: SuiteResult<F>) => void]): SuiteRunResult<F>;
40
+ (
41
+ ...args: [fieldName: F, cb: (res: SuiteResult<F>) => void]
42
+ ): SuiteRunResult<F>;
43
+ }
package/src/vest.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { enforce } from 'n4s';
2
+ import { optional } from 'optional';
3
+
4
+ import { IsolateTest } from 'IsolateTest';
5
+ import type { SuiteResult, SuiteRunResult } from 'SuiteResultTypes';
6
+ import { SuiteSummary } from 'SuiteResultTypes';
7
+ import { createSuite, Suite } from 'createSuite';
8
+ import { each } from 'each';
9
+ import { skip, only } from 'exclusive';
10
+ import { group } from 'group';
11
+ import { include } from 'include';
12
+ import { eager } from 'mode';
13
+ import { omitWhen } from 'omitWhen';
14
+ import { skipWhen } from 'skipWhen';
15
+ import { suiteSelectors } from 'suiteSelectors';
16
+ import { test } from 'test';
17
+ import { warn } from 'warn';
18
+
19
+ export {
20
+ createSuite as create,
21
+ test,
22
+ group,
23
+ optional,
24
+ enforce,
25
+ skip,
26
+ skipWhen,
27
+ omitWhen,
28
+ only,
29
+ warn,
30
+ include,
31
+ suiteSelectors,
32
+ eager,
33
+ each,
34
+ };
35
+
36
+ export type { SuiteResult, SuiteRunResult, SuiteSummary, IsolateTest, Suite };
@@ -0,0 +1,5 @@
1
+ import * as vest from 'vest';
2
+
3
+ export type TVestMock = typeof vest;
4
+
5
+ export type TTestSuite = vest.Suite<(...args: any[]) => void, string>;
@@ -1,17 +1,17 @@
1
- import { partition } from 'vest-utils';
1
+ import partition from '../partition';
2
2
 
3
3
  describe('partition', () => {
4
4
  it('Should correctly partition array', () => {
5
5
  expect(partition([300, 200, 10, 50, 0, -500], v => v <= 100))
6
6
  .toMatchInlineSnapshot(`
7
- Array [
8
- Array [
7
+ [
8
+ [
9
9
  10,
10
10
  50,
11
11
  0,
12
12
  -500,
13
13
  ],
14
- Array [
14
+ [
15
15
  300,
16
16
  200,
17
17
  ],
@@ -1,11 +1,13 @@
1
+ import { TVestMock } from './TVestMock';
2
+
1
3
  export default function mockThrowError() {
2
- const deferThrow = jest.fn();
4
+ const deferThrow = jest.fn<string, any>();
3
5
  jest.resetModules();
4
6
  jest.mock('vest-utils', () => ({
5
7
  ...jest.requireActual('vest-utils'),
6
8
  deferThrow,
7
9
  }));
8
- const vest = require('vest');
10
+ const vest = require('vest') as TVestMock;
9
11
 
10
12
  return {
11
13
  deferThrow,
@@ -2,6 +2,7 @@ import { asArray } from 'vest-utils';
2
2
 
3
3
  import { dummyTest } from './testDummy';
4
4
 
5
+ import { TFieldName } from 'SuiteResultTypes';
5
6
  import { optional, create, skip, SuiteResult } from 'vest';
6
7
 
7
8
  export function failing(failingFields?: string | string[]) {
@@ -103,6 +104,6 @@ function createSuite(
103
104
  });
104
105
  }
105
106
 
106
- export function ser(res: SuiteResult) {
107
+ export function ser<F extends TFieldName>(res: SuiteResult<F>) {
107
108
  return JSON.parse(JSON.stringify(res));
108
109
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable jest/valid-title */
2
- import faker from 'faker';
2
+ import { faker } from '@faker-js/faker';
3
3
 
4
- import { test, warn } from 'vest';
4
+ import { test as vestTest, warn } from 'vest';
5
5
 
6
6
  /**
7
7
  * Generates dummy vest tests.
@@ -12,7 +12,7 @@ const testDummy = () => {
12
12
  message: string = faker.random.words(),
13
13
  groupName?: string
14
14
  ) => {
15
- const to = test(
15
+ const to = vestTest(
16
16
  name,
17
17
  message,
18
18
  jest.fn(() => {
@@ -32,7 +32,7 @@ const testDummy = () => {
32
32
  message = faker.random.words(),
33
33
  groupName?: string
34
34
  ) => {
35
- const to = test(
35
+ const to = vestTest(
36
36
  name,
37
37
  message,
38
38
  jest.fn(() => {
@@ -53,7 +53,7 @@ const testDummy = () => {
53
53
  message = faker.random.words(),
54
54
  groupName?: string
55
55
  ) => {
56
- const to = test(name, message, jest.fn());
56
+ const to = vestTest(name, message, jest.fn());
57
57
 
58
58
  if (groupName) {
59
59
  to.groupName = groupName;
@@ -67,7 +67,7 @@ const testDummy = () => {
67
67
  message = faker.random.words(),
68
68
  groupName?: string
69
69
  ) => {
70
- const to = test(
70
+ const to = vestTest(
71
71
  name,
72
72
  message,
73
73
  jest.fn(() => {
@@ -84,7 +84,7 @@ const testDummy = () => {
84
84
  name = faker.random.word(),
85
85
  { message = faker.random.words(), time = 0 } = {}
86
86
  ) =>
87
- test(
87
+ vestTest(
88
88
  name,
89
89
  message,
90
90
  jest.fn(
@@ -99,7 +99,7 @@ const testDummy = () => {
99
99
  name = faker.random.word(),
100
100
  { message = faker.random.words(), time = 0 } = {}
101
101
  ) =>
102
- test(
102
+ vestTest(
103
103
  name,
104
104
  message,
105
105
  jest.fn(() => {
@@ -114,7 +114,7 @@ const testDummy = () => {
114
114
  name = faker.random.word(),
115
115
  { message = faker.random.words(), time = 0 } = {}
116
116
  ) =>
117
- test(
117
+ vestTest(
118
118
  name,
119
119
  message,
120
120
  jest.fn(
@@ -129,7 +129,7 @@ const testDummy = () => {
129
129
  name = faker.random.word(),
130
130
  { message = faker.random.words(), time = 0 } = {}
131
131
  ) =>
132
- test(
132
+ vestTest(
133
133
  name,
134
134
  message,
135
135
  jest.fn(() => {
@@ -153,3 +153,5 @@ const testDummy = () => {
153
153
  };
154
154
 
155
155
  export const dummyTest = testDummy();
156
+
157
+ export type TDummyTest = typeof dummyTest;
@@ -0,0 +1,3 @@
1
+ export function TestPromise(cb: (done: () => void) => void): Promise<void> {
2
+ return new Promise<void>(done => cb(done));
3
+ }
package/tsconfig.json CHANGED
@@ -1,8 +1,90 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
+ "rootDir": ".",
3
4
  "compilerOptions": {
4
- "declarationMap": true,
5
+ "baseUrl": ".",
5
6
  "declarationDir": "./types",
6
- "outDir": "./dist"
7
+ "declarationMap": true,
8
+ "outDir": "./dist",
9
+ "paths": {
10
+ "PersistedContext": ["src/core/context/PersistedContext.ts"],
11
+ "SuiteContext": ["src/core/context/SuiteContext.ts"],
12
+ "isIsolate": ["src/core/isolate/isIsolate.ts"],
13
+ "isolate": ["src/core/isolate/isolate.ts"],
14
+ "IsolateTest": ["src/core/isolate/IsolateTest/IsolateTest.ts"],
15
+ "IsolateTestReconciler": [
16
+ "src/core/isolate/IsolateTest/IsolateTestReconciler.ts"
17
+ ],
18
+ "IsolateTestStateMachine": [
19
+ "src/core/isolate/IsolateTest/IsolateTestStateMachine.ts"
20
+ ],
21
+ "SimpleStateMachine": [
22
+ "src/core/isolate/IsolateTest/SimpleStateMachine.ts"
23
+ ],
24
+ "TestWalker": ["src/core/isolate/IsolateTest/TestWalker.ts"],
25
+ "IsolateTypes": ["src/core/isolate/IsolateTypes.ts"],
26
+ "cancelOverriddenPendingTest": [
27
+ "src/core/isolate/reconciler/cancelOverriddenPendingTest.ts"
28
+ ],
29
+ "isSameProfileTest": ["src/core/isolate/reconciler/isSameProfileTest.ts"],
30
+ "Reconciler": ["src/core/isolate/reconciler/Reconciler/Reconciler.ts"],
31
+ "walker": ["src/core/isolate/walker.ts"],
32
+ "SuiteWalker": ["src/core/SuiteWalker/SuiteWalker.ts"],
33
+ "asVestTest": ["src/core/test/helpers/asVestTest.ts"],
34
+ "matchingFieldName": ["src/core/test/helpers/matchingFieldName.ts"],
35
+ "matchingGroupName": ["src/core/test/helpers/matchingGroupName.ts"],
36
+ "nonMatchingSeverityProfile": [
37
+ "src/core/test/helpers/nonMatchingSeverityProfile.ts"
38
+ ],
39
+ "shouldUseErrorMessage": [
40
+ "src/core/test/helpers/shouldUseErrorMessage.ts"
41
+ ],
42
+ "test.memo": ["src/core/test/test.memo.ts"],
43
+ "test": ["src/core/test/test.ts"],
44
+ "runTest": ["src/core/test/testLevelFlowControl/runTest.ts"],
45
+ "verifyTestRun": ["src/core/test/testLevelFlowControl/verifyTestRun.ts"],
46
+ "testObjectIsolate": ["src/core/test/testObjectIsolate.ts"],
47
+ "TestTypes": ["src/core/test/TestTypes.ts"],
48
+ "VestBus": ["src/core/VestBus/VestBus.ts"],
49
+ "ErrorStrings": ["src/errors/ErrorStrings.ts"],
50
+ "classnames": ["src/exports/classnames.ts"],
51
+ "enforce@compose": ["src/exports/enforce@compose.ts"],
52
+ "enforce@compounds": ["src/exports/enforce@compounds.ts"],
53
+ "enforce@schema": ["src/exports/enforce@schema.ts"],
54
+ "parser": ["src/exports/parser.ts"],
55
+ "promisify": ["src/exports/promisify.ts"],
56
+ "exclusive": ["src/hooks/exclusive.ts"],
57
+ "include": ["src/hooks/include.ts"],
58
+ "mode": ["src/hooks/mode.ts"],
59
+ "optional": ["src/hooks/optional/optional.ts"],
60
+ "OptionalTypes": ["src/hooks/optional/OptionalTypes.ts"],
61
+ "warn": ["src/hooks/warn.ts"],
62
+ "each": ["src/isolates/each.ts"],
63
+ "group": ["src/isolates/group.ts"],
64
+ "omitWhen": ["src/isolates/omitWhen.ts"],
65
+ "skipWhen": ["src/isolates/skipWhen.ts"],
66
+ "createSuite": ["src/suite/createSuite.ts"],
67
+ "runCallbacks": ["src/suite/runCallbacks.ts"],
68
+ "deferDoneCallback": ["src/suiteResult/done/deferDoneCallback.ts"],
69
+ "shouldSkipDoneRegistration": [
70
+ "src/suiteResult/done/shouldSkipDoneRegistration.ts"
71
+ ],
72
+ "collectFailures": ["src/suiteResult/selectors/collectFailures.ts"],
73
+ "hasFailuresByTestObjects": [
74
+ "src/suiteResult/selectors/hasFailuresByTestObjects.ts"
75
+ ],
76
+ "produceSuiteSummary": [
77
+ "src/suiteResult/selectors/produceSuiteSummary.ts"
78
+ ],
79
+ "shouldAddValidProperty": [
80
+ "src/suiteResult/selectors/shouldAddValidProperty.ts"
81
+ ],
82
+ "suiteSelectors": ["src/suiteResult/selectors/suiteSelectors.ts"],
83
+ "Severity": ["src/suiteResult/Severity.ts"],
84
+ "suiteResult": ["src/suiteResult/suiteResult.ts"],
85
+ "SuiteResultTypes": ["src/suiteResult/SuiteResultTypes.ts"],
86
+ "suiteRunResult": ["src/suiteResult/suiteRunResult.ts"],
87
+ "vest": ["src/vest.ts"]
88
+ }
7
89
  }
8
90
  }