@flemist/test-variants 3.0.3 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +283 -49
- package/build/browser/index.cjs +1 -0
- package/build/browser/index.d.ts +1 -0
- package/build/browser/index.mjs +4 -0
- package/build/common/-test/freezeProps.d.ts +2 -0
- package/build/common/garbage-collect/garbageCollect.d.ts +5 -0
- package/build/common/helpers/log.d.ts +5 -0
- package/build/common/index.cjs +1 -0
- package/build/common/index.d.ts +2 -0
- package/build/common/index.mjs +4 -0
- package/build/common/test-variants/-test/caches.d.ts +1 -0
- package/build/common/test-variants/-test/constants.d.ts +8 -0
- package/build/common/test-variants/-test/estimations/estimateCallCount.d.ts +4 -0
- package/build/common/test-variants/-test/estimations/estimateModeChanges.d.ts +4 -0
- package/build/common/test-variants/-test/generators/findBestError.d.ts +4 -0
- package/build/common/test-variants/-test/generators/primitives.d.ts +16 -0
- package/build/common/test-variants/-test/generators/run.d.ts +9 -0
- package/build/common/test-variants/-test/generators/template.d.ts +3 -0
- package/build/common/test-variants/-test/generators/testFunc.d.ts +3 -0
- package/build/common/test-variants/-test/helpers/CallController.d.ts +28 -0
- package/build/common/test-variants/-test/helpers/ErrorVariantController.d.ts +17 -0
- package/build/common/test-variants/-test/helpers/TestError.d.ts +2 -0
- package/build/common/test-variants/-test/helpers/deepEqualJsonLikeWithoutSeed.d.ts +1 -0
- package/build/common/test-variants/-test/helpers/deepFreezeJsonLike.d.ts +1 -0
- package/build/common/test-variants/-test/helpers/forEachVariant.d.ts +4 -0
- package/build/common/test-variants/-test/helpers/getMaxAttemptsPerVariant.d.ts +2 -0
- package/build/common/test-variants/-test/helpers/getParallelLimit.d.ts +7 -0
- package/build/common/test-variants/-test/helpers/getVariantArgs.d.ts +12 -0
- package/build/common/test-variants/-test/helpers/runWithTimeController.d.ts +7 -0
- package/build/common/test-variants/-test/invariants/CallCountInvariant.d.ts +18 -0
- package/build/common/test-variants/-test/invariants/CallOptionsInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/ErrorBehaviorInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/FindBestErrorInvariant.d.ts +37 -0
- package/build/common/test-variants/-test/invariants/IterationsInvariant.d.ts +21 -0
- package/build/common/test-variants/-test/invariants/LimitTimeInvariant.d.ts +26 -0
- package/build/common/test-variants/-test/invariants/LogInvariant.d.ts +126 -0
- package/build/common/test-variants/-test/invariants/OnErrorInvariant.d.ts +38 -0
- package/build/common/test-variants/-test/invariants/OnModeChangeInvariant.d.ts +32 -0
- package/build/common/test-variants/-test/invariants/ParallelInvariant.d.ts +25 -0
- package/build/common/test-variants/-test/log.d.ts +3 -0
- package/build/common/test-variants/-test/types.d.ts +34 -0
- package/build/common/test-variants/-test/variants.d.ts +3 -0
- package/build/common/test-variants/createTestRun.d.ts +3 -0
- package/build/common/test-variants/createTestVariants.d.ts +4 -0
- package/build/common/test-variants/iterator/createVariantsIterator.d.ts +4 -0
- package/build/common/test-variants/iterator/helpers/findValueIndex.d.ts +2 -0
- package/build/common/test-variants/iterator/helpers/mode.d.ts +3 -0
- package/build/common/test-variants/iterator/helpers/template.d.ts +7 -0
- package/build/common/test-variants/iterator/types.d.ts +102 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/caches.d.ts +1 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/check.d.ts +2 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/create.d.ts +3 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/format.d.ts +6 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/parse.d.ts +8 -0
- package/build/common/test-variants/iterator/variant-navigation/-test/helpers/variants.d.ts +12 -0
- package/build/common/test-variants/iterator/variant-navigation/variantNavigation.d.ts +28 -0
- package/build/common/test-variants/log/format.d.ts +7 -0
- package/build/common/test-variants/log/getMemoryUsage.d.ts +2 -0
- package/build/common/test-variants/log/logOptions.d.ts +8 -0
- package/build/common/test-variants/run/AbortErrorSilent.d.ts +3 -0
- package/build/common/test-variants/run/RunContext.d.ts +21 -0
- package/build/common/test-variants/run/createRunResult.d.ts +6 -0
- package/build/common/test-variants/run/createRunState.d.ts +23 -0
- package/build/common/test-variants/run/errorHandlers.d.ts +20 -0
- package/build/common/test-variants/run/gcManager.d.ts +6 -0
- package/build/common/test-variants/run/resolveRunOptions.d.ts +23 -0
- package/build/common/test-variants/run/runIterationLoop.d.ts +9 -0
- package/build/common/test-variants/run/runLogger.d.ts +9 -0
- package/build/common/test-variants/run/types.d.ts +57 -0
- package/build/common/test-variants/testVariantsRun.d.ts +6 -0
- package/build/common/test-variants/types.d.ts +183 -0
- package/build/createTestVariants-BL9wiuRD.mjs +1014 -0
- package/build/createTestVariants-CpzwjKTs.js +4 -0
- package/build/node/index.cjs +1 -0
- package/build/node/index.d.ts +8 -0
- package/build/node/index.mjs +102 -0
- package/build/node/test-variants/createSaveErrorVariantsStore.d.ts +5 -0
- package/{dist/lib → build/node}/test-variants/saveErrorVariants.d.ts +4 -3
- package/package.json +109 -68
- package/dist/bundle/browser.js +0 -669
- package/dist/lib/garbage-collect/garbageCollect.cjs +0 -30
- package/dist/lib/garbage-collect/garbageCollect.d.ts +0 -2
- package/dist/lib/garbage-collect/garbageCollect.mjs +0 -26
- package/dist/lib/index.cjs +0 -23
- package/dist/lib/index.d.ts +0 -7
- package/dist/lib/index.mjs +0 -13
- package/dist/lib/test-variants/argsToString.cjs +0 -17
- package/dist/lib/test-variants/argsToString.d.ts +0 -2
- package/dist/lib/test-variants/argsToString.mjs +0 -13
- package/dist/lib/test-variants/createTestVariants.cjs +0 -91
- package/dist/lib/test-variants/createTestVariants.d.ts +0 -8
- package/dist/lib/test-variants/createTestVariants.mjs +0 -87
- package/dist/lib/test-variants/createTestVariants.perf.cjs +0 -44
- package/dist/lib/test-variants/createTestVariants.perf.d.ts +0 -1
- package/dist/lib/test-variants/createTestVariants.perf.mjs +0 -42
- package/dist/lib/test-variants/prime.cjs +0 -65
- package/dist/lib/test-variants/prime.d.ts +0 -3
- package/dist/lib/test-variants/prime.mjs +0 -59
- package/dist/lib/test-variants/prime.perf.cjs +0 -30
- package/dist/lib/test-variants/prime.perf.d.ts +0 -1
- package/dist/lib/test-variants/prime.perf.mjs +0 -28
- package/dist/lib/test-variants/saveErrorVariants.cjs +0 -97
- package/dist/lib/test-variants/saveErrorVariants.mjs +0 -69
- package/dist/lib/test-variants/testVariantsCreateTestRun.cjs +0 -80
- package/dist/lib/test-variants/testVariantsCreateTestRun.d.ts +0 -22
- package/dist/lib/test-variants/testVariantsCreateTestRun.mjs +0 -76
- package/dist/lib/test-variants/testVariantsIterable.cjs +0 -70
- package/dist/lib/test-variants/testVariantsIterable.d.ts +0 -15
- package/dist/lib/test-variants/testVariantsIterable.mjs +0 -66
- package/dist/lib/test-variants/testVariantsIterator.cjs +0 -429
- package/dist/lib/test-variants/testVariantsIterator.d.ts +0 -67
- package/dist/lib/test-variants/testVariantsIterator.mjs +0 -425
- package/dist/lib/test-variants/testVariantsRun.cjs +0 -289
- package/dist/lib/test-variants/testVariantsRun.d.ts +0 -50
- package/dist/lib/test-variants/testVariantsRun.mjs +0 -265
- package/dist/lib/test-variants/types.cjs +0 -2
- package/dist/lib/test-variants/types.d.ts +0 -20
- package/dist/lib/test-variants/types.mjs +0 -1
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/** Find last index of value in array; uses custom equals or strict equality */
|
|
6
|
-
function findLastIndex(values, value, equals) {
|
|
7
|
-
if (equals) {
|
|
8
|
-
for (let i = values.length - 1; i >= 0; i--) {
|
|
9
|
-
if (equals(values[i], value)) {
|
|
10
|
-
return i;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return -1;
|
|
14
|
-
}
|
|
15
|
-
for (let i = values.length - 1; i >= 0; i--) {
|
|
16
|
-
if (values[i] === value) {
|
|
17
|
-
return i;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return -1;
|
|
21
|
-
}
|
|
22
|
-
/** Calculate template values for given key index */
|
|
23
|
-
function calcTemplateValues(templates, args, keyIndex) {
|
|
24
|
-
const template = templates[keyIndex];
|
|
25
|
-
if (typeof template === 'function') {
|
|
26
|
-
return template(args);
|
|
27
|
-
}
|
|
28
|
-
return template;
|
|
29
|
-
}
|
|
30
|
-
/** Reset iterator state for new cycle */
|
|
31
|
-
function resetIteratorState(state, templates, keysCount) {
|
|
32
|
-
state.index = -1;
|
|
33
|
-
state.repeatIndex = 0;
|
|
34
|
-
for (let i = 0; i < keysCount; i++) {
|
|
35
|
-
state.indexes[i] = -1;
|
|
36
|
-
state.argValues[i] = [];
|
|
37
|
-
}
|
|
38
|
-
if (keysCount > 0) {
|
|
39
|
-
state.argValues[0] = calcTemplateValues(templates, state.args, 0);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/** Get effective max index for an arg (considering argLimit) */
|
|
43
|
-
function getMaxIndex(state, keyIndex) {
|
|
44
|
-
const valuesLen = state.argValues[keyIndex].length;
|
|
45
|
-
const argLimit = state.argLimits[keyIndex];
|
|
46
|
-
if (argLimit == null) {
|
|
47
|
-
return valuesLen;
|
|
48
|
-
}
|
|
49
|
-
return argLimit < valuesLen ? argLimit : valuesLen;
|
|
50
|
-
}
|
|
51
|
-
/** Advance to next variant in cartesian product; returns true if successful */
|
|
52
|
-
function advanceVariant(state, templates, keys, keysCount) {
|
|
53
|
-
var _a;
|
|
54
|
-
for (let keyIndex = keysCount - 1; keyIndex >= 0; keyIndex--) {
|
|
55
|
-
const valueIndex = state.indexes[keyIndex] + 1;
|
|
56
|
-
const maxIndex = getMaxIndex(state, keyIndex);
|
|
57
|
-
if (valueIndex < maxIndex) {
|
|
58
|
-
const key = keys[keyIndex];
|
|
59
|
-
const value = state.argValues[keyIndex][valueIndex];
|
|
60
|
-
state.indexes[keyIndex] = valueIndex;
|
|
61
|
-
state.args[key] = value;
|
|
62
|
-
for (keyIndex++; keyIndex < keysCount; keyIndex++) {
|
|
63
|
-
const keyVariants = calcTemplateValues(templates, state.args, keyIndex);
|
|
64
|
-
const keyMaxIndex = (_a = state.argLimits[keyIndex]) !== null && _a !== void 0 ? _a : keyVariants.length;
|
|
65
|
-
if (keyVariants.length === 0 || keyMaxIndex <= 0) {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
state.indexes[keyIndex] = 0;
|
|
69
|
-
state.argValues[keyIndex] = keyVariants;
|
|
70
|
-
const key = keys[keyIndex];
|
|
71
|
-
const value = keyVariants[0];
|
|
72
|
-
state.args[key] = value;
|
|
73
|
-
}
|
|
74
|
-
if (keyIndex >= keysCount) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
/** Validate saved args keys match iterator's arg names (ignoring "seed" key) */
|
|
82
|
-
function validateArgsKeys(savedArgs, keysSet, keysCount) {
|
|
83
|
-
const savedKeys = Object.keys(savedArgs).filter(k => k !== 'seed');
|
|
84
|
-
if (savedKeys.length !== keysCount) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
for (const key of savedKeys) {
|
|
88
|
-
if (!keysSet.has(key)) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
/** For static templates, verify arg value exists in template values */
|
|
95
|
-
function validateStaticArgsValues(savedArgs, templates, keys, keysCount, equals) {
|
|
96
|
-
for (let i = 0; i < keysCount; i++) {
|
|
97
|
-
const template = templates[i];
|
|
98
|
-
if (typeof template !== 'function') {
|
|
99
|
-
const value = savedArgs[keys[i]];
|
|
100
|
-
if (findLastIndex(template, value, equals) < 0) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
/** Check if current position >= pending args position; returns false if current < pending or all args skipped */
|
|
108
|
-
function isPositionReached(state, pendingArgs, keys, keysCount, equals) {
|
|
109
|
-
let anyCompared = false;
|
|
110
|
-
for (let i = 0; i < keysCount; i++) {
|
|
111
|
-
const currentValueIndex = state.indexes[i];
|
|
112
|
-
const pendingValue = pendingArgs[keys[i]];
|
|
113
|
-
const pendingValueIndex = findLastIndex(state.argValues[i], pendingValue, equals);
|
|
114
|
-
// Dynamic template value not found - skip this arg from comparison
|
|
115
|
-
if (pendingValueIndex < 0) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
anyCompared = true;
|
|
119
|
-
if (currentValueIndex < pendingValueIndex) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
if (currentValueIndex > pendingValueIndex) {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// All compared args are equal - position reached; or all args skipped - keep pending
|
|
127
|
-
return anyCompared;
|
|
128
|
-
}
|
|
129
|
-
/** Calculate indexes for given args; returns null if any value not found */
|
|
130
|
-
function calcArgsIndexes(limitArgs, templates, keys, keysCount, equals) {
|
|
131
|
-
const indexes = [];
|
|
132
|
-
for (let i = 0; i < keysCount; i++) {
|
|
133
|
-
const key = keys[i];
|
|
134
|
-
const value = limitArgs[key];
|
|
135
|
-
// Use limitArgs for dynamic template calculation
|
|
136
|
-
const values = calcTemplateValues(templates, limitArgs, i);
|
|
137
|
-
const valueIndex = findLastIndex(values, value, equals);
|
|
138
|
-
if (valueIndex < 0) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
indexes.push(valueIndex);
|
|
142
|
-
}
|
|
143
|
-
return indexes;
|
|
144
|
-
}
|
|
145
|
-
/** Compare two index arrays lexicographically; returns -1 if a < b, 0 if equal, 1 if a > b */
|
|
146
|
-
function compareLexicographic(a, b) {
|
|
147
|
-
var _a, _b;
|
|
148
|
-
const len = Math.max(a.length, b.length);
|
|
149
|
-
for (let i = 0; i < len; i++) {
|
|
150
|
-
const ai = (_a = a[i]) !== null && _a !== void 0 ? _a : 0;
|
|
151
|
-
const bi = (_b = b[i]) !== null && _b !== void 0 ? _b : 0;
|
|
152
|
-
if (ai < bi) {
|
|
153
|
-
return -1;
|
|
154
|
-
}
|
|
155
|
-
if (ai > bi) {
|
|
156
|
-
return 1;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return 0;
|
|
160
|
-
}
|
|
161
|
-
/** Update per-arg limits from args values using lexicographic comparison; returns true if updated */
|
|
162
|
-
function updateArgLimits(state, limitArgs, oldLimitArgs, templates, keys, keysCount, equals, limitArgOnError) {
|
|
163
|
-
if (!limitArgOnError) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
// Calculate indexes for new limit args
|
|
167
|
-
const newIndexes = calcArgsIndexes(limitArgs, templates, keys, keysCount, equals);
|
|
168
|
-
if (!newIndexes) {
|
|
169
|
-
return false; // Value not found, can't apply limit
|
|
170
|
-
}
|
|
171
|
-
// If we have existing limit, compare lexicographically
|
|
172
|
-
if (oldLimitArgs) {
|
|
173
|
-
const currentIndexes = calcArgsIndexes(oldLimitArgs, templates, keys, keysCount, equals);
|
|
174
|
-
if (currentIndexes) {
|
|
175
|
-
const cmp = compareLexicographic(newIndexes, currentIndexes);
|
|
176
|
-
if (cmp >= 0) {
|
|
177
|
-
// New is larger or equal - reject entirely
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
// New is smaller (or first limit) - replace all argLimits
|
|
183
|
-
for (let i = 0; i < keysCount; i++) {
|
|
184
|
-
const valueIndex = newIndexes[i];
|
|
185
|
-
// Check callback if provided
|
|
186
|
-
if (typeof limitArgOnError === 'function') {
|
|
187
|
-
const key = keys[i];
|
|
188
|
-
const values = calcTemplateValues(templates, limitArgs, i);
|
|
189
|
-
const shouldLimit = limitArgOnError({
|
|
190
|
-
name: key,
|
|
191
|
-
valueIndex,
|
|
192
|
-
values,
|
|
193
|
-
maxValueIndex: state.argLimits[i],
|
|
194
|
-
});
|
|
195
|
-
if (!shouldLimit) {
|
|
196
|
-
state.argLimits[i] = null;
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// Set argLimit: index 0 can't be limited further, store null
|
|
201
|
-
state.argLimits[i] = valueIndex > 0 ? valueIndex : null;
|
|
202
|
-
}
|
|
203
|
-
// Filter out pending limits that are now excluded by argLimits
|
|
204
|
-
state.pendingLimits = state.pendingLimits.filter(pending => {
|
|
205
|
-
for (let i = 0; i < keysCount; i++) {
|
|
206
|
-
const value = pending.args[keys[i]];
|
|
207
|
-
const values = calcTemplateValues(templates, pending.args, i);
|
|
208
|
-
const valueIndex = findLastIndex(values, value, equals);
|
|
209
|
-
const argLimit = state.argLimits[i];
|
|
210
|
-
if (argLimit != null && valueIndex >= argLimit) {
|
|
211
|
-
return false; // Pending position is excluded by argLimits
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return true; // Keep
|
|
215
|
-
});
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
/** Process pending limits; returns true if any limit was applied */
|
|
219
|
-
function processPendingLimits(state, templates, keys, keysCount, equals, limitArgOnError) {
|
|
220
|
-
var _a, _b;
|
|
221
|
-
let applied = false;
|
|
222
|
-
for (let i = state.pendingLimits.length - 1; i >= 0; i--) {
|
|
223
|
-
const pending = state.pendingLimits[i];
|
|
224
|
-
if (isPositionReached(state, pending.args, keys, keysCount, equals)) {
|
|
225
|
-
// Current position >= pending position: apply limit
|
|
226
|
-
if (state.count == null || state.index < state.count) {
|
|
227
|
-
const oldLimitArgs = (_b = (_a = state.limit) === null || _a === void 0 ? void 0 : _a.args) !== null && _b !== void 0 ? _b : null;
|
|
228
|
-
state.count = state.index;
|
|
229
|
-
state.limit = typeof pending.error !== 'undefined'
|
|
230
|
-
? { args: pending.args, error: pending.error }
|
|
231
|
-
: { args: pending.args };
|
|
232
|
-
updateArgLimits(state, pending.args, oldLimitArgs, templates, keys, keysCount, equals, limitArgOnError);
|
|
233
|
-
applied = true;
|
|
234
|
-
}
|
|
235
|
-
// Remove from pending
|
|
236
|
-
state.pendingLimits.splice(i, 1);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
return applied;
|
|
240
|
-
}
|
|
241
|
-
/** Creates test variants iterator with limiting capabilities */
|
|
242
|
-
function testVariantsIterator(options) {
|
|
243
|
-
const { argsTemplates, getSeed, repeatsPerVariant: _repeatsPerVariant, equals, limitArgOnError } = options;
|
|
244
|
-
const repeatsPerVariant = _repeatsPerVariant !== null && _repeatsPerVariant !== void 0 ? _repeatsPerVariant : 1;
|
|
245
|
-
const keys = Object.keys(argsTemplates);
|
|
246
|
-
const templates = Object.values(argsTemplates);
|
|
247
|
-
const keysCount = keys.length;
|
|
248
|
-
const keysSet = new Set(keys);
|
|
249
|
-
// Initialize state
|
|
250
|
-
const indexes = [];
|
|
251
|
-
const argValues = [];
|
|
252
|
-
const argLimits = [];
|
|
253
|
-
for (let i = 0; i < keysCount; i++) {
|
|
254
|
-
indexes[i] = -1;
|
|
255
|
-
argValues[i] = [];
|
|
256
|
-
argLimits[i] = null;
|
|
257
|
-
}
|
|
258
|
-
const state = {
|
|
259
|
-
args: {},
|
|
260
|
-
indexes,
|
|
261
|
-
argValues,
|
|
262
|
-
argLimits,
|
|
263
|
-
index: -1,
|
|
264
|
-
cycleIndex: -1,
|
|
265
|
-
repeatIndex: 0,
|
|
266
|
-
count: null,
|
|
267
|
-
limit: null,
|
|
268
|
-
started: false,
|
|
269
|
-
currentArgs: null,
|
|
270
|
-
pendingLimits: [],
|
|
271
|
-
};
|
|
272
|
-
const iterator = {
|
|
273
|
-
get index() {
|
|
274
|
-
return state.index;
|
|
275
|
-
},
|
|
276
|
-
get cycleIndex() {
|
|
277
|
-
return state.cycleIndex;
|
|
278
|
-
},
|
|
279
|
-
get count() {
|
|
280
|
-
return state.count;
|
|
281
|
-
},
|
|
282
|
-
get limit() {
|
|
283
|
-
return state.limit;
|
|
284
|
-
},
|
|
285
|
-
addLimit(_options) {
|
|
286
|
-
var _a, _b, _c, _d, _e, _f;
|
|
287
|
-
const hasArgs = typeof (_options === null || _options === void 0 ? void 0 : _options.args) !== 'undefined' && _options.args !== null;
|
|
288
|
-
const hasIndex = (_options === null || _options === void 0 ? void 0 : _options.index) != null;
|
|
289
|
-
// addLimit() or addLimit({error}) - uses current args and index
|
|
290
|
-
if (!hasArgs && !hasIndex) {
|
|
291
|
-
if (state.index < 0) {
|
|
292
|
-
throw new Error('[testVariantsIterator] addLimit() requires at least one next() call');
|
|
293
|
-
}
|
|
294
|
-
if (state.count == null || state.index < state.count) {
|
|
295
|
-
const oldLimitArgs = (_b = (_a = state.limit) === null || _a === void 0 ? void 0 : _a.args) !== null && _b !== void 0 ? _b : null;
|
|
296
|
-
state.count = state.index;
|
|
297
|
-
state.limit = typeof (_options === null || _options === void 0 ? void 0 : _options.error) !== 'undefined'
|
|
298
|
-
? { args: state.currentArgs, error: _options.error }
|
|
299
|
-
: { args: state.currentArgs };
|
|
300
|
-
updateArgLimits(state, state.args, oldLimitArgs, templates, keys, keysCount, equals, limitArgOnError);
|
|
301
|
-
}
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
// addLimit({index}) - only index limiting, no args
|
|
305
|
-
if (hasIndex && !hasArgs) {
|
|
306
|
-
if (state.count == null || _options.index < state.count) {
|
|
307
|
-
state.count = _options.index;
|
|
308
|
-
}
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
// addLimit({args}) or addLimit({args, error}) - pending limit + immediate per-arg limits
|
|
312
|
-
if (hasArgs && !hasIndex) {
|
|
313
|
-
// Validate args keys match iterator's arg names
|
|
314
|
-
if (!validateArgsKeys(_options.args, keysSet, keysCount)) {
|
|
315
|
-
return; // Discard - unreproducible (templates changed)
|
|
316
|
-
}
|
|
317
|
-
// For static templates, verify arg value exists
|
|
318
|
-
if (!validateStaticArgsValues(_options.args, templates, keys, keysCount, equals)) {
|
|
319
|
-
return; // Discard - unreproducible (value not in template)
|
|
320
|
-
}
|
|
321
|
-
// Apply per-arg limits immediately (if limitArgOnError enabled)
|
|
322
|
-
const oldLimitArgs = (_d = (_c = state.limit) === null || _c === void 0 ? void 0 : _c.args) !== null && _d !== void 0 ? _d : null;
|
|
323
|
-
const updated = updateArgLimits(state, _options.args, oldLimitArgs, templates, keys, keysCount, equals, limitArgOnError);
|
|
324
|
-
if (updated) {
|
|
325
|
-
// argLimits updated - this is the new best, update state.limit for future comparisons
|
|
326
|
-
state.limit = typeof _options.error !== 'undefined'
|
|
327
|
-
? { args: _options.args, error: _options.error }
|
|
328
|
-
: { args: _options.args };
|
|
329
|
-
// Pending limit at this position is now filtered by argLimits, don't add
|
|
330
|
-
}
|
|
331
|
-
else if (!limitArgOnError) {
|
|
332
|
-
// No argLimits filtering - add pending limit for position-based stopping
|
|
333
|
-
const pending = typeof _options.error !== 'undefined'
|
|
334
|
-
? { args: _options.args, error: _options.error }
|
|
335
|
-
: { args: _options.args };
|
|
336
|
-
state.pendingLimits.push(pending);
|
|
337
|
-
}
|
|
338
|
-
// If limitArgOnError and not updated (lexicographically larger), discard entirely
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
// addLimit({args, index}) or addLimit({args, index, error}) - immediate index + pending args
|
|
342
|
-
if (hasArgs && hasIndex) {
|
|
343
|
-
// Check if this is earliest (before potentially updating count)
|
|
344
|
-
const isEarliest = state.count == null || _options.index < state.count;
|
|
345
|
-
// Always apply index limit
|
|
346
|
-
if (isEarliest) {
|
|
347
|
-
state.count = _options.index;
|
|
348
|
-
}
|
|
349
|
-
// Validate args for limit property update
|
|
350
|
-
if (!validateArgsKeys(_options.args, keysSet, keysCount)) {
|
|
351
|
-
return; // Skip per-arg limits and limit property update
|
|
352
|
-
}
|
|
353
|
-
if (!validateStaticArgsValues(_options.args, templates, keys, keysCount, equals)) {
|
|
354
|
-
return; // Skip per-arg limits and limit property update
|
|
355
|
-
}
|
|
356
|
-
// Update limit if this is earliest
|
|
357
|
-
if (isEarliest) {
|
|
358
|
-
const oldLimitArgs = (_f = (_e = state.limit) === null || _e === void 0 ? void 0 : _e.args) !== null && _f !== void 0 ? _f : null;
|
|
359
|
-
state.limit = typeof _options.error !== 'undefined'
|
|
360
|
-
? { args: _options.args, error: _options.error }
|
|
361
|
-
: { args: _options.args };
|
|
362
|
-
updateArgLimits(state, _options.args, oldLimitArgs, templates, keys, keysCount, equals, limitArgOnError);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
start() {
|
|
367
|
-
state.cycleIndex++;
|
|
368
|
-
resetIteratorState(state, templates, keysCount);
|
|
369
|
-
state.started = true;
|
|
370
|
-
},
|
|
371
|
-
next() {
|
|
372
|
-
if (!state.started) {
|
|
373
|
-
throw new Error('[testVariantsIterator] start() must be called before next()');
|
|
374
|
-
}
|
|
375
|
-
// Try next repeat for current variant
|
|
376
|
-
if (state.index >= 0 && state.repeatIndex + 1 < repeatsPerVariant) {
|
|
377
|
-
// Check if current variant is still within limit
|
|
378
|
-
if (state.count == null || state.index < state.count) {
|
|
379
|
-
state.repeatIndex++;
|
|
380
|
-
if (getSeed) {
|
|
381
|
-
const seed = getSeed({
|
|
382
|
-
variantIndex: state.index,
|
|
383
|
-
cycleIndex: state.cycleIndex,
|
|
384
|
-
repeatIndex: state.repeatIndex,
|
|
385
|
-
});
|
|
386
|
-
state.currentArgs = Object.assign(Object.assign({}, state.args), { seed });
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
state.currentArgs = Object.assign({}, state.args);
|
|
390
|
-
}
|
|
391
|
-
return state.currentArgs;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
// Move to next variant
|
|
395
|
-
state.repeatIndex = 0;
|
|
396
|
-
if (!advanceVariant(state, templates, keys, keysCount)) {
|
|
397
|
-
// First complete cycle sets count to total variant count
|
|
398
|
-
if (state.count == null) {
|
|
399
|
-
state.count = state.index + 1;
|
|
400
|
-
}
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
state.index++;
|
|
404
|
-
// Process pending limits at new position
|
|
405
|
-
if (state.pendingLimits.length > 0) {
|
|
406
|
-
processPendingLimits(state, templates, keys, keysCount, equals, limitArgOnError);
|
|
407
|
-
}
|
|
408
|
-
// Check count limit (may have been updated by pending limit)
|
|
409
|
-
if (state.count != null && state.index >= state.count) {
|
|
410
|
-
return null;
|
|
411
|
-
}
|
|
412
|
-
if (getSeed) {
|
|
413
|
-
const seed = getSeed({
|
|
414
|
-
variantIndex: state.index,
|
|
415
|
-
cycleIndex: state.cycleIndex,
|
|
416
|
-
repeatIndex: state.repeatIndex,
|
|
417
|
-
});
|
|
418
|
-
state.currentArgs = Object.assign(Object.assign({}, state.args), { seed });
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
state.currentArgs = Object.assign({}, state.args);
|
|
422
|
-
}
|
|
423
|
-
return state.currentArgs;
|
|
424
|
-
},
|
|
425
|
-
};
|
|
426
|
-
return iterator;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
exports.testVariantsIterator = testVariantsIterator;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { Obj } from "./types";
|
|
2
|
-
import type { TestVariantsTemplate, TestVariantsTemplates } from "./testVariantsIterable";
|
|
3
|
-
/** Parameters passed to getSeed function for generating test seeds */
|
|
4
|
-
export declare type GetSeedParams = {
|
|
5
|
-
/** Index of current variant/parameter-combination being tested */
|
|
6
|
-
variantIndex: number;
|
|
7
|
-
/** Index of current cycle - full pass through all variants (0..cycles-1) */
|
|
8
|
-
cycleIndex: number;
|
|
9
|
-
/** Index of repeat for current variant within this cycle (0..repeatsPerVariant-1) */
|
|
10
|
-
repeatIndex: number;
|
|
11
|
-
};
|
|
12
|
-
/** Options for limiting per-arg indexes on error */
|
|
13
|
-
export declare type LimitArgOnErrorOptions = {
|
|
14
|
-
/** Arg name */
|
|
15
|
-
name: string;
|
|
16
|
-
/** Arg value's index in template values array */
|
|
17
|
-
valueIndex: number;
|
|
18
|
-
/** Current template values array for this arg */
|
|
19
|
-
values: any[];
|
|
20
|
-
/** Current max value index limit for this arg; null if no limit */
|
|
21
|
-
maxValueIndex: number | null;
|
|
22
|
-
};
|
|
23
|
-
/** Callback to decide whether to apply limit for specific arg */
|
|
24
|
-
export declare type LimitArgOnError = (options: LimitArgOnErrorOptions) => boolean;
|
|
25
|
-
/** Options for creating test variants iterator */
|
|
26
|
-
export declare type TestVariantsIteratorOptions<Args extends Obj> = {
|
|
27
|
-
argsTemplates: TestVariantsTemplates<Args>;
|
|
28
|
-
/** Custom equality for comparing arg values */
|
|
29
|
-
equals?: null | ((a: any, b: any) => boolean);
|
|
30
|
-
/** Limit per-arg indexes on error; boolean enables/disables, function for custom per-arg logic */
|
|
31
|
-
limitArgOnError?: null | boolean | LimitArgOnError;
|
|
32
|
-
/** Generates seed for reproducible randomized testing; seed is added to args */
|
|
33
|
-
getSeed?: null | ((params: GetSeedParams) => any);
|
|
34
|
-
/** Number of repeat tests per variant within each cycle */
|
|
35
|
-
repeatsPerVariant?: null | number;
|
|
36
|
-
};
|
|
37
|
-
/** Limit information with args and optional error */
|
|
38
|
-
export declare type TestVariantsIteratorLimit<Args> = {
|
|
39
|
-
args: Args;
|
|
40
|
-
error?: unknown;
|
|
41
|
-
};
|
|
42
|
-
/** Options for addLimit method */
|
|
43
|
-
export declare type AddLimitOptions<Args> = {
|
|
44
|
-
args?: null | Args;
|
|
45
|
-
index?: null | number;
|
|
46
|
-
error?: unknown;
|
|
47
|
-
};
|
|
48
|
-
/** Test variants iterator with limiting capabilities */
|
|
49
|
-
export declare type TestVariantsIterator<Args extends Obj> = {
|
|
50
|
-
/** Current variant index; -1 before first next() */
|
|
51
|
-
readonly index: number;
|
|
52
|
-
/** Current cycle index; starts at 0 after first start() */
|
|
53
|
-
readonly cycleIndex: number;
|
|
54
|
-
/** Maximum variant count; variants with index >= count are not yielded */
|
|
55
|
-
readonly count: number | null;
|
|
56
|
-
/** Last applied limit's args and error; null if no args-based limit applied */
|
|
57
|
-
readonly limit: TestVariantsIteratorLimit<Args> | null;
|
|
58
|
-
/** Add or tighten limit */
|
|
59
|
-
addLimit(options?: null | AddLimitOptions<Args>): void;
|
|
60
|
-
/** Reset to beginning of iteration for next cycle */
|
|
61
|
-
start(): void;
|
|
62
|
-
/** Get next variant or null when done */
|
|
63
|
-
next(): Args | null;
|
|
64
|
-
};
|
|
65
|
-
export { type TestVariantsTemplate, type TestVariantsTemplates, };
|
|
66
|
-
/** Creates test variants iterator with limiting capabilities */
|
|
67
|
-
export declare function testVariantsIterator<Args extends Obj>(options: TestVariantsIteratorOptions<Args>): TestVariantsIterator<Args>;
|