@flemist/test-variants 0.0.14 → 0.0.15

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,76 +1,78 @@
1
1
  !function(e){"use strict";function n(e,n,t,r){
2
- return new(t||(t=Promise))((function(o,u){
3
- function a(e){try{c(r.next(e))}catch(e){u(e)}}
4
- function i(e){try{c(r.throw(e))}catch(e){u(e)}}
2
+ return new(t||(t=Promise))((function(o,a){
3
+ function i(e){try{c(r.next(e))}catch(e){a(e)}}
4
+ function u(e){try{c(r.throw(e))}catch(e){a(e)}}
5
5
  function c(e){var n
6
6
  ;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){
7
- e(n)}))).then(a,i)}c((r=r.apply(e,n||[])).next())
8
- }))}function t(e,n){var t,r,o,u,a={label:0,
7
+ e(n)}))).then(i,u)}c((r=r.apply(e,n||[])).next())
8
+ }))}function t(e,n){var t,r,o,a,i={label:0,
9
9
  sent:function(){if(1&o[0])throw o[1];return o[1]},
10
- trys:[],ops:[]};return u={next:i(0),throw:i(1),
11
- return:i(2)
12
- },"function"==typeof Symbol&&(u[Symbol.iterator]=function(){
13
- return this}),u;function i(u){return function(i){
14
- return function(u){
10
+ trys:[],ops:[]};return a={next:u(0),throw:u(1),
11
+ return:u(2)
12
+ },"function"==typeof Symbol&&(a[Symbol.iterator]=function(){
13
+ return this}),a;function u(a){return function(u){
14
+ return function(a){
15
15
  if(t)throw new TypeError("Generator is already executing.")
16
- ;for(;a;)try{
17
- if(t=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),
18
- 0):r.next)&&!(o=o.call(r,u[1])).done)return o
19
- ;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:
20
- case 1:o=u;break;case 4:return a.label++,{
21
- value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0]
22
- ;continue;case 7:u=a.ops.pop(),a.trys.pop()
16
+ ;for(;i;)try{
17
+ if(t=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),
18
+ 0):r.next)&&!(o=o.call(r,a[1])).done)return o
19
+ ;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:
20
+ case 1:o=a;break;case 4:return i.label++,{
21
+ value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0]
22
+ ;continue;case 7:a=i.ops.pop(),i.trys.pop()
23
23
  ;continue;default:
24
- if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){
25
- a=0;continue}
26
- if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){
27
- a.label=u[1];break}if(6===u[0]&&a.label<o[1]){
28
- a.label=o[1],o=u;break}if(o&&a.label<o[2]){
29
- a.label=o[2],a.ops.push(u);break}
30
- o[2]&&a.ops.pop(),a.trys.pop();continue}
31
- u=n.call(e,a)}catch(e){u=[6,e],r=0}finally{t=o=0}
32
- if(5&u[0])throw u[1];return{
33
- value:u[0]?u[1]:void 0,done:!0}}([u,i])}}}
24
+ if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){
25
+ i=0;continue}
26
+ if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){
27
+ i.label=a[1];break}if(6===a[0]&&i.label<o[1]){
28
+ i.label=o[1],o=a;break}if(o&&i.label<o[2]){
29
+ i.label=o[2],i.ops.push(a);break}
30
+ o[2]&&i.ops.pop(),i.trys.pop();continue}
31
+ a=n.call(e,i)}catch(e){a=[6,e],r=0}finally{t=o=0}
32
+ if(5&a[0])throw a[1];return{
33
+ value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}
34
34
  function r(e){
35
35
  if(null==e||e<=0)throw new Error("Iterations = ".concat(e))
36
36
  ;e--;var n=new Promise((function(n){
37
37
  setTimeout((function(){n(e)}),1)}))
38
38
  ;return e<=0?n:n.then(r)}
39
39
  e.createTestVariants=function(e){
40
- return function(o){return function(u){
41
- var a=void 0===u?{}:u,i=a.GC_Iterations,c=void 0===i?1e6:i,s=a.GC_IterationsAsync,l=void 0===s?1e4:s,f=a.GC_Interval,v=void 0===f?1e3:f,h=a.logInterval,b=void 0===h?5e3:h,p=a.logCompleted,y=void 0===p||p,d=Object.keys(o),w=Object.values(o),g=d.length,m={}
42
- ;function I(e){var n=w[e]
43
- ;return"function"==typeof n&&(n=n(m)),n}
44
- for(var k=[],x=[],D=0;D<g;D++)k[D]=-1,x[D]=[]
45
- ;x[0]=I(0);var G=0,O=0,T=!1,_=0;function j(e){
40
+ return function(o){return function(a){
41
+ var i=void 0===a?{}:a,u=i.GC_Iterations,c=void 0===u?1e6:u,l=i.GC_IterationsAsync,s=void 0===l?1e4:l,f=i.GC_Interval,v=void 0===f?1e3:f,h=i.logInterval,b=void 0===h?5e3:h,p=i.logCompleted,y=void 0===p||p,d=i.onError,w=void 0===d?null:d,g=Object.keys(o),m=Object.values(o),I=g.length,k={}
42
+ ;function x(e){var n=m[e]
43
+ ;return"function"==typeof n&&(n=n(k)),n}
44
+ for(var D=[],E=[],G=0;G<I;G++)D[G]=-1,E[G]=[]
45
+ ;E[0]=x(0);var O=0,T=0,_=!1,j=0;function C(e){
46
46
  return n(this,void 0,void 0,(function(){var n
47
47
  ;return t(this,(function(t){switch(t.label){
48
48
  case 0:
49
- return console.error(JSON.stringify(m,null,2)),console.error(e),n=Date.now(),
50
- Date.now()-n>50&&_<5?(console.log("DEBUG ITERATION: "+_),
51
- T=!0,[4,A()]):[3,2];case 1:t.sent(),_++,t.label=2
52
- ;case 2:throw e}}))}))}
53
- var C=Date.now(),E=C,P=G,S=O;function A(){
49
+ return console.error("error variant: ".concat(O,"\r\n").concat(JSON.stringify(k,null,2))),
50
+ console.error(e),
51
+ n=Date.now(),Date.now()-n>50&&j<5?(console.log("DEBUG ITERATION: "+j),
52
+ _=!0,[4,B()]):[3,2];case 1:t.sent(),j++,t.label=2
53
+ ;case 2:throw w&&w({iteration:O,variant:k,error:e
54
+ }),e}}))}))}var P=Date.now(),S=P,A=O,N=T
55
+ ;function B(){
54
56
  return n(this,void 0,void 0,(function(){
55
- var n,o,u,a;return t(this,(function(t){
57
+ var n,o,a,i;return t(this,(function(t){
56
58
  switch(t.label){case 0:
57
59
  t.trys.push([0,7,,9]),t.label=1;case 1:
58
- return T||function(){for(var e=g-1;e>=0;e--){
59
- var n=k[e]+1;if(n<x[e].length){
60
- for(k[e]=n,m[d[e]]=x[e][n],e++;e<g;e++){var t=I(e)
61
- ;if(0===t.length)break;k[e]=0,x[e]=t,m[d[e]]=t[0]}
62
- if(e>=g)return!0}}return!1
63
- }()?(n=(b||v)&&Date.now(),b&&n-C>=b&&(console.log(G),C=n),
64
- c&&G-P>=c||l&&O-S>=l||v&&n-E>=v?(P=G,
65
- S=O,E=n,[4,r(1)]):[3,3]):[3,6];case 2:
60
+ return _||function(){for(var e=I-1;e>=0;e--){
61
+ var n=D[e]+1;if(n<E[e].length){
62
+ for(D[e]=n,k[g[e]]=E[e][n],e++;e<I;e++){var t=x(e)
63
+ ;if(0===t.length)break;D[e]=0,E[e]=t,k[g[e]]=t[0]}
64
+ if(e>=I)return!0}}return!1
65
+ }()?(n=(b||v)&&Date.now(),b&&n-P>=b&&(console.log(O),P=n),
66
+ c&&O-A>=c||s&&T-N>=s||v&&n-S>=v?(A=O,
67
+ N=T,S=n,[4,r(1)]):[3,3]):[3,6];case 2:
66
68
  return t.sent(),[3,1];case 3:
67
- return"object"==typeof(o=e(m))&&o&&"function"==typeof o.then?[4,o]:[3,5]
69
+ return"object"==typeof(o=e(k))&&o&&"function"==typeof o.then?[4,o]:[3,5]
68
70
  ;case 4:
69
- return u=t.sent(),O+=a="number"==typeof u?u:1,G+=a,[3,1]
70
- ;case 5:return G+="number"==typeof o?o:1,[3,1]
71
- ;case 6:return[3,9];case 7:return[4,j(t.sent())]
71
+ return a=t.sent(),T+=i="number"==typeof a?a:1,O+=i,[3,1]
72
+ ;case 5:return O+="number"==typeof o?o:1,[3,1]
73
+ ;case 6:return[3,9];case 7:return[4,C(t.sent())]
72
74
  ;case 8:return t.sent(),[3,9];case 9:
73
- return y&&console.log("variants: "+G),[4,r(1)]
74
- ;case 10:return t.sent(),[2,G]}}))}))}return A()}}
75
+ return y&&console.log("variants: "+O),[4,r(1)]
76
+ ;case 10:return t.sent(),[2,O]}}))}))}return B()}}
75
77
  },Object.defineProperty(e,"__esModule",{value:!0})
76
78
  }({});
@@ -8,7 +8,7 @@ var garbageCollect_garbageCollect = require('../garbage-collect/garbageCollect.c
8
8
  /* eslint-disable @typescript-eslint/no-shadow */
9
9
  function createTestVariants(test) {
10
10
  return function testVariantsArgs(args) {
11
- return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, } = {}) {
11
+ return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, onError: onErrorCallback = null, } = {}) {
12
12
  const argsKeys = Object.keys(args);
13
13
  const argsValues = Object.values(args);
14
14
  const argsLength = argsKeys.length;
@@ -53,10 +53,10 @@ function createTestVariants(test) {
53
53
  let iterationsAsync = 0;
54
54
  let debug = false;
55
55
  let debugIteration = 0;
56
- function onError(err) {
56
+ function onError(error) {
57
57
  return tslib.__awaiter(this, void 0, void 0, function* () {
58
- console.error(JSON.stringify(variantArgs, null, 2));
59
- console.error(err);
58
+ console.error(`error variant: ${iterations}\r\n${JSON.stringify(variantArgs, null, 2)}`);
59
+ console.error(error);
60
60
  // rerun failed variant 5 times for debug
61
61
  const time0 = Date.now();
62
62
  // eslint-disable-next-line no-debugger
@@ -67,7 +67,14 @@ function createTestVariants(test) {
67
67
  yield next();
68
68
  debugIteration++;
69
69
  }
70
- throw err;
70
+ if (onErrorCallback) {
71
+ onErrorCallback({
72
+ iteration: iterations,
73
+ variant: variantArgs,
74
+ error,
75
+ });
76
+ }
77
+ throw error;
71
78
  });
72
79
  }
73
80
  function onCompleted() {
@@ -2,11 +2,11 @@ declare type VariantsArgs<TArgs> = {
2
2
  [key in keyof TArgs]: TArgs[key][] | ((args: TArgs) => TArgs[key][]);
3
3
  };
4
4
  declare type PromiseOrValue<T> = Promise<T> | T;
5
- declare type TestVariantsCall = (callParams?: TestVariantsCallParams) => PromiseOrValue<number>;
5
+ declare type TestVariantsCall<TArgs> = (callParams?: TestVariantsCallParams<TArgs>) => PromiseOrValue<number>;
6
6
  declare type TestVariantsSetArgs<TArgs> = <TAdditionalArgs>(args: VariantsArgs<{
7
7
  [key in (keyof TAdditionalArgs | keyof TArgs)]: key extends keyof TArgs ? TArgs[key] : key extends keyof TAdditionalArgs ? TAdditionalArgs[key] : never;
8
- }>) => TestVariantsCall;
9
- export declare type TestVariantsCallParams = {
8
+ }>) => TestVariantsCall<TArgs>;
9
+ export declare type TestVariantsCallParams<TArgs> = {
10
10
  /** Wait for garbage collection after iterations */
11
11
  GC_Iterations?: number;
12
12
  /** Same as GC_Iterations but only for async test variants, required for 10000 and more of Promise rejections */
@@ -17,6 +17,11 @@ export declare type TestVariantsCallParams = {
17
17
  logInterval?: number;
18
18
  /** console log iterations on test completed */
19
19
  logCompleted?: boolean;
20
+ onError?: (event: {
21
+ iteration: number;
22
+ variant: TArgs;
23
+ error: any;
24
+ }) => void;
20
25
  };
21
26
  export declare function createTestVariants<TArgs extends object>(test: (args: TArgs) => Promise<number | void> | number | void): TestVariantsSetArgs<TArgs>;
22
27
  export {};
@@ -4,7 +4,7 @@ import { garbageCollect } from '../garbage-collect/garbageCollect.mjs';
4
4
  /* eslint-disable @typescript-eslint/no-shadow */
5
5
  function createTestVariants(test) {
6
6
  return function testVariantsArgs(args) {
7
- return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, } = {}) {
7
+ return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, onError: onErrorCallback = null, } = {}) {
8
8
  const argsKeys = Object.keys(args);
9
9
  const argsValues = Object.values(args);
10
10
  const argsLength = argsKeys.length;
@@ -49,10 +49,10 @@ function createTestVariants(test) {
49
49
  let iterationsAsync = 0;
50
50
  let debug = false;
51
51
  let debugIteration = 0;
52
- function onError(err) {
52
+ function onError(error) {
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
- console.error(JSON.stringify(variantArgs, null, 2));
55
- console.error(err);
54
+ console.error(`error variant: ${iterations}\r\n${JSON.stringify(variantArgs, null, 2)}`);
55
+ console.error(error);
56
56
  // rerun failed variant 5 times for debug
57
57
  const time0 = Date.now();
58
58
  // eslint-disable-next-line no-debugger
@@ -63,7 +63,14 @@ function createTestVariants(test) {
63
63
  yield next();
64
64
  debugIteration++;
65
65
  }
66
- throw err;
66
+ if (onErrorCallback) {
67
+ onErrorCallback({
68
+ iteration: iterations,
69
+ variant: variantArgs,
70
+ error,
71
+ });
72
+ }
73
+ throw error;
67
74
  });
68
75
  }
69
76
  function onCompleted() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Runs a test function with all possible combinations of its parameters.",
5
5
  "main": "dist/lib/index.cjs",
6
6
  "module": "dist/lib/index.mjs",
@@ -41,7 +41,7 @@
41
41
  "@babel/runtime-corejs3": "7.18.3",
42
42
  "@flemist/copy-glob-flat": "0.0.5",
43
43
  "@flemist/karma-custom-launcher": "0.0.0",
44
- "@flemist/test-utils": "0.0.5",
44
+ "@flemist/test-utils": "0.0.7",
45
45
  "@rollup/plugin-alias": "3.1.9",
46
46
  "@rollup/plugin-babel": "5.3.1",
47
47
  "@rollup/plugin-commonjs": "=21.1.0",
@@ -55,7 +55,8 @@
55
55
  "@types/fs-extra": "9.0.13",
56
56
  "@types/mocha": "9.1.1",
57
57
  "@types/node": "18.0.0",
58
- "cpy-cli": "3.1.1",
58
+ "@zerollup/ts-transform-paths": "1.7.18",
59
+ "cpy-cli": "=3.1.1",
59
60
  "eslint": "8.18.0",
60
61
  "eslint-config-pro": "3.0.14",
61
62
  "fs-extra": "10.1.0",
@@ -90,8 +91,7 @@
90
91
  "lint:fix": "eslint --fix ./**/*.{js,cjs,mjs,ts,tsx}",
91
92
  "lint:wizard": "eslint-nibble --cache --multi ./**/*.{js,cjs,mjs,ts,tsx}",
92
93
  "build:js": "rimraf dist/lib && cpy \"**/assets/**\" \"../dist/lib/\" --parents --cwd=src && rollup -c",
93
- "build:types": "tsc --outDir dist/lib --declaration",
94
- "build": "rimraf dist && pnpm run build:js && pnpm run build:types",
94
+ "build": "rimraf dist && pnpm run build:js",
95
95
  "coverage:merge": "rimraf tmp/coverage/{all,merge} && cp-flat \"tmp/coverage/*/json/**/*.json\" \"tmp/coverage/merge\" && nyc report -r lcov --report-dir tmp/coverage/all/lcov --temp-dir \"tmp/coverage/merge/\"",
96
96
  "coverage:check": "pnpm run coverage:merge && nyc check-coverage --report-dir tmp/coverage/all/lcov --lines 50 --functions 50 --branches 50 --statements 50",
97
97
  "test:mocha": "mocha ./src/**/*.test.*",