@flemist/test-variants 5.0.17 → 5.0.18

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 CHANGED
@@ -330,7 +330,8 @@ The internal implementation operates in a faster synchronous mode (without await
330
330
  ```
331
331
  [test-variants] replay skipped, args not in template; file: tmp/test/variants/2025-01-01_10-00-00.json
332
332
  [test-variants] replay, files: 2/3, memory: 139MB
333
- [test-variants] replay end, tests: 20 (1.5s), maxTime: 0.1s, async: 0, memory: 148MB (+8.8MB)
333
+ [test-variants] replay, tests: 10 (5.0s), maxTime: 0.1s, async: 0, memory: 148MB (+8.8MB)
334
+ [test-variants] replay end, tests: 20 (10.5s), maxTime: 0.1s, async: 0, memory: 148MB (+8.8MB)
334
335
  [test-variants] start, memory: 139MB
335
336
  [test-variants] mode[0]: random
336
337
  [test-variants] tests: 615 (5.0s), maxTime: 0.1s, async: 12, memory: 148MB (+8.8MB)
@@ -1,4 +1,4 @@
1
- import { T as e, c as t } from "../createTestVariants-CHmhRbUZ.mjs";
1
+ import { T as e, c as t } from "../createTestVariants-BiAcjV3Y.mjs";
2
2
  export {
3
3
  e as TimeoutError,
4
4
  t as createTestVariants
@@ -1,4 +1,4 @@
1
- import { T as e, c as t } from "../createTestVariants-CHmhRbUZ.mjs";
1
+ import { T as e, c as t } from "../createTestVariants-BiAcjV3Y.mjs";
2
2
  export {
3
3
  e as TimeoutError,
4
4
  t as createTestVariants
@@ -892,7 +892,13 @@ function Vt(e) {
892
892
  const { options: t, state: r } = e, { logOptions: o, timeControllerInternal: i } = t;
893
893
  if (!o.completed)
894
894
  return;
895
- const s = i.now() - r.startTime, n = xe(r.tests, s, r.maxTestDuration, r.iterationsAsync, r.startMemory);
895
+ const s = i.now() - r.startTime, n = xe(
896
+ r.tests,
897
+ s,
898
+ r.maxTestDuration,
899
+ r.iterationsAsync,
900
+ r.startMemory
901
+ );
896
902
  o.func("completed", `[test-variants] end, ${n.message}`);
897
903
  }
898
904
  function Se(e) {
@@ -907,7 +913,13 @@ function Ct(e) {
907
913
  if (!o.progress || s - r.prevLogTime < o.progress)
908
914
  return !1;
909
915
  Se(e);
910
- const n = s - r.startTime, l = xe(r.tests, n, r.maxTestDuration, r.iterationsAsync, r.prevLogMemory);
916
+ const n = s - r.startTime, l = xe(
917
+ r.tests,
918
+ n,
919
+ r.maxTestDuration,
920
+ r.iterationsAsync,
921
+ r.prevLogMemory
922
+ );
911
923
  return l.memory != null && (r.prevLogMemory = l.memory), o.func("progress", `[test-variants] ${l.message}`), r.prevLogTime = s, !0;
912
924
  }
913
925
  function re(e, t) {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../createTestVariants-B-tIuCMH.js"),k=require("path"),v=require("@flemist/simple-utils"),I=require("@flemist/simple-utils/node"),L=require("fs");function F(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const S=F(k),h=F(L);async function N(e){const t=await h.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await h.promises.readdir(e)).filter(s=>s.endsWith(".json")).sort((s,o)=>s>o?-1:s<o?1:0).map(s=>S.join(e,s))}async function q(e,t){const n=await h.promises.readFile(e,"utf-8");let r;try{r=JSON.parse(n)}catch{throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`)}if(t)try{return t(r)}catch{throw new Error(`[saveErrorVariants] jsonToArgs failed for file: ${e}`)}return r}function _(e){const t=Math.random().toString(36).substring(2);return v.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function J(e,t,n){let r;if(n){const s=n(e);typeof s=="string"?r=s:r=JSON.stringify(s,null,2)}else r=JSON.stringify(e,null,2);await h.promises.mkdir(S.dirname(t),{recursive:!0}),await h.promises.writeFile(t,r,"utf-8")}function B(e,t){const n=Math.max(e.length,t.length);for(let r=0;r<n;r++){const s=e[r],o=t[r];if(s==null){if(o==null)continue;return 1}if(o==null||s<o)return-1;if(s>o)return 1}return 0}class C{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const n=new Date;this.filePath=S.resolve(t.dir,t.getFilePath?.({sessionDate:n})??_({sessionDate:n}))}async save(t){v.deepEqualJsonLike(t,this.lastSavedArgs)||(this.lastSavedArgs={...t},await I.fileLock({filePath:this.filePath,func:()=>J(t,this.filePath,this.options.argsToJson)}))}async replay(t){const{testRun:n,variantsIterator:r,testOptions:s,findBestErrorEnabled:o,state:l,logOptions:u,timeControllerInternal:E}=t,P=this.options.useToFindBestError,b=this.options.limitArg??!1,$=this.options.extendTemplates??!1,D=this.options.attemptsPerVariant??1,T=new Map;function w(i){let a=T.get(i);return a===void 0&&(a=r.calcIndexes(i,{includeLimit:!1,limitArg:b}),T.set(i,a)),a}const d=await N(this.options.dir);if(d.length===0)return;const c=[];for(let i=0,a=d.length;i<a;i++){const p=d[i],f=await q(p,this.options.jsonToArgs);$&&r.extendTemplates(f),w(f)!=null?c.push(f):u.replay&&u.func("replay",`[test-variants] replay skipped, args not in template; file: ${p}`)}if(c.length===0)return;const V=u.replay;let A=0,O=0,j=0,m=null;if(V){A=E.now(),O=l.tests,j=l.iterationsAsync,m=y.getMemoryUsage();let i=`[test-variants] replay, files: ${c.length}/${d.length}`;m!=null&&(i+=`, memory: ${y.formatBytes(m)}`),u.func("replay",i)}function M(i,a){return B(w(i),w(a))}c.sort(M);for(let i=0,a=c.length;i<a;i++){const p=c[i];for(let f=0;f<D;f++)try{const g=l.tests;l.tests++;const x=n(p,g,s);v.isPromiseLike(x)&&await x}catch(g){if(P&&o){r.addLimit({args:p,error:g});break}throw g}}if(V){const i=E.now()-A,a=y.formatTestStats(l.tests-O,i,l.maxTestDuration,l.iterationsAsync-j,m);u.func("replay",`[test-variants] replay end, ${a.message}`)}}}function R(e){return new C(e)}function U(e){const t=y.createTestVariants(e);return function(r){const s=t(r);return function(l){return s({...l,createSaveErrorVariantsStore:R})}}}exports.createTestVariants=U;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../createTestVariants-B-tIuCMH.js"),q=require("path"),V=require("@flemist/simple-utils"),_=require("@flemist/simple-utils/node"),J=require("fs");function D(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const A=D(q),h=D(J);async function B(e){const t=await h.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await h.promises.readdir(e)).filter(s=>s.endsWith(".json")).sort((s,l)=>s>l?-1:s<l?1:0).map(s=>A.join(e,s))}async function C(e,t){const n=await h.promises.readFile(e,"utf-8");let r;try{r=JSON.parse(n)}catch{throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`)}if(t)try{return t(r)}catch{throw new Error(`[saveErrorVariants] jsonToArgs failed for file: ${e}`)}return r}function R(e){const t=Math.random().toString(36).substring(2);return V.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function U(e,t,n){let r;if(n){const s=n(e);typeof s=="string"?r=s:r=JSON.stringify(s,null,2)}else r=JSON.stringify(e,null,2);await h.promises.mkdir(A.dirname(t),{recursive:!0}),await h.promises.writeFile(t,r,"utf-8")}function z(e,t){const n=Math.max(e.length,t.length);for(let r=0;r<n;r++){const s=e[r],l=t[r];if(s==null){if(l==null)continue;return 1}if(l==null||s<l)return-1;if(s>l)return 1}return 0}class W{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const n=new Date;this.filePath=A.resolve(t.dir,t.getFilePath?.({sessionDate:n})??R({sessionDate:n}))}async save(t){V.deepEqualJsonLike(t,this.lastSavedArgs)||(this.lastSavedArgs={...t},await _.fileLock({filePath:this.filePath,func:()=>U(t,this.filePath,this.options.argsToJson)}))}async replay(t){const{testRun:n,variantsIterator:r,testOptions:s,findBestErrorEnabled:l,state:a,logOptions:c,timeControllerInternal:v}=t,M=this.options.useToFindBestError,I=this.options.limitArg??!1,k=this.options.extendTemplates??!1,L=this.options.attemptsPerVariant??1,x=new Map;function T(i){let o=x.get(i);return o===void 0&&(o=r.calcIndexes(i,{includeLimit:!1,limitArg:I}),x.set(i,o)),o}const d=await B(this.options.dir);if(d.length===0)return;const u=[];for(let i=0,o=d.length;i<o;i++){const m=d[i],p=await C(m,this.options.jsonToArgs);k&&r.extendTemplates(p),T(p)!=null?u.push(p):c.replay&&c.func("replay",`[test-variants] replay skipped, args not in template; file: ${m}`)}if(u.length===0)return;const O=c.replay,P=c.replay&&c.progress,S=v.now(),j=a.tests,F=a.iterationsAsync,y=g.getMemoryUsage();if(O){let i=`[test-variants] replay, files: ${u.length}/${d.length}`;y!=null&&(i+=`, memory: ${g.formatBytes(y)}`),c.func("replay",i)}function N(i,o){return z(T(i),T(o))}u.sort(N);let b=S,$=y;for(let i=0,o=u.length;i<o;i++){const m=u[i];for(let p=0;p<L;p++){if(P){const f=v.now();if(f-b>=P){b=f;const w=f-S,E=g.formatTestStats(a.tests-j,w,a.maxTestDuration,a.iterationsAsync-F,$);E.memory!=null&&($=E.memory),c.func("progress",`[test-variants] replay, ${E.message}`)}}try{const f=a.tests;a.tests++;const w=n(m,f,s);V.isPromiseLike(w)&&await w}catch(f){if(M&&l){r.addLimit({args:m,error:f});break}throw f}}}if(O){const i=v.now()-S,o=g.formatTestStats(a.tests-j,i,a.maxTestDuration,a.iterationsAsync-F,y);c.func("replay",`[test-variants] replay end, ${o.message}`)}}}function G(e){return new W(e)}function H(e){const t=g.createTestVariants(e);return function(r){const s=t(r);return function(a){return s({...a,createSaveErrorVariantsStore:G})}}}exports.createTestVariants=H;
