@flemist/test-variants 5.0.1 → 5.0.2
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/build/node/index.cjs +1 -1
- package/build/node/index.mjs +28 -29
- package/package.json +1 -1
package/build/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../createTestVariants-Cmx68kHs.js"),S=require("path"),j=require("@flemist/async-utils"),d=require("@flemist/simple-utils"),F=require("@flemist/simple-utils/node"),O=require("fs");function m(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../createTestVariants-Cmx68kHs.js"),S=require("path"),j=require("@flemist/async-utils"),d=require("@flemist/simple-utils"),F=require("@flemist/simple-utils/node"),O=require("fs");function m(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const u=m(S),a=m(O);async function T(e){const t=await a.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await a.promises.readdir(e)).filter(i=>i.endsWith(".json")).sort((i,n)=>i>n?-1:i<n?1:0).map(i=>u.join(e,i))}async function b(e,t){const s=await a.promises.readFile(e,"utf-8");let r;try{r=JSON.parse(s)}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 P(e){const t=Math.random().toString(36).substring(2);return d.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function A(e,t,s){let r;if(s){const i=s(e);typeof i=="string"?r=i:r=JSON.stringify(i,null,2)}else r=JSON.stringify(e,null,2);await a.promises.mkdir(u.dirname(t),{recursive:!0}),await a.promises.writeFile(t,r,"utf-8")}class q{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const s=new Date;this.filePath=u.resolve(t.dir,t.getFilePath?.({sessionDate:s})??P({sessionDate:s}))}async save(t){d.deepEqualJsonLike(t,this.lastSavedArgs)||(this.lastSavedArgs={...t},await F.fileLock({filePath:this.filePath,func:()=>A(t,this.filePath,this.options.argsToJson)}))}async replay(t){const{testRun:s,variantsIterator:r,testOptions:i,findBestErrorEnabled:n}=t,c=this.options.useToFindBestError,g=this.options.limitArg??!1,w=this.options.extendTemplates??!1,y=this.options.attemptsPerVariant??1,f=await T(this.options.dir);for(let l=0,E=f.length;l<E;l++){const V=f[l],p=await b(V,this.options.jsonToArgs);for(let h=0;h<y;h++)try{const o=s(p,0,i);j.isPromiseLike(o)&&await o}catch(o){r.addLimit({args:p,error:o,limitArg:g,extendTemplates:w});break}}if(!(c&&n)&&r.limit)throw r.limit.error??new Error("Limit found but error missing")}}function D(e){return new q(e)}function N(e){const t=v.createTestVariants(e);return function(r){const i=t(r);return function(c){return i({...c,createSaveErrorVariantsStore:D})}}}exports.createTestVariants=N;
|
package/build/node/index.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { c as y } from "../createTestVariants-BE_TQ9u5.mjs";
|
|
2
2
|
import * as f from "path";
|
|
3
|
-
import { isPromiseLike as
|
|
3
|
+
import { isPromiseLike as V } from "@flemist/async-utils";
|
|
4
4
|
import { formatDateFileName as v, deepEqualJsonLike as F } from "@flemist/simple-utils";
|
|
5
5
|
import { fileLock as S } from "@flemist/simple-utils/node";
|
|
6
|
-
import * as
|
|
6
|
+
import * as a from "fs";
|
|
7
7
|
async function A(r) {
|
|
8
|
-
const t = await
|
|
8
|
+
const t = await a.promises.stat(r).catch(() => null);
|
|
9
9
|
if (t == null)
|
|
10
10
|
return [];
|
|
11
11
|
if (!t.isDirectory())
|
|
12
12
|
throw new Error(`[saveErrorVariants] path is not a directory: ${r}`);
|
|
13
|
-
return (await
|
|
13
|
+
return (await a.promises.readdir(r)).filter((e) => e.endsWith(".json")).sort((e, n) => e > n ? -1 : e < n ? 1 : 0).map((e) => f.join(r, e));
|
|
14
14
|
}
|
|
15
15
|
async function P(r, t) {
|
|
16
|
-
const i = await
|
|
16
|
+
const i = await a.promises.readFile(r, "utf-8");
|
|
17
17
|
let s;
|
|
18
18
|
try {
|
|
19
19
|
s = JSON.parse(i);
|
|
@@ -41,9 +41,9 @@ async function j(r, t, i) {
|
|
|
41
41
|
typeof e == "string" ? s = e : s = JSON.stringify(e, null, 2);
|
|
42
42
|
} else
|
|
43
43
|
s = JSON.stringify(r, null, 2);
|
|
44
|
-
await
|
|
44
|
+
await a.promises.mkdir(f.dirname(t), { recursive: !0 }), await a.promises.writeFile(t, s, "utf-8");
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class L {
|
|
47
47
|
options;
|
|
48
48
|
filePath;
|
|
49
49
|
lastSavedArgs = null;
|
|
@@ -62,42 +62,41 @@ class N {
|
|
|
62
62
|
}));
|
|
63
63
|
}
|
|
64
64
|
async replay(t) {
|
|
65
|
-
const { testRun: i, variantsIterator: s, testOptions: e, findBestErrorEnabled: n } = t, l = this.options.useToFindBestError,
|
|
65
|
+
const { testRun: i, variantsIterator: s, testOptions: e, findBestErrorEnabled: n } = t, l = this.options.useToFindBestError, p = this.options.limitArg ?? !1, d = this.options.extendTemplates ?? !1, w = this.options.attemptsPerVariant ?? 1, u = await A(this.options.dir);
|
|
66
66
|
for (let c = 0, E = u.length; c < E; c++) {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const g = u[c], m = await P(
|
|
68
|
+
g,
|
|
69
69
|
this.options.jsonToArgs
|
|
70
70
|
);
|
|
71
|
-
for (let
|
|
71
|
+
for (let h = 0; h < w; h++)
|
|
72
72
|
try {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
} catch (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
break;
|
|
84
|
-
} else
|
|
85
|
-
throw a;
|
|
73
|
+
const o = i(m, 0, e);
|
|
74
|
+
V(o) && await o;
|
|
75
|
+
} catch (o) {
|
|
76
|
+
s.addLimit({
|
|
77
|
+
args: m,
|
|
78
|
+
error: o,
|
|
79
|
+
limitArg: p,
|
|
80
|
+
extendTemplates: d
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
86
83
|
}
|
|
87
84
|
}
|
|
85
|
+
if (!(l && n) && s.limit)
|
|
86
|
+
throw s.limit.error ?? new Error("Limit found but error missing");
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
function
|
|
91
|
-
return new
|
|
89
|
+
function N(r) {
|
|
90
|
+
return new L(r);
|
|
92
91
|
}
|
|
93
92
|
function x(r) {
|
|
94
|
-
const t =
|
|
93
|
+
const t = y(r);
|
|
95
94
|
return function(s) {
|
|
96
95
|
const e = t(s);
|
|
97
96
|
return function(l) {
|
|
98
97
|
return e({
|
|
99
98
|
...l,
|
|
100
|
-
createSaveErrorVariantsStore:
|
|
99
|
+
createSaveErrorVariantsStore: N
|
|
101
100
|
});
|
|
102
101
|
};
|
|
103
102
|
};
|