@flemist/test-variants 0.0.11 → 0.0.14

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,33 +1,76 @@
1
- !function(e){"use strict"
2
- ;e.createTestVariants=function(e){
3
- return function(n){return function(t){
4
- var o=void 0===t?{}:t,r=o.pauseInterval,u=void 0===r?1e3:r,a=o.pauseTime,i=void 0===a?10:a,f=o.logInterval,c=void 0===f?1e4:f,v=o.logCompleted,l=void 0===v||v,s=Object.keys(n),p=Object.values(n),y=s.length,g={}
5
- ;function h(e){var n=p[e]
6
- ;return"function"==typeof n&&(n=n(g)),n}
7
- for(var b=[],d=[],m=0;m<y;m++)b[m]=-1,d[m]=[]
8
- ;function w(){for(var e=y-1;e>=0;e--){var n=b[e]+1
9
- ;if(n<d[e].length){
10
- for(b[e]=n,g[s[e]]=d[e][n],e++;e<y;e++){var t=h(e)
11
- ;if(0===t.length)break;b[e]=0,d[e]=t,g[s[e]]=t[0]}
12
- if(e>=y)return!0}}return!1}d[0]=h(0)
13
- ;var D=0,j=!1,O=0;function T(e){
14
- console.error(JSON.stringify(g,null,2)),console.error(e)
15
- ;var n=Date.now()
16
- ;throw Date.now()-n>50&&O<5&&(console.log("DEBUG ITERATION: "+O),
17
- j=!0,P(0),O++),e}var I=Date.now();function P(n){
18
- var t=(c||u)&&Date.now()
19
- ;t&&t-I>=c&&(console.log(D),I=t),D+="number"==typeof n?n:1
20
- ;for(var o=u&&t,r=function(){try{var n=e(g)
21
- ;if("object"==typeof n&&n&&"function"==typeof n.then)return{
22
- value:n.catch(T).then(P)}
23
- ;if(o&&Date.now()-o>=u)return{
24
- value:(i?new Promise((function(e){
25
- setTimeout((function(){e(n)}),i)
26
- })):Promise.resolve(n)).then(P)}
27
- ;D+="number"==typeof n?n:1}catch(e){T(e)}
28
- };j||w();){var a=r()
29
- ;if("object"==typeof a)return a.value}
30
- return l&&console.log("variants: "+D),D}
31
- return P(0)}}
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)}}
5
+ function c(e){var n
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,
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){
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()
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])}}}
34
+ function r(e){
35
+ if(null==e||e<=0)throw new Error("Iterations = ".concat(e))
36
+ ;e--;var n=new Promise((function(n){
37
+ setTimeout((function(){n(e)}),1)}))
38
+ ;return e<=0?n:n.then(r)}
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){
46
+ return n(this,void 0,void 0,(function(){var n
47
+ ;return t(this,(function(t){switch(t.label){
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(){
54
+ return n(this,void 0,void 0,(function(){
55
+ var n,o,u,a;return t(this,(function(t){
56
+ switch(t.label){case 0:
57
+ 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:
66
+ return t.sent(),[3,1];case 3:
67
+ return"object"==typeof(o=e(m))&&o&&"function"==typeof o.then?[4,o]:[3,5]
68
+ ;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())]
72
+ ;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()}}
32
75
  },Object.defineProperty(e,"__esModule",{value:!0})
33
76
  }({});
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /** Wait for garbage collection and return 0. It may be required for very long calculations. */
6
+ function garbageCollect(iterations) {
7
+ if (iterations == null || iterations <= 0) {
8
+ throw new Error(`Iterations = ${iterations}`);
9
+ }
10
+ iterations--;
11
+ // const time0 = Date.now()
12
+ const promise = new Promise(resolve => {
13
+ setTimeout(() => {
14
+ resolve(iterations);
15
+ }, 1);
16
+ });
17
+ return iterations <= 0
18
+ ? promise
19
+ : promise.then(garbageCollect);
20
+ // : promise.then(o => {
21
+ // const gcTime = Date.now() - time0
22
+ // if (gcTime > 50) {
23
+ // console.log('GC time: ' + gcTime)
24
+ // o++
25
+ // }
26
+ // return garbageCollect(o)
27
+ // })
28
+ }
29
+
30
+ exports.garbageCollect = garbageCollect;
@@ -0,0 +1,2 @@
1
+ /** Wait for garbage collection and return 0. It may be required for very long calculations. */
2
+ export declare function garbageCollect(iterations: number): Promise<0>;
@@ -0,0 +1,26 @@
1
+ /** Wait for garbage collection and return 0. It may be required for very long calculations. */
2
+ function garbageCollect(iterations) {
3
+ if (iterations == null || iterations <= 0) {
4
+ throw new Error(`Iterations = ${iterations}`);
5
+ }
6
+ iterations--;
7
+ // const time0 = Date.now()
8
+ const promise = new Promise(resolve => {
9
+ setTimeout(() => {
10
+ resolve(iterations);
11
+ }, 1);
12
+ });
13
+ return iterations <= 0
14
+ ? promise
15
+ : promise.then(garbageCollect);
16
+ // : promise.then(o => {
17
+ // const gcTime = Date.now() - time0
18
+ // if (gcTime > 50) {
19
+ // console.log('GC time: ' + gcTime)
20
+ // o++
21
+ // }
22
+ // return garbageCollect(o)
23
+ // })
24
+ }
25
+
26
+ export { garbageCollect };
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var testVariants_createTestVariants = require('./test-variants/createTestVariants.cjs');
6
+ require('tslib');
7
+ require('./garbage-collect/garbageCollect.cjs');
6
8
 
7
9
 
8
10
 
@@ -1 +1,3 @@
1
1
  export { createTestVariants } from './test-variants/createTestVariants.mjs';
2
+ import 'tslib';
3
+ import './garbage-collect/garbageCollect.mjs';
@@ -2,10 +2,13 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tslib = require('tslib');
6
+ var garbageCollect_garbageCollect = require('../garbage-collect/garbageCollect.cjs');
7
+
5
8
  /* eslint-disable @typescript-eslint/no-shadow */
6
9
  function createTestVariants(test) {
7
10
  return function testVariantsArgs(args) {
8
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
11
+ return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, } = {}) {
9
12
  const argsKeys = Object.keys(args);
10
13
  const argsValues = Object.values(args);
11
14
  const argsLength = argsKeys.length;
@@ -47,22 +50,25 @@ function createTestVariants(test) {
47
50
  return false;
48
51
  }
49
52
  let iterations = 0;
53
+ let iterationsAsync = 0;
50
54
  let debug = false;
51
55
  let debugIteration = 0;
52
56
  function onError(err) {
53
- console.error(JSON.stringify(variantArgs, null, 2));
54
- console.error(err); // required to show intelliJ idea assertion difference
55
- // rerun failed variant 5 times for debug
56
- const time0 = Date.now();
57
- // eslint-disable-next-line no-debugger
58
- debugger;
59
- if (Date.now() - time0 > 50 && debugIteration < 5) {
60
- console.log('DEBUG ITERATION: ' + debugIteration);
61
- debug = true;
62
- next(0);
63
- debugIteration++;
64
- }
65
- throw err;
57
+ return tslib.__awaiter(this, void 0, void 0, function* () {
58
+ console.error(JSON.stringify(variantArgs, null, 2));
59
+ console.error(err);
60
+ // rerun failed variant 5 times for debug
61
+ const time0 = Date.now();
62
+ // eslint-disable-next-line no-debugger
63
+ debugger;
64
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
65
+ console.log('DEBUG ITERATION: ' + debugIteration);
66
+ debug = true;
67
+ yield next();
68
+ debugIteration++;
69
+ }
70
+ throw err;
71
+ });
66
72
  }
67
73
  function onCompleted() {
68
74
  if (logCompleted) {
@@ -70,45 +76,50 @@ function createTestVariants(test) {
70
76
  }
71
77
  }
72
78
  let prevLogTime = Date.now();
73
- function next(value) {
74
- const now = (logInterval || pauseInterval) && Date.now();
75
- if (now) {
76
- if (now - prevLogTime >= logInterval) {
77
- // the log is required to prevent the karma browserNoActivityTimeout
78
- console.log(iterations);
79
- prevLogTime = now;
80
- }
81
- }
82
- iterations += typeof value === 'number' ? value : 1;
83
- const syncCallStartTime = pauseInterval && now;
84
- while (debug || nextVariant()) {
79
+ let prevGC_Time = prevLogTime;
80
+ let prevGC_Iterations = iterations;
81
+ let prevGC_IterationsAsync = iterationsAsync;
82
+ function next() {
83
+ return tslib.__awaiter(this, void 0, void 0, function* () {
85
84
  try {
86
- const promiseOrIterations = test(variantArgs);
87
- if (typeof promiseOrIterations === 'object'
88
- && promiseOrIterations
89
- && typeof promiseOrIterations.then === 'function') {
90
- return promiseOrIterations.catch(onError).then(next);
91
- }
92
- if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
93
- const pausePromise = pauseTime
94
- ? new Promise(resolve => {
95
- setTimeout(() => {
96
- resolve(promiseOrIterations);
97
- }, pauseTime);
98
- })
99
- : Promise.resolve(promiseOrIterations);
100
- return pausePromise.then(next);
85
+ while (debug || nextVariant()) {
86
+ const now = (logInterval || GC_Interval) && Date.now();
87
+ if (logInterval && now - prevLogTime >= logInterval) {
88
+ // the log is required to prevent the karma browserNoActivityTimeout
89
+ console.log(iterations);
90
+ prevLogTime = now;
91
+ }
92
+ if (GC_Iterations && iterations - prevGC_Iterations >= GC_Iterations
93
+ || GC_IterationsAsync && iterationsAsync - prevGC_IterationsAsync >= GC_IterationsAsync
94
+ || GC_Interval && now - prevGC_Time >= GC_Interval) {
95
+ prevGC_Iterations = iterations;
96
+ prevGC_IterationsAsync = iterationsAsync;
97
+ prevGC_Time = now;
98
+ yield garbageCollect_garbageCollect.garbageCollect(1);
99
+ continue;
100
+ }
101
+ const promiseOrIterations = test(variantArgs);
102
+ if (typeof promiseOrIterations === 'object'
103
+ && promiseOrIterations
104
+ && typeof promiseOrIterations.then === 'function') {
105
+ const value = yield promiseOrIterations;
106
+ const newIterations = typeof value === 'number' ? value : 1;
107
+ iterationsAsync += newIterations;
108
+ iterations += newIterations;
109
+ continue;
110
+ }
111
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
101
112
  }
102
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
103
113
  }
104
114
  catch (err) {
105
- onError(err);
115
+ yield onError(err);
106
116
  }
107
- }
108
- onCompleted();
109
- return iterations;
117
+ onCompleted();
118
+ yield garbageCollect_garbageCollect.garbageCollect(1);
119
+ return iterations;
120
+ });
110
121
  }
111
- return next(0);
122
+ return next();
112
123
  };
113
124
  };
114
125
  }
@@ -7,9 +7,12 @@ 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
8
  }>) => TestVariantsCall;
9
9
  export declare type TestVariantsCallParams = {
10
- /** pause test, required to prevent the karma browserDisconnectTimeout */
11
- pauseInterval?: number;
12
- pauseTime?: number;
10
+ /** Wait for garbage collection after iterations */
11
+ GC_Iterations?: number;
12
+ /** Same as GC_Iterations but only for async test variants, required for 10000 and more of Promise rejections */
13
+ GC_IterationsAsync?: number;
14
+ /** Wait for garbage collection after time interval, required to prevent the karma browserDisconnectTimeout */
15
+ GC_Interval?: number;
13
16
  /** console log current iterations, required to prevent the karma browserNoActivityTimeout */
14
17
  logInterval?: number;
15
18
  /** console log iterations on test completed */
@@ -1,7 +1,10 @@
1
+ import { __awaiter } from 'tslib';
2
+ import { garbageCollect } from '../garbage-collect/garbageCollect.mjs';
3
+
1
4
  /* eslint-disable @typescript-eslint/no-shadow */
2
5
  function createTestVariants(test) {
3
6
  return function testVariantsArgs(args) {
4
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
7
+ return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, } = {}) {
5
8
  const argsKeys = Object.keys(args);
6
9
  const argsValues = Object.values(args);
7
10
  const argsLength = argsKeys.length;
@@ -43,22 +46,25 @@ function createTestVariants(test) {
43
46
  return false;
44
47
  }
45
48
  let iterations = 0;
49
+ let iterationsAsync = 0;
46
50
  let debug = false;
47
51
  let debugIteration = 0;
48
52
  function onError(err) {
49
- console.error(JSON.stringify(variantArgs, null, 2));
50
- console.error(err); // required to show intelliJ idea assertion difference
51
- // rerun failed variant 5 times for debug
52
- const time0 = Date.now();
53
- // eslint-disable-next-line no-debugger
54
- debugger;
55
- if (Date.now() - time0 > 50 && debugIteration < 5) {
56
- console.log('DEBUG ITERATION: ' + debugIteration);
57
- debug = true;
58
- next(0);
59
- debugIteration++;
60
- }
61
- throw err;
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ console.error(JSON.stringify(variantArgs, null, 2));
55
+ console.error(err);
56
+ // rerun failed variant 5 times for debug
57
+ const time0 = Date.now();
58
+ // eslint-disable-next-line no-debugger
59
+ debugger;
60
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
61
+ console.log('DEBUG ITERATION: ' + debugIteration);
62
+ debug = true;
63
+ yield next();
64
+ debugIteration++;
65
+ }
66
+ throw err;
67
+ });
62
68
  }
63
69
  function onCompleted() {
64
70
  if (logCompleted) {
@@ -66,45 +72,50 @@ function createTestVariants(test) {
66
72
  }
67
73
  }
68
74
  let prevLogTime = Date.now();
69
- function next(value) {
70
- const now = (logInterval || pauseInterval) && Date.now();
71
- if (now) {
72
- if (now - prevLogTime >= logInterval) {
73
- // the log is required to prevent the karma browserNoActivityTimeout
74
- console.log(iterations);
75
- prevLogTime = now;
76
- }
77
- }
78
- iterations += typeof value === 'number' ? value : 1;
79
- const syncCallStartTime = pauseInterval && now;
80
- while (debug || nextVariant()) {
75
+ let prevGC_Time = prevLogTime;
76
+ let prevGC_Iterations = iterations;
77
+ let prevGC_IterationsAsync = iterationsAsync;
78
+ function next() {
79
+ return __awaiter(this, void 0, void 0, function* () {
81
80
  try {
82
- const promiseOrIterations = test(variantArgs);
83
- if (typeof promiseOrIterations === 'object'
84
- && promiseOrIterations
85
- && typeof promiseOrIterations.then === 'function') {
86
- return promiseOrIterations.catch(onError).then(next);
87
- }
88
- if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
89
- const pausePromise = pauseTime
90
- ? new Promise(resolve => {
91
- setTimeout(() => {
92
- resolve(promiseOrIterations);
93
- }, pauseTime);
94
- })
95
- : Promise.resolve(promiseOrIterations);
96
- return pausePromise.then(next);
81
+ while (debug || nextVariant()) {
82
+ const now = (logInterval || GC_Interval) && Date.now();
83
+ if (logInterval && now - prevLogTime >= logInterval) {
84
+ // the log is required to prevent the karma browserNoActivityTimeout
85
+ console.log(iterations);
86
+ prevLogTime = now;
87
+ }
88
+ if (GC_Iterations && iterations - prevGC_Iterations >= GC_Iterations
89
+ || GC_IterationsAsync && iterationsAsync - prevGC_IterationsAsync >= GC_IterationsAsync
90
+ || GC_Interval && now - prevGC_Time >= GC_Interval) {
91
+ prevGC_Iterations = iterations;
92
+ prevGC_IterationsAsync = iterationsAsync;
93
+ prevGC_Time = now;
94
+ yield garbageCollect(1);
95
+ continue;
96
+ }
97
+ const promiseOrIterations = test(variantArgs);
98
+ if (typeof promiseOrIterations === 'object'
99
+ && promiseOrIterations
100
+ && typeof promiseOrIterations.then === 'function') {
101
+ const value = yield promiseOrIterations;
102
+ const newIterations = typeof value === 'number' ? value : 1;
103
+ iterationsAsync += newIterations;
104
+ iterations += newIterations;
105
+ continue;
106
+ }
107
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
97
108
  }
98
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
99
109
  }
100
110
  catch (err) {
101
- onError(err);
111
+ yield onError(err);
102
112
  }
103
- }
104
- onCompleted();
105
- return iterations;
113
+ onCompleted();
114
+ yield garbageCollect(1);
115
+ return iterations;
116
+ });
106
117
  }
107
- return next(0);
118
+ return next();
108
119
  };
109
120
  };
110
121
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  var rdtsc = require('rdtsc');
4
4
  var testVariants_createTestVariants = require('./createTestVariants.cjs');
5
+ require('tslib');
6
+ require('../garbage-collect/garbageCollect.cjs');
5
7
 
6
8
  describe('test > testVariants perf', function () {
7
9
  this.timeout(300000);
@@ -1,5 +1,7 @@
1
1
  import { calcPerformance } from 'rdtsc';
2
2
  import { createTestVariants } from './createTestVariants.mjs';
3
+ import 'tslib';
4
+ import '../garbage-collect/garbageCollect.mjs';
3
5
 
4
6
  describe('test > testVariants perf', function () {
5
7
  this.timeout(300000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
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",