@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
|
|
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)
|
package/build/browser/index.mjs
CHANGED
package/build/common/index.mjs
CHANGED
|
@@ -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(
|
|
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(
|
|
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) {
|
package/build/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/build/node/index.mjs
CHANGED
|
@@ -1,168 +1,185 @@
|
|
|
1
|
-
import { g as
|
|
2
|
-
import * as
|
|
3
|
-
import { formatDateFileName as
|
|
4
|
-
import { fileLock as
|
|
5
|
-
import * as
|
|
6
|
-
async function
|
|
7
|
-
const t = await
|
|
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
|
|
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
|
|
15
|
-
const i = await
|
|
16
|
-
let
|
|
14
|
+
async function W(e, t) {
|
|
15
|
+
const i = await h.promises.readFile(e, "utf-8");
|
|
16
|
+
let s;
|
|
17
17
|
try {
|
|
18
|
-
|
|
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(
|
|
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
|
|
30
|
+
return s;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function _(e) {
|
|
33
33
|
const t = Math.random().toString(36).substring(2);
|
|
34
|
-
return
|
|
34
|
+
return C(e.sessionDate, "UTC") + "_" + t + ".json";
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
37
|
-
let
|
|
36
|
+
async function z(e, t, i) {
|
|
37
|
+
let s;
|
|
38
38
|
if (i) {
|
|
39
|
-
const
|
|
40
|
-
typeof
|
|
39
|
+
const r = i(e);
|
|
40
|
+
typeof r == "string" ? s = r : s = JSON.stringify(r, null, 2);
|
|
41
41
|
} else
|
|
42
|
-
|
|
43
|
-
await
|
|
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
|
|
45
|
+
function G(e, t) {
|
|
46
46
|
const i = Math.max(e.length, t.length);
|
|
47
|
-
for (let
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
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 (
|
|
54
|
+
if (l == null || r < l)
|
|
55
55
|
return -1;
|
|
56
|
-
if (
|
|
56
|
+
if (r > l)
|
|
57
57
|
return 1;
|
|
58
58
|
}
|
|
59
59
|
return 0;
|
|
60
60
|
}
|
|
61
|
-
class
|
|
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 =
|
|
68
|
+
this.filePath = V.resolve(
|
|
69
69
|
t.dir,
|
|
70
|
-
t.getFilePath?.({ sessionDate: i }) ??
|
|
70
|
+
t.getFilePath?.({ sessionDate: i }) ?? _({ sessionDate: i })
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
async save(t) {
|
|
74
|
-
|
|
74
|
+
R(t, this.lastSavedArgs) || (this.lastSavedArgs = { ...t }, await U({
|
|
75
75
|
filePath: this.filePath,
|
|
76
|
-
func: () =>
|
|
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:
|
|
83
|
-
testOptions:
|
|
84
|
-
findBestErrorEnabled:
|
|
85
|
-
state:
|
|
86
|
-
logOptions:
|
|
87
|
-
timeControllerInternal:
|
|
88
|
-
} = t,
|
|
89
|
-
function
|
|
90
|
-
let
|
|
91
|
-
return
|
|
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
|
-
}),
|
|
93
|
+
limitArg: L
|
|
94
|
+
}), x.set(n, o)), o;
|
|
95
95
|
}
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
96
|
+
const g = await q(this.options.dir);
|
|
97
|
+
if (g.length === 0)
|
|
98
98
|
return;
|
|
99
|
-
const
|
|
100
|
-
for (let n = 0,
|
|
101
|
-
const
|
|
102
|
-
|
|
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
|
-
|
|
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 (
|
|
110
|
+
if (u.length === 0)
|
|
108
111
|
return;
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
117
|
-
return
|
|
117
|
+
function k(n, o) {
|
|
118
|
+
return G(v(n), v(o));
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
} catch (
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
args:
|
|
132
|
-
error:
|
|
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
|
|
152
|
+
throw f;
|
|
137
153
|
}
|
|
154
|
+
}
|
|
138
155
|
}
|
|
139
|
-
if (
|
|
140
|
-
const n =
|
|
141
|
-
|
|
156
|
+
if (A) {
|
|
157
|
+
const n = w.now() - E, o = j(
|
|
158
|
+
a.tests - F,
|
|
142
159
|
n,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
160
|
+
a.maxTestDuration,
|
|
161
|
+
a.iterationsAsync - P,
|
|
162
|
+
y
|
|
146
163
|
);
|
|
147
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
184
|
+
Z as createTestVariants
|
|
168
185
|
};
|