@flemist/test-variants 5.0.12 → 5.0.14

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.
@@ -1,1042 +0,0 @@
1
- import { timeControllerDefault as K } from "@flemist/time-controller";
2
- import { formatAny as de, deepCloneJsonLike as Je } from "@flemist/simple-utils";
3
- import { isPromiseLike as T, waitMicrotasks as Xe, combineAbortSignals as oe } from "@flemist/async-utils";
4
- import { AbortError as Ze, AbortControllerFast as ie } from "@flemist/abort-controller-fast";
5
- import { poolWait as se, Pool as Ke } from "@flemist/time-limits";
6
- function Q() {
7
- if (typeof process < "u" && process.memoryUsage)
8
- try {
9
- return process.memoryUsage.rss();
10
- } catch {
11
- }
12
- if (typeof performance < "u") {
13
- const e = performance.memory;
14
- if (e)
15
- try {
16
- return e.usedJSHeapSize;
17
- } catch {
18
- }
19
- }
20
- return null;
21
- }
22
- const Qe = 1e3, q = [];
23
- function Ye(e) {
24
- return de(e, { pretty: !0, maxDepth: 5, maxItems: 50 });
25
- }
26
- function et(...e) {
27
- const n = e.map((t) => typeof t == "string" ? t : Ye(t)).join(" ");
28
- q.push(n), q.length > Qe && q.shift(), console.log(n);
29
- }
30
- function tt() {
31
- return q.join(`
32
- `);
33
- }
34
- globalThis.__getStressTestLogLast = tt;
35
- const me = (e, n) => {
36
- et(n);
37
- }, ge = (e) => de(e, {
38
- pretty: !0,
39
- maxDepth: 20,
40
- maxItems: 100,
41
- maxStringLength: 5e3,
42
- dontExpandClassInstances: !0,
43
- dontExpandFunctions: !0
44
- }), S = {
45
- start: !0,
46
- progress: 5e3,
47
- completed: !0,
48
- error: !0,
49
- modeChange: !0,
50
- debug: !1,
51
- func: me,
52
- format: ge
53
- }, rt = {
54
- start: !1,
55
- progress: !1,
56
- completed: !1,
57
- error: !1,
58
- modeChange: !1,
59
- debug: !1,
60
- func: me,
61
- format: ge
62
- };
63
- function pe(e) {
64
- return e === !1 ? rt : e === !0 || !e ? S : {
65
- start: e.start ?? S.start,
66
- progress: e.progress ?? S.progress,
67
- completed: e.completed ?? S.completed,
68
- error: e.error ?? S.error,
69
- modeChange: e.modeChange ?? S.modeChange,
70
- debug: e.debug ?? S.debug,
71
- func: e.func ?? S.func,
72
- format: e.format ?? S.format
73
- };
74
- }
75
- function nt(e, n) {
76
- const t = e.now();
77
- return {
78
- startTime: t,
79
- startMemory: n,
80
- debugMode: !1,
81
- tests: 0,
82
- iterations: 0,
83
- iterationsAsync: 0,
84
- prevLogTime: t,
85
- prevLogMemory: n,
86
- pendingModeChange: null,
87
- prevGcTime: t,
88
- prevGcIterations: 0,
89
- prevGcIterationsAsync: 0
90
- };
91
- }
92
- class I extends Ze {
93
- }
94
- const ot = 50, it = 5;
95
- function ae(e, n) {
96
- return typeof e == "number" ? { iterationsAsync: 0, iterationsSync: e } : e != null && typeof e == "object" ? e : n ? { iterationsAsync: 1, iterationsSync: 0 } : { iterationsAsync: 0, iterationsSync: 1 };
97
- }
98
- function st(e, n) {
99
- const t = n.log, i = n.pauseDebuggerOnError ?? !0, o = n.onStart, s = n.onEnd;
100
- let r = null, l = 0;
101
- function f(m, c, b) {
102
- r == null && (r = { error: m, args: c, tests: b }, t.error && t.func(
103
- "error",
104
- `[test-variants] error variant: ${t.format(c)}
105
- tests: ${b}
106
- ${t.format(m)}`
107
- ));
108
- const y = Date.now();
109
- if (i)
110
- debugger;
111
- if (Date.now() - y > ot && l < it) {
112
- t.func(
113
- "debug",
114
- `[test-variants] debug iteration: ${l}`
115
- ), l++;
116
- return;
117
- }
118
- const h = r;
119
- throw r = null, n.onError && n.onError(h), h.error;
120
- }
121
- return function(c, b, y) {
122
- o && o({ args: c, tests: b });
123
- try {
124
- const d = e(c, y);
125
- if (T(d))
126
- return d.then(
127
- (v) => {
128
- const x = ae(v, !0);
129
- return s && s({ args: c, tests: b, result: x }), x;
130
- },
131
- (v) => (s && !(v instanceof I) && s({ args: c, tests: b, error: v }), f(v, c, b))
132
- );
133
- const h = ae(d, !1);
134
- return s && s({ args: c, tests: b, result: h }), h;
135
- } catch (d) {
136
- return d instanceof I ? void 0 : (s && s({ args: c, tests: b, error: d }), f(d, c, b));
137
- }
138
- };
139
- }
140
- function U(e, n, t) {
141
- for (let i = 0, o = e.length; i < o; i++)
142
- if (t ? t(e[i], n) : e[i] === n)
143
- return i;
144
- return -1;
145
- }
146
- function le(e, n, t, i) {
147
- const o = Object.keys(e.templates), s = {}, r = [], l = [], f = [], m = o.length;
148
- for (let c = 0; c < m; c++) {
149
- const b = o[c];
150
- s[b] = void 0, r.push(-1), l.push(void 0), f.push(null);
151
- }
152
- return {
153
- args: s,
154
- argsNames: o,
155
- indexes: r,
156
- argValues: l,
157
- argLimits: f,
158
- attempts: 0,
159
- templates: e,
160
- limitArgOnError: t,
161
- equals: n,
162
- includeErrorVariant: i ?? !1
163
- };
164
- }
165
- function L(e, n) {
166
- const t = e.templates.templates[n], i = e.templates.extra[n];
167
- let o;
168
- if (typeof t == "function" ? o = t(e.args) : o = t, i == null)
169
- return o;
170
- let s = null;
171
- const r = i.length;
172
- for (let l = 0; l < r; l++) {
173
- const f = i[l];
174
- U(o, f, e.equals) < 0 && (s == null ? s = [...o, f] : s.push(f));
175
- }
176
- return s ?? o;
177
- }
178
- function M(e, n, t) {
179
- const i = e.argValues[n].length;
180
- if (i === 0)
181
- return -1;
182
- const o = e.argLimits[n];
183
- if (o == null)
184
- return i - 1;
185
- let s = e.limitArgOnError;
186
- if (typeof s == "function") {
187
- const r = e.argsNames[n];
188
- s = s({
189
- name: r,
190
- values: e.argValues[n],
191
- maxValueIndex: o
192
- });
193
- }
194
- return !t || s ? Math.min(o, i - 1) : i - 1;
195
- }
196
- function V(e) {
197
- const n = e.indexes.length;
198
- for (let t = 0; t < n; t++) {
199
- const i = e.argLimits[t];
200
- if (i == null)
201
- return !1;
202
- const o = e.indexes[t];
203
- if (o > i)
204
- return !0;
205
- if (o < i)
206
- return !1;
207
- }
208
- return !e.includeErrorVariant;
209
- }
210
- function O(e) {
211
- const n = e.indexes.length;
212
- for (let t = 0; t < n; t++)
213
- e.indexes[t] = -1, e.argValues[t] = void 0, e.args[e.argsNames[t]] = void 0;
214
- }
215
- function he(e) {
216
- let n = !1, t = !0;
217
- const i = e.indexes.length;
218
- let o = i, s = !1, r = 0;
219
- for (; r < i; r++) {
220
- const l = e.argValues[r] == null;
221
- (l || s) && (l && (n = !0), e.argValues[r] = L(
222
- e,
223
- e.argsNames[r]
224
- ));
225
- const f = M(
226
- e,
227
- r,
228
- r > o
229
- );
230
- if (f < 0) {
231
- t = !1, e.indexes[r] = -1;
232
- break;
233
- }
234
- l && (e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0]), (s || e.indexes[r] > f) && (e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f], s = !0), o === i && e.indexes[r] < f && (o = r);
235
- }
236
- if (V(e))
237
- return O(e), !1;
238
- if (n && t)
239
- return !0;
240
- for (r--; r >= 0; r--) {
241
- if (e.argValues[r] == null)
242
- continue;
243
- let l = r > o;
244
- const f = M(e, r, l), m = e.indexes[r] + 1;
245
- if (m <= f) {
246
- e.indexes[r] = m, e.args[e.argsNames[r]] = e.argValues[r][m], m < f && (l = !0);
247
- for (let c = r + 1; c < i; c++)
248
- e.args[e.argsNames[c]] = void 0;
249
- for (r++; r < i; r++) {
250
- e.argValues[r] = L(
251
- e,
252
- e.argsNames[r]
253
- );
254
- const c = M(e, r, l);
255
- if (c < 0)
256
- break;
257
- e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0], c > 0 && (l = !0);
258
- }
259
- if (r >= i)
260
- return V(e) ? (O(e), !1) : !0;
261
- }
262
- }
263
- return O(e), !1;
264
- }
265
- function z(e) {
266
- V(e) && O(e);
267
- let n = !1, t = !0;
268
- const i = e.indexes.length;
269
- let o = i, s = !1, r = 0;
270
- for (; r < i; r++) {
271
- const l = e.argValues[r] == null;
272
- (l || s) && (l && (n = !0), e.argValues[r] = L(
273
- e,
274
- e.argsNames[r]
275
- ));
276
- const f = M(
277
- e,
278
- r,
279
- r > o
280
- );
281
- if (f < 0) {
282
- t = !1, e.indexes[r] = -1;
283
- break;
284
- }
285
- l && (e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f]), (s || e.indexes[r] > f) && (e.indexes[r] = f, e.args[e.argsNames[r]] = e.argValues[r][f], s = !0), o === i && e.indexes[r] < f && (o = r);
286
- }
287
- if ((n || s) && t && !V(e))
288
- return !0;
289
- for (r--; r >= 0; r--) {
290
- if (e.argValues[r] == null)
291
- continue;
292
- let l = r > o;
293
- const f = M(e, r, l);
294
- let m = e.indexes[r] - 1;
295
- if (m > f && (m = f), m >= 0) {
296
- e.indexes[r] = m, e.args[e.argsNames[r]] = e.argValues[r][m], m < f && (l = !0);
297
- for (let c = r + 1; c < i; c++)
298
- e.args[e.argsNames[c]] = void 0;
299
- for (r++; r < i; r++) {
300
- e.argValues[r] = L(
301
- e,
302
- e.argsNames[r]
303
- );
304
- const c = M(e, r, l);
305
- if (c < 0)
306
- break;
307
- e.indexes[r] = c, e.args[e.argsNames[r]] = e.argValues[r][c], c > 0 && (l = !0);
308
- }
309
- if (r >= i)
310
- return !0;
311
- }
312
- }
313
- return O(e), !1;
314
- }
315
- function at(e, n) {
316
- O(e);
317
- const t = e.argsNames, i = t.length;
318
- let o = !1;
319
- for (let s = 0; s < i; s++) {
320
- const r = t[s], l = n[r];
321
- if (l === void 0)
322
- return null;
323
- e.argValues[s] = L(e, r);
324
- const f = M(e, s, o);
325
- if (f < 0)
326
- return null;
327
- const m = U(
328
- e.argValues[s],
329
- l,
330
- e.equals
331
- );
332
- if (m < 0 || m > f)
333
- return null;
334
- e.indexes[s] = m, e.args[e.argsNames[s]] = e.argValues[s][m], e.indexes[s] < f && (o = !0);
335
- }
336
- return V(e) ? null : e.indexes.slice();
337
- }
338
- function lt(e) {
339
- const n = e.indexes.length;
340
- if (n === 0)
341
- return !1;
342
- let t = !1;
343
- for (let i = 0; i < n; i++) {
344
- e.argValues[i] = L(e, e.argsNames[i]);
345
- const o = M(e, i, t);
346
- if (o < 0)
347
- return Math.random() < 0.5 ? he(e) : z(e);
348
- e.indexes[i] = Math.floor(Math.random() * (o + 1)), e.args[e.argsNames[i]] = e.argValues[i][e.indexes[i]], e.indexes[i] < o && (t = !0);
349
- }
350
- return V(e) ? z(e) : !0;
351
- }
352
- function _(e) {
353
- return e.mode === "forward" || e.mode === "backward";
354
- }
355
- function ut(e, n, t, i) {
356
- const o = n[t], s = e.templates[t];
357
- if (typeof s != "function") {
358
- if (U(s, o, i) >= 0)
359
- return;
360
- s.push(o);
361
- return;
362
- }
363
- const r = e.extra[t];
364
- if (r == null) {
365
- e.extra[t] = [o];
366
- return;
367
- }
368
- U(r, o, i) >= 0 || r.push(o);
369
- }
370
- function ft(e, n, t) {
371
- for (const i in n)
372
- if (Object.prototype.hasOwnProperty.call(n, i)) {
373
- if (i === "seed")
374
- continue;
375
- ut(e, n, i, t);
376
- }
377
- }
378
- function ue(e, n) {
379
- for (const t in n)
380
- if (Object.prototype.hasOwnProperty.call(n, t)) {
381
- if (t === "seed")
382
- continue;
383
- if (!e[t])
384
- return !1;
385
- }
386
- return !0;
387
- }
388
- const ct = [{ mode: "forward" }];
389
- function dt(e) {
390
- const {
391
- argsTemplates: n,
392
- equals: t,
393
- limitArgOnError: i,
394
- includeErrorVariant: o,
395
- getSeed: s,
396
- iterationModes: r,
397
- onModeChange: l,
398
- limitCompletionCount: f,
399
- limitTests: m,
400
- limitTime: c
401
- } = e, b = e.timeController ?? K, y = {
402
- templates: Je(n),
403
- extra: {}
404
- }, d = r == null || r.length === 0 ? ct : r, h = [];
405
- let v = null, x = null, p = 0, w = 0, A = !1, P = 0;
406
- function $() {
407
- A || (A = !0, P = b.now(), Se(), p = 0, te(), we());
408
- }
409
- function Se() {
410
- for (let a = 0, u = d.length; a < u; a++)
411
- h.push(xe());
412
- }
413
- function xe() {
414
- return {
415
- navigationState: le(
416
- y,
417
- t ?? null,
418
- i ?? null,
419
- o ?? null
420
- ),
421
- cycleCount: 0,
422
- completedCount: 0,
423
- testsInLastTurn: 0,
424
- tryNextVariantAttempts: 0,
425
- startTime: null
426
- };
427
- }
428
- function we() {
429
- v = le(
430
- y,
431
- t ?? null,
432
- // Initial values; overwritten in calcIndexes before each use
433
- !1,
434
- !1
435
- );
436
- }
437
- function te() {
438
- l?.({
439
- mode: d[p],
440
- modeIndex: p,
441
- tests: w
442
- });
443
- }
444
- function Me(a) {
445
- $(), ue(y.templates, a) && ft(y, a, t);
446
- }
447
- function re(a, u) {
448
- return $(), ue(y.templates, a) ? (v.limitArgOnError = u?.limitArg ?? i ?? null, v.includeErrorVariant = u?.includeLimit ?? o ?? !1, at(v, a)) : null;
449
- }
450
- function Ie(a) {
451
- const u = a?.args;
452
- if (u == null)
453
- return;
454
- $();
455
- const g = re(u);
456
- if (g != null) {
457
- x = {
458
- args: u,
459
- error: a?.error,
460
- tests: a?.tests ?? w
461
- }, v.argLimits = g;
462
- for (let E = 0, D = h.length; E < D; E++) {
463
- const j = h[E].navigationState;
464
- j.argLimits = g;
465
- }
466
- }
467
- }
468
- function Te() {
469
- return $(), Ve();
470
- }
471
- function Ve() {
472
- for (; ; ) {
473
- if (!Ae())
474
- return null;
475
- for (; ; ) {
476
- const a = qe();
477
- if (a != null)
478
- return h[p].testsInLastTurn++, w++, a;
479
- if ($e()) {
480
- if (!Ge())
481
- return null;
482
- _e();
483
- break;
484
- }
485
- }
486
- }
487
- }
488
- function Ae() {
489
- return !(Ce() || Oe() || G() && (Le() || !Ne()) || !Pe());
490
- }
491
- function Ce() {
492
- return m != null && w >= m;
493
- }
494
- function Oe() {
495
- return c != null && b.now() - P >= c;
496
- }
497
- function Le() {
498
- if (!G())
499
- throw new Error("Unexpected behavior");
500
- return f != null && f <= 0;
501
- }
502
- function Ne() {
503
- if (!G())
504
- throw new Error("Unexpected behavior");
505
- for (let a = 0, u = d.length; a < u; a++)
506
- if (C(d[a]) && R(a))
507
- return !0;
508
- return !1;
509
- }
510
- function Pe() {
511
- for (let a = 0, u = d.length; a < u; a++)
512
- if (R(a))
513
- return !0;
514
- return !1;
515
- }
516
- function $e() {
517
- p++;
518
- const a = p >= d.length;
519
- return a && (p = 0), te(), a;
520
- }
521
- function Ge() {
522
- if (G()) {
523
- const a = De();
524
- if (f != null && a >= f)
525
- return !1;
526
- }
527
- return !0;
528
- }
529
- function G() {
530
- for (let a = 0, u = d.length; a < u; a++)
531
- if (_(d[a]))
532
- return !0;
533
- return !1;
534
- }
535
- function De() {
536
- let a = !1, u = 1 / 0;
537
- for (let g = 0, E = h.length; g < E; g++) {
538
- const D = h[g], j = d[g];
539
- _(j) && (a = !0, R(g) && D.completedCount < u && (u = D.completedCount));
540
- }
541
- if (!a)
542
- throw new Error("Unexpected behavior");
543
- return u;
544
- }
545
- function R(a) {
546
- const u = d[a], g = h[a];
547
- return u.limitTests != null && u.limitTests <= 0 || C(u) && (u.cycles != null && u.cycles <= 0 || u.attemptsPerVariant != null && u.attemptsPerVariant <= 0) ? !1 : g.tryNextVariantAttempts < 2;
548
- }
549
- function _e() {
550
- p = 0;
551
- for (let a = 0, u = h.length; a < u; a++) {
552
- const g = h[a];
553
- g.testsInLastTurn = 0, g.startTime = null;
554
- }
555
- }
556
- function qe() {
557
- let a = 0;
558
- for (; a < 2; ) {
559
- if (!Ue())
560
- return null;
561
- const u = je();
562
- if (u != null)
563
- return u;
564
- if (C(d[p]) && Fe())
565
- return null;
566
- a++;
567
- }
568
- return null;
569
- }
570
- function Ue() {
571
- const a = d[p];
572
- return !(Be() || ke() || C(a) && !Re(p));
573
- }
574
- function Be() {
575
- const a = d[p], u = h[p];
576
- return a.limitTests != null && u.testsInLastTurn >= a.limitTests;
577
- }
578
- function ke() {
579
- const a = d[p], u = h[p];
580
- return a.limitTime != null && u.startTime != null && b.now() - u.startTime >= a.limitTime;
581
- }
582
- function C(a) {
583
- return _(a);
584
- }
585
- function Re(a) {
586
- const u = d[a], g = h[a];
587
- if (!C(u))
588
- throw new Error("Unexpected behavior");
589
- return g.cycleCount < (u.cycles ?? 1);
590
- }
591
- function Fe() {
592
- const a = d[p], u = h[p];
593
- if (!C(a))
594
- throw new Error("Unexpected behavior");
595
- return u.cycleCount++, u.cycleCount >= (a.cycles ?? 1) ? (u.cycleCount = 0, u.completedCount++, !0) : !1;
596
- }
597
- function je() {
598
- const a = d[p], u = h[p], g = u.navigationState;
599
- if (N(a)) {
600
- if (F())
601
- return null;
602
- const E = We();
603
- if (E != null)
604
- return u.startTime == null && (u.startTime = b.now()), E;
605
- }
606
- return He() ? (u.tryNextVariantAttempts = 0, N(a) && ze(), u.startTime == null && (u.startTime = b.now()), ne(g.args)) : (u.tryNextVariantAttempts++, null);
607
- }
608
- function We() {
609
- const a = d[p], g = h[p].navigationState;
610
- if (!N(a))
611
- throw new Error("Unexpected behavior");
612
- if (F())
613
- throw new Error("Unexpected behavior");
614
- const E = a.attemptsPerVariant ?? 1;
615
- return g.attempts > 0 && g.attempts < E ? V(g) ? null : (g.attempts++, ne(g.args)) : null;
616
- }
617
- function ze() {
618
- const a = d[p], g = h[p].navigationState;
619
- if (!N(a))
620
- throw new Error("Unexpected behavior");
621
- if (F())
622
- throw new Error("Unexpected behavior");
623
- g.attempts = 1;
624
- }
625
- function N(a) {
626
- return _(a);
627
- }
628
- function F() {
629
- const a = d[p];
630
- if (!N(a))
631
- throw new Error("Unexpected behavior");
632
- return (a.attemptsPerVariant ?? 1) <= 0;
633
- }
634
- function He() {
635
- const a = d[p], g = h[p].navigationState;
636
- switch (a.mode) {
637
- case "forward":
638
- return he(g);
639
- case "backward":
640
- return z(g);
641
- case "random":
642
- return lt(g);
643
- default:
644
- throw new Error(`Unknown mode: ${a.mode}`);
645
- }
646
- }
647
- function ne(a) {
648
- const u = { ...a };
649
- return s != null && (u.seed = s({ tests: w })), u;
650
- }
651
- return {
652
- get limit() {
653
- return x;
654
- },
655
- get modeIndex() {
656
- return p;
657
- },
658
- get modeConfigs() {
659
- return d;
660
- },
661
- get modeStates() {
662
- return h;
663
- },
664
- get tests() {
665
- return w;
666
- },
667
- calcIndexes: re,
668
- extendTemplates: Me,
669
- addLimit: Ie,
670
- next: Te
671
- };
672
- }
673
- function Y(e) {
674
- if (e == null || e <= 0)
675
- throw new Error(`Iterations = ${e}`);
676
- e--;
677
- const n = Xe().then(() => e);
678
- return e <= 0 ? n : n.then(Y);
679
- }
680
- function mt(e, n, t) {
681
- const i = n.limit ? {
682
- error: n.limit.error,
683
- args: n.limit.args,
684
- tests: n.limit.tests
685
- } : null;
686
- if (i && !t)
687
- throw i.error;
688
- return {
689
- iterations: e.iterations,
690
- bestError: i
691
- };
692
- }
693
- const fe = 2 ** 31;
694
- function gt(e) {
695
- if (e == null)
696
- return { parallel: 1, sequentialOnError: !1 };
697
- if (typeof e == "boolean")
698
- return {
699
- parallel: e ? fe : 1,
700
- sequentialOnError: !1
701
- };
702
- if (typeof e == "number")
703
- return { parallel: e > 0 ? e : 1, sequentialOnError: !1 };
704
- const n = e.count;
705
- let t = 1;
706
- return n === !0 ? t = fe : typeof n == "number" && n > 0 && (t = n), {
707
- parallel: t,
708
- sequentialOnError: e.sequentialOnError ?? !1
709
- };
710
- }
711
- function pt(e) {
712
- const n = e?.saveErrorVariants, t = n && e.createSaveErrorVariantsStore ? e.createSaveErrorVariantsStore(n) : null, i = e?.findBestError, { parallel: o, sequentialOnError: s } = gt(
713
- e?.parallel
714
- );
715
- return {
716
- store: t,
717
- GC_Iterations: e?.GC_Iterations ?? 1e6,
718
- GC_IterationsAsync: e?.GC_IterationsAsync ?? 1e4,
719
- GC_Interval: e?.GC_Interval ?? 1e3,
720
- logOptions: pe(e?.log),
721
- abortSignalExternal: e?.abortSignal,
722
- findBestError: i,
723
- dontThrowIfError: i?.dontThrowIfError,
724
- timeController: e?.timeController ?? K,
725
- parallel: o,
726
- sequentialOnError: s
727
- };
728
- }
729
- function B(e, n, t) {
730
- const { options: i, variantsIterator: o } = e, s = o.limit?.args ?? n;
731
- if (!i.store)
732
- return;
733
- const r = i.store.save(s);
734
- if (t)
735
- return r;
736
- }
737
- function ht(e, n, t, i) {
738
- const { abortControllerParallel: o, state: s, options: r } = e, { logOptions: l } = r;
739
- if (e.options.findBestError)
740
- e.variantsIterator.addLimit({ args: n, error: t, tests: i }), s.debugMode = !1, B(e, n, !1), r.sequentialOnError && !o.signal.aborted ? (l.debug && l.func(
741
- "debug",
742
- "[test-variants] sequentialOnError: aborting parallel, switching to sequential"
743
- ), o.abort(new I())) : l.debug && l.func(
744
- "debug",
745
- "[test-variants] parallel error in findBestError mode, continuing with new limits"
746
- );
747
- else {
748
- if (o.signal.aborted)
749
- return;
750
- B(e, n, !1), o.abort(t);
751
- }
752
- }
753
- function ce(e, n, t, i) {
754
- const { state: o } = e;
755
- if (e.options.findBestError) {
756
- e.variantsIterator.addLimit({ args: n, error: t, tests: i });
757
- const r = B(e, n, !0);
758
- if (r)
759
- return r.then(() => {
760
- o.debugMode = !1;
761
- });
762
- o.debugMode = !1;
763
- return;
764
- }
765
- const s = B(e, n, !0);
766
- if (s)
767
- return s.then(() => {
768
- throw t;
769
- });
770
- throw t;
771
- }
772
- function bt(e, n) {
773
- const { GC_Iterations: t, GC_IterationsAsync: i, GC_Interval: o } = e.options;
774
- return t > 0 && e.state.iterations - e.state.prevGcIterations >= t || i > 0 && e.state.iterationsAsync - e.state.prevGcIterationsAsync >= i || o > 0 && n - e.state.prevGcTime >= o;
775
- }
776
- async function yt(e, n) {
777
- e.prevGcIterations = e.iterations, e.prevGcIterationsAsync = e.iterationsAsync, e.prevGcTime = n, await Y(1);
778
- }
779
- function ee(e) {
780
- const n = e / 1e3;
781
- if (n < 60)
782
- return `${n.toFixed(1)}s`;
783
- const t = n / 60;
784
- return t < 60 ? `${t.toFixed(1)}m` : `${(t / 60).toFixed(1)}h`;
785
- }
786
- function H(e) {
787
- const n = e / 1073741824;
788
- if (n >= 1)
789
- return n >= 10 ? `${Math.round(n)}GB` : `${n.toFixed(1)}GB`;
790
- const t = e / (1024 * 1024);
791
- return t >= 10 ? `${Math.round(t)}MB` : `${t.toFixed(1)}MB`;
792
- }
793
- function vt(e, n) {
794
- if (!e)
795
- return `mode[${n}]: null`;
796
- let t = `mode[${n}]: ${e.mode}`;
797
- return (e.mode === "forward" || e.mode === "backward") && (e.cycles != null && (t += `, cycles=${e.cycles}`), e.attemptsPerVariant != null && (t += `, attempts=${e.attemptsPerVariant}`)), e.limitTime != null && (t += `, limitTime=${ee(e.limitTime)}`), e.limitTests != null && (t += `, limitTests=${e.limitTests}`), t;
798
- }
799
- function be(e, n) {
800
- const t = e - n, i = t >= 0 ? "+" : "";
801
- return `${H(e)} (${i}${H(t)})`;
802
- }
803
- function Et(e, n) {
804
- if (!e.start)
805
- return;
806
- let t = "[test-variants] start";
807
- n != null && (t += `, memory: ${H(n)}`), e.func("start", t);
808
- }
809
- function St(e) {
810
- const { options: n, state: t } = e, { logOptions: i, timeController: o } = n;
811
- if (!i.completed)
812
- return;
813
- const s = o.now() - t.startTime;
814
- let r = `[test-variants] end, tests: ${t.tests} (${ee(s)}), async: ${t.iterationsAsync}`;
815
- if (t.startMemory != null) {
816
- const l = Q();
817
- l != null && (r += `, memory: ${be(l, t.startMemory)}`);
818
- }
819
- i.func("completed", r);
820
- }
821
- function ye(e) {
822
- const { options: n, state: t } = e, { logOptions: i } = n, o = t.pendingModeChange;
823
- !i.modeChange || o == null || (i.func(
824
- "modeChange",
825
- `[test-variants] ${vt(o.mode, o.modeIndex)}`
826
- ), t.pendingModeChange = null);
827
- }
828
- function xt(e) {
829
- const { options: n, state: t } = e, { logOptions: i, timeController: o } = n, s = o.now();
830
- if (!i.progress || s - t.prevLogTime < i.progress)
831
- return !1;
832
- ye(e);
833
- const r = s - t.startTime;
834
- let l = `[test-variants] tests: ${t.tests} (${ee(r)}), async: ${t.iterationsAsync}`;
835
- if (t.prevLogMemory != null) {
836
- const f = Q();
837
- f != null && (l += `, memory: ${be(f, t.prevLogMemory)}`, t.prevLogMemory = f);
838
- }
839
- return i.func("progress", l), t.prevLogTime = s, !0;
840
- }
841
- function J(e, n) {
842
- e.debugMode = !1, n && (e.iterationsAsync += n.iterationsAsync, e.iterations += n.iterationsSync + n.iterationsAsync);
843
- }
844
- function X(e) {
845
- e.state.debugMode = !0, e.abortControllerParallel.abort(new I());
846
- }
847
- function ve(e, n) {
848
- const { testRun: t, testOptions: i, state: o } = e, s = o.tests;
849
- o.tests++;
850
- try {
851
- const r = t(n, s, i);
852
- if (T(r))
853
- return r.then(
854
- (l) => {
855
- if (!l) {
856
- X(e);
857
- return;
858
- }
859
- J(o, l);
860
- },
861
- (l) => ce(e, n, l, s)
862
- );
863
- if (!r) {
864
- X(e);
865
- return;
866
- }
867
- J(o, r);
868
- } catch (r) {
869
- return r instanceof I ? void 0 : ce(e, n, r, s);
870
- }
871
- }
872
- function wt(e, n) {
873
- const { pool: t, abortSignal: i, testRun: o, testOptionsParallel: s, state: r } = e;
874
- if (!t)
875
- return;
876
- const l = r.tests;
877
- r.tests++, (async () => {
878
- try {
879
- if (i.aborted)
880
- return;
881
- let f = o(n, l, s);
882
- if (T(f) && (f = await f), !f) {
883
- X(e);
884
- return;
885
- }
886
- J(r, f);
887
- } catch (f) {
888
- if (f instanceof I)
889
- return;
890
- ht(e, n, f, l);
891
- } finally {
892
- t.release(1);
893
- }
894
- })();
895
- }
896
- function Ee(e) {
897
- const { options: n, state: t } = e, { logOptions: i, timeController: o, GC_Interval: s } = n;
898
- if (!i.progress && !s)
899
- return;
900
- xt(e);
901
- const r = o.now();
902
- if (bt(e, r))
903
- return yt(t, r);
904
- }
905
- function k(e) {
906
- return e.options.abortSignalExternal?.aborted ?? !1;
907
- }
908
- function Z(e) {
909
- return e.abortSignal.aborted;
910
- }
911
- async function W(e, n) {
912
- const { pool: t, state: i, options: o } = e, { parallel: s, logOptions: r } = o;
913
- let l = null;
914
- for (; !k(e); ) {
915
- const f = t && !Z(e);
916
- let m = !1;
917
- f && (t.hold(1) || await se({ pool: t, count: 1, hold: !0 }), m = !0);
918
- try {
919
- if (n != null ? (l = n, n = null) : e.state.debugMode || (l = e.variantsIterator.next()), l == null)
920
- break;
921
- const c = Ee(e);
922
- if (T(c) && await c, k(e))
923
- continue;
924
- if (f)
925
- wt(e, l), m = !1;
926
- else {
927
- r.debug && t && Z(e) && r.func(
928
- "debug",
929
- `[test-variants] parallel aborted, running sequential: tests=${i.tests}`
930
- );
931
- const b = ve(e, l);
932
- T(b) && await b;
933
- }
934
- } finally {
935
- m && t.release(1);
936
- }
937
- }
938
- t && (await se({ pool: t, count: s, hold: !0 }), t.release(s));
939
- }
940
- function Mt(e) {
941
- const { pool: n, state: t, options: i } = e, { logOptions: o } = i;
942
- if (n)
943
- return W(e);
944
- let s = null;
945
- for (; !k(e) && (e.state.debugMode || (s = e.variantsIterator.next()), s != null); ) {
946
- const r = Ee(e);
947
- if (T(r))
948
- return r.then(() => W(e, s));
949
- if (k(e))
950
- continue;
951
- o.debug && Z(e) && o.func(
952
- "debug",
953
- `[test-variants] parallel aborted, running sequential: tests=${t.tests}`
954
- );
955
- const l = ve(e, s);
956
- if (T(l))
957
- return l.then(() => W(e));
958
- }
959
- }
960
- async function It(e, n, t, i) {
961
- const o = pt(i), {
962
- store: s,
963
- logOptions: r,
964
- abortSignalExternal: l,
965
- findBestError: f,
966
- dontThrowIfError: m,
967
- timeController: c,
968
- parallel: b
969
- } = o, y = new ie(), d = new ie(), h = oe(
970
- l,
971
- y.signal
972
- ), v = oe(
973
- h,
974
- d.signal
975
- ), x = {
976
- abortSignal: h,
977
- timeController: c
978
- }, p = {
979
- abortSignal: v,
980
- timeController: c
981
- };
982
- s && await s.replay({
983
- testRun: e,
984
- variantsIterator: n,
985
- testOptions: x,
986
- findBestErrorEnabled: !!f
987
- });
988
- const w = b <= 1 ? null : new Ke(b);
989
- Et(r, t.startMemory);
990
- const A = {
991
- options: o,
992
- testRun: e,
993
- variantsIterator: n,
994
- testOptions: x,
995
- testOptionsParallel: p,
996
- abortControllerGlobal: y,
997
- abortControllerParallel: d,
998
- abortSignal: v,
999
- pool: w,
1000
- state: t
1001
- };
1002
- ye(A);
1003
- try {
1004
- await Mt(A), v.throwIfAborted();
1005
- } catch (P) {
1006
- throw y.abort(new I()), P;
1007
- }
1008
- return h.throwIfAborted(), y.abort(new I()), St(A), await Y(1), mt(t, n, m);
1009
- }
1010
- function Nt(e) {
1011
- return function(t) {
1012
- return async function(o) {
1013
- const s = pe(o?.log), r = st(e, {
1014
- onStart: o?.onStart,
1015
- onEnd: o?.onEnd,
1016
- onError: o?.onError,
1017
- log: s,
1018
- pauseDebuggerOnError: o?.pauseDebuggerOnError
1019
- }), l = o?.timeController ?? K, f = Q(), m = nt(l, f), c = o?.onModeChange;
1020
- function b(d) {
1021
- m.pendingModeChange = d, c?.(d);
1022
- }
1023
- const y = dt({
1024
- argsTemplates: t,
1025
- getSeed: o?.getSeed,
1026
- iterationModes: o?.iterationModes,
1027
- equals: o?.findBestError?.equals,
1028
- limitArgOnError: o?.findBestError?.limitArgOnError,
1029
- includeErrorVariant: o?.findBestError?.includeErrorVariant,
1030
- timeController: l,
1031
- onModeChange: b,
1032
- limitCompletionCount: o?.cycles ?? 1,
1033
- limitTests: o?.limitTests,
1034
- limitTime: o?.limitTime
1035
- });
1036
- return It(r, y, m, o);
1037
- };
1038
- };
1039
- }
1040
- export {
1041
- Nt as c
1042
- };