@@ -1,168 +1,185 @@
1
- import { g as L, f as O, a as k, c as D } from "../createTestVariants-CHmhRbUZ.mjs";
2
- import * as w from "path";
3
- import { formatDateFileName as M, deepEqualJsonLike as N, isPromiseLike as J } from "@flemist/simple-utils";
4
- import { fileLock as B } from "@flemist/simple-utils/node";
5
- import * as m from "fs";
6
- async function C(e) {
7
- const t = await m.promises.stat(e).catch(() => null);
1
+ import { g as N, f as J, a as j, c as B } from "../createTestVariants-BiAcjV3Y.mjs";
2
+ import * as V from "path";
3
+ import { formatDateFileName as C, deepEqualJsonLike as R, isPromiseLike as b } from "@flemist/simple-utils";
4
+ import { fileLock as U } from "@flemist/simple-utils/node";
5
+ import * as h from "fs";
6
+ async function q(e) {
7
+ const t = await h.promises.stat(e).catch(() => null);
8
8
  if (t == null)
9
9
  return [];
10
10
  if (!t.isDirectory())
11
11
  throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);
12
- return (await m.promises.readdir(e)).filter((s) => s.endsWith(".json")).sort((s, o) => s > o ? -1 : s < o ? 1 : 0).map((s) => w.join(e, s));
12
+ return (await h.promises.readdir(e)).filter((r) => r.endsWith(".json")).sort((r, l) => r > l ? -1 : r < l ? 1 : 0).map((r) => V.join(e, r));
13
13
  }
14
- async function R(e, t) {
15
- const i = await m.promises.readFile(e, "utf-8");
16
- let r;
14
+ async function W(e, t) {
15
+ const i = await h.promises.readFile(e, "utf-8");
16
+ let s;
17
17
  try {
18
- r = JSON.parse(i);
18
+ s = JSON.parse(i);
19
19
  } catch {
20
20
  throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`);
21
21
  }
22
22
  if (t)
23
23
  try {
24
- return t(r);
24
+ return t(s);
25
25
  } catch {
26
26
  throw new Error(
27
27
  `[saveErrorVariants] jsonToArgs failed for file: ${e}`
28
28
  );
29
29
  }
30
- return r;
30
+ return s;
31
31
  }
32
- function b(e) {
32
+ function _(e) {
33
33
  const t = Math.random().toString(36).substring(2);
34
- return M(e.sessionDate, "UTC") + "_" + t + ".json";
34
+ return C(e.sessionDate, "UTC") + "_" + t + ".json";
35
35
  }
36
- async function U(e, t, i) {
37
- let r;
36
+ async function z(e, t, i) {
37
+ let s;
38
38
  if (i) {
39
- const s = i(e);
40
- typeof s == "string" ? r = s : r = JSON.stringify(s, null, 2);
39
+ const r = i(e);
40
+ typeof r == "string" ? s = r : s = JSON.stringify(r, null, 2);
41
41
  } else
42
- r = JSON.stringify(e, null, 2);
43
- await m.promises.mkdir(w.dirname(t), { recursive: !0 }), await m.promises.writeFile(t, r, "utf-8");
42
+ s = JSON.stringify(e, null, 2);
43
+ await h.promises.mkdir(V.dirname(t), { recursive: !0 }), await h.promises.writeFile(t, s, "utf-8");
44
44
  }
45
- function q(e, t) {
45
+ function G(e, t) {
46
46
  const i = Math.max(e.length, t.length);
47
- for (let r = 0; r < i; r++) {
48
- const s = e[r], o = t[r];
49
- if (s == null) {
50
- if (o == null)
47
+ for (let s = 0; s < i; s++) {
48
+ const r = e[s], l = t[s];
49
+ if (r == null) {
50
+ if (l == null)
51
51
  continue;
52
52
  return 1;
53
53
  }
54
- if (o == null || s < o)
54
+ if (l == null || r < l)
55
55
  return -1;
56
- if (s > o)
56
+ if (r > l)
57
57
  return 1;
58
58
  }
59
59
  return 0;
60
60
  }
61
- class W {
61
+ class H {
62
62
  options;
63
63
  filePath;
64
64
  lastSavedArgs = null;
65
65
  constructor(t) {
66
66
  this.options = t;
67
67
  const i = /* @__PURE__ */ new Date();
68
- this.filePath = w.resolve(
68
+ this.filePath = V.resolve(
69
69
  t.dir,
70
- t.getFilePath?.({ sessionDate: i }) ?? b({ sessionDate: i })
70
+ t.getFilePath?.({ sessionDate: i }) ?? _({ sessionDate: i })
71
71
  );
72
72
  }
73
73
  async save(t) {
74
- N(t, this.lastSavedArgs) || (this.lastSavedArgs = { ...t }, await B({
74
+ R(t, this.lastSavedArgs) || (this.lastSavedArgs = { ...t }, await U({
75
75
  filePath: this.filePath,
76
- func: () => U(t, this.filePath, this.options.argsToJson)
76
+ func: () => z(t, this.filePath, this.options.argsToJson)
77
77
  }));
78
78
  }
79
79
  async replay(t) {
80
80
  const {
81
81
  testRun: i,
82
- variantsIterator: r,
83
- testOptions: s,
84
- findBestErrorEnabled: o,
85
- state: l,
86
- logOptions: u,
87
- timeControllerInternal: v
88
- } = t, F = this.options.useToFindBestError, $ = this.options.limitArg ?? !1, P = this.options.extendTemplates ?? !1, j = this.options.attemptsPerVariant ?? 1, E = /* @__PURE__ */ new Map();
89
- function y(n) {
90
- let a = E.get(n);
91
- return a === void 0 && (a = r.calcIndexes(n, {
82
+ variantsIterator: s,
83
+ testOptions: r,
84
+ findBestErrorEnabled: l,
85
+ state: a,
86
+ logOptions: c,
87
+ timeControllerInternal: w
88
+ } = t, D = this.options.useToFindBestError, L = this.options.limitArg ?? !1, M = this.options.extendTemplates ?? !1, O = this.options.attemptsPerVariant ?? 1, x = /* @__PURE__ */ new Map();
89
+ function v(n) {
90
+ let o = x.get(n);
91
+ return o === void 0 && (o = s.calcIndexes(n, {
92
92
  includeLimit: !1,
93
- limitArg: $
94
- }), E.set(n, a)), a;
93
+ limitArg: L
94
+ }), x.set(n, o)), o;
95
95
  }
96
- const h = await C(this.options.dir);
97
- if (h.length === 0)
96
+ const g = await q(this.options.dir);
97
+ if (g.length === 0)
98
98
  return;
99
- const c = [];
100
- for (let n = 0, a = h.length; n < a; n++) {
101
- const p = h[n], f = await R(
102
- p,
99
+ const u = [];
100
+ for (let n = 0, o = g.length; n < o; n++) {
101
+ const m = g[n], p = await W(
102
+ m,
103
103
  this.options.jsonToArgs
104
104
  );
105
- P && r.extendTemplates(f), y(f) != null ? c.push(f) : u.replay && u.func("replay", `[test-variants] replay skipped, args not in template; file: ${p}`);
105
+ M && s.extendTemplates(p), v(p) != null ? u.push(p) : c.replay && c.func(
106
+ "replay",
107
+ `[test-variants] replay skipped, args not in template; file: ${m}`
108
+ );
106
109
  }
107
- if (c.length === 0)
110
+ if (u.length === 0)
108
111
  return;
109
- const V = u.replay;
110
- let S = 0, x = 0, A = 0, d = null;
111
- if (V) {
112
- S = v.now(), x = l.tests, A = l.iterationsAsync, d = L();
113
- let n = `[test-variants] replay, files: ${c.length}/${h.length}`;
114
- d != null && (n += `, memory: ${O(d)}`), u.func("replay", n);
112
+ const A = c.replay, S = c.replay && c.progress, E = w.now(), F = a.tests, P = a.iterationsAsync, y = N();
113
+ if (A) {
114
+ let n = `[test-variants] replay, files: ${u.length}/${g.length}`;
115
+ y != null && (n += `, memory: ${J(y)}`), c.func("replay", n);
115
116
  }
116
- function I(n, a) {
117
- return q(y(n), y(a));
117
+ function k(n, o) {
118
+ return G(v(n), v(o));
118
119
  }
119
- c.sort(I);
120
- for (let n = 0, a = c.length; n < a; n++) {
121
- const p = c[n];
122
- for (let f = 0; f < j; f++)
120
+ u.sort(k);
121
+ let $ = E, I = y;
122
+ for (let n = 0, o = u.length; n < o; n++) {
123
+ const m = u[n];
124
+ for (let p = 0; p < O; p++) {
125
+ if (S) {
126
+ const f = w.now();
127
+ if (f - $ >= S) {
128
+ $ = f;
129
+ const d = f - E, T = j(
130
+ a.tests - F,
131
+ d,
132
+ a.maxTestDuration,
133
+ a.iterationsAsync - P,
134
+ I
135
+ );
136
+ T.memory != null && (I = T.memory), c.func("progress", `[test-variants] replay, ${T.message}`);
137
+ }
138
+ }
123
139
  try {
124
- const g = l.tests;
125
- l.tests++;
126
- const T = i(p, g, s);
127
- J(T) && await T;
128
- } catch (g) {
129
- if (F && o) {
130
- r.addLimit({
131
- args: p,
132
- error: g
140
+ const f = a.tests;
141
+ a.tests++;
142
+ const d = i(m, f, r);
143
+ b(d) && await d;
144
+ } catch (f) {
145
+ if (D && l) {
146
+ s.addLimit({
147
+ args: m,
148
+ error: f
133
149
  });
134
150
  break;
135
151
  }
136
- throw g;
152
+ throw f;
137
153
  }
154
+ }
138
155
  }
139
- if (V) {
140
- const n = v.now() - S, a = k(
141
- l.tests - x,
156
+ if (A) {
157
+ const n = w.now() - E, o = j(
158
+ a.tests - F,
142
159
  n,
143
- l.maxTestDuration,
144
- l.iterationsAsync - A,
145
- d
160
+ a.maxTestDuration,
161
+ a.iterationsAsync - P,
162
+ y
146
163
  );
147
- u.func("replay", `[test-variants] replay end, ${a.message}`);
164
+ c.func("replay", `[test-variants] replay end, ${o.message}`);
148
165
  }
149
166
  }
150
167
  }
151
- function _(e) {
152
- return new W(e);
153
- }
154
168
  function K(e) {
155
- const t = D(e);
156
- return function(r) {
157
- const s = t(r);
158
- return function(l) {
159
- return s({
160
- ...l,
161
- createSaveErrorVariantsStore: _
169
+ return new H(e);
170
+ }
171
+ function Z(e) {
172
+ const t = B(e);
173
+ return function(s) {
174
+ const r = t(s);
175
+ return function(a) {
176
+ return r({
177
+ ...a,
178
+ createSaveErrorVariantsStore: K
162
179
  });
163
180
  };
164
181
  };
165
182
  }
166
183
  export {
167
- K as createTestVariants
184
+ Z as createTestVariants
168
185
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "5.0.17",
3
+ "version": "5.0.18",
4
4
  "description": "Runs a test function with all possible combinations of its parameters.",
5
5
  "sideEffects": false,
6
6
  "types": "build/common/index.d.ts",