@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.
@@ -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 r in e)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const u=m(S),o=m(O);async function T(e){const t=await o.promises.stat(e).catch(()=>null);if(t==null)return[];if(!t.isDirectory())throw new Error(`[saveErrorVariants] path is not a directory: ${e}`);return(await o.promises.readdir(e)).filter(n=>n.endsWith(".json")).sort((n,i)=>n>i?-1:n<i?1:0).map(n=>u.join(e,n))}async function P(e,t){const r=await o.promises.readFile(e,"utf-8");let s;try{s=JSON.parse(r)}catch{throw new Error(`[saveErrorVariants] invalid JSON in file: ${e}`)}if(t)try{return t(s)}catch{throw new Error(`[saveErrorVariants] jsonToArgs failed for file: ${e}`)}return s}function b(e){const t=Math.random().toString(36).substring(2);return d.formatDateFileName(e.sessionDate,"UTC")+"_"+t+".json"}async function A(e,t,r){let s;if(r){const n=r(e);typeof n=="string"?s=n:s=JSON.stringify(n,null,2)}else s=JSON.stringify(e,null,2);await o.promises.mkdir(u.dirname(t),{recursive:!0}),await o.promises.writeFile(t,s,"utf-8")}class q{options;filePath;lastSavedArgs=null;constructor(t){this.options=t;const r=new Date;this.filePath=u.resolve(t.dir,t.getFilePath?.({sessionDate:r})??b({sessionDate:r}))}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:r,variantsIterator:s,testOptions:n,findBestErrorEnabled:i}=t,c=this.options.useToFindBestError,g=this.options.limitArg??!1,y=this.options.extendTemplates??!1,w=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 P(V,this.options.jsonToArgs);for(let h=0;h<w;h++)try{const a=r(p,0,n);j.isPromiseLike(a)&&await a}catch(a){if(c&&i){s.addLimit({args:p,error:a,limitArg:g,extendTemplates:y});break}else throw a}}}}function D(e){return new q(e)}function N(e){const t=v.createTestVariants(e);return function(s){const n=t(s);return function(c){return n({...c,createSaveErrorVariantsStore:D})}}}exports.createTestVariants=N;
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;
@@ -1,19 +1,19 @@
1
- import { c as V } from "../createTestVariants-BE_TQ9u5.mjs";
1
+ import { c as y } from "../createTestVariants-BE_TQ9u5.mjs";
2
2
  import * as f from "path";
3
- import { isPromiseLike as g } from "@flemist/async-utils";
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 o from "fs";
6
+ import * as a from "fs";
7
7
  async function A(r) {
8
- const t = await o.promises.stat(r).catch(() => null);
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 o.promises.readdir(r)).filter((e) => e.endsWith(".json")).sort((e, n) => e > n ? -1 : e < n ? 1 : 0).map((e) => f.join(r, e));
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 o.promises.readFile(r, "utf-8");
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 o.promises.mkdir(f.dirname(t), { recursive: !0 }), await o.promises.writeFile(t, s, "utf-8");
44
+ await a.promises.mkdir(f.dirname(t), { recursive: !0 }), await a.promises.writeFile(t, s, "utf-8");
45
45
  }
46
- class N {
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, m = this.options.limitArg ?? !1, d = this.options.extendTemplates ?? !1, w = this.options.attemptsPerVariant ?? 1, u = await A(this.options.dir);
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 y = u[c], h = await P(
68
- y,
67
+ const g = u[c], m = await P(
68
+ g,
69
69
  this.options.jsonToArgs
70
70
  );
71
- for (let p = 0; p < w; p++)
71
+ for (let h = 0; h < w; h++)
72
72
  try {
73
- const a = i(h, 0, e);
74
- g(a) && await a;
75
- } catch (a) {
76
- if (l && n) {
77
- s.addLimit({
78
- args: h,
79
- error: a,
80
- limitArg: m,
81
- extendTemplates: d
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 O(r) {
91
- return new N(r);
89
+ function N(r) {
90
+ return new L(r);
92
91
  }
93
92
  function x(r) {
94
- const t = V(r);
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: O
99
+ createSaveErrorVariantsStore: N
101
100
  });
102
101
  };
103
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "5.0.1",
3
+ "version": "5.0.2",
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",