@flemist/test-variants 0.0.13 → 0.0.16
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/dist/bundle/browser.js +78 -31
- package/dist/lib/garbage-collect/garbageCollect.cjs +30 -0
- package/dist/lib/garbage-collect/garbageCollect.d.ts +2 -0
- package/dist/lib/garbage-collect/garbageCollect.mjs +26 -0
- package/dist/lib/index.cjs +2 -0
- package/dist/lib/index.mjs +2 -0
- package/dist/lib/test-variants/createTestVariants.cjs +69 -48
- package/dist/lib/test-variants/createTestVariants.d.ts +16 -6
- package/dist/lib/test-variants/createTestVariants.mjs +69 -48
- package/dist/lib/test-variants/createTestVariants.perf.cjs +2 -0
- package/dist/lib/test-variants/createTestVariants.perf.mjs +2 -0
- package/package.json +23 -21
package/dist/bundle/browser.js
CHANGED
|
@@ -1,33 +1,80 @@
|
|
|
1
|
-
!function(e){"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
;
|
|
20
|
-
|
|
21
|
-
;
|
|
22
|
-
|
|
23
|
-
;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
!function(e){"use strict";function n(e,n,t,r){
|
|
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
|
+
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(i,u)}c((r=r.apply(e,n||[])).next())
|
|
8
|
+
}))}function t(e,n){var t,r,o,a,i={label:0,
|
|
9
|
+
sent:function(){if(1&o[0])throw o[1];return o[1]},
|
|
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
|
+
if(t)throw new TypeError("Generator is already executing.")
|
|
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
|
+
;continue;default:
|
|
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
|
+
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(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,d=i.logCompleted,p=void 0===d||d,y=i.onError,w=void 0===y?null:y,g=i.abortSignal,m=Object.keys(o),I=Object.values(o),k=m.length,x={}
|
|
42
|
+
;function D(e){var n=I[e]
|
|
43
|
+
;return"function"==typeof n&&(n=n(x)),n}
|
|
44
|
+
for(var E=[],G=[],O=0;O<k;O++)E[O]=-1,G[O]=[]
|
|
45
|
+
;G[0]=D(0);var T=0,_=0,j=!1,C=0;function S(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("error variant: ".concat(T,"\r\n").concat(JSON.stringify(x,null,2))),
|
|
50
|
+
console.error(e),
|
|
51
|
+
n=Date.now(),Date.now()-n>50&&C<5?(console.log("DEBUG ITERATION: "+C),
|
|
52
|
+
j=!0,[4,J()]):[3,2];case 1:t.sent(),C++,t.label=2
|
|
53
|
+
;case 2:throw w&&w({iteration:T,variant:x,error:e
|
|
54
|
+
}),e}}))}))}var P=Date.now(),A=P,N=T,B=_
|
|
55
|
+
;function J(){
|
|
56
|
+
return n(this,void 0,void 0,(function(){
|
|
57
|
+
var n,o,a,i;return t(this,(function(t){
|
|
58
|
+
switch(t.label){case 0:
|
|
59
|
+
t.trys.push([0,7,,9]),t.label=1;case 1:
|
|
60
|
+
return(null==g?void 0:g.aborted)||!j&&!function(){
|
|
61
|
+
for(var e=k-1;e>=0;e--){var n=E[e]+1
|
|
62
|
+
;if(n<G[e].length){
|
|
63
|
+
for(E[e]=n,x[m[e]]=G[e][n],e++;e<k;e++){var t=D(e)
|
|
64
|
+
;if(0===t.length)break;E[e]=0,G[e]=t,x[m[e]]=t[0]}
|
|
65
|
+
if(e>=k)return!0}}return!1
|
|
66
|
+
}()?[3,6]:(n=(b||v)&&Date.now(),b&&n-P>=b&&(console.log(T),
|
|
67
|
+
P=n),c&&T-N>=c||s&&_-B>=s||v&&n-A>=v?(N=T,
|
|
68
|
+
B=_,A=n,[4,r(1)]):[3,3]);case 2:
|
|
69
|
+
return t.sent(),[3,1];case 3:
|
|
70
|
+
return"object"==typeof(o=e(x))&&o&&"function"==typeof o.then?[4,o]:[3,5]
|
|
71
|
+
;case 4:
|
|
72
|
+
return a=t.sent(),_+=i="number"==typeof a?a:1,T+=i,[3,1]
|
|
73
|
+
;case 5:return T+="number"==typeof o?o:1,[3,1]
|
|
74
|
+
;case 6:return[3,9];case 7:return[4,S(t.sent())]
|
|
75
|
+
;case 8:return t.sent(),[3,9];case 9:
|
|
76
|
+
if(null==g?void 0:g.aborted)throw g.reason
|
|
77
|
+
;return p&&console.log("variants: "+T),[4,r(1)]
|
|
78
|
+
;case 10:return t.sent(),[2,T]}}))}))}return J()}}
|
|
32
79
|
},Object.defineProperty(e,"__esModule",{value:!0})
|
|
33
80
|
}({});
|
|
@@ -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,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 };
|
package/dist/lib/index.cjs
CHANGED
package/dist/lib/index.mjs
CHANGED
|
@@ -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({
|
|
11
|
+
return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, onError: onErrorCallback = null, abortSignal, } = {}) {
|
|
9
12
|
const argsKeys = Object.keys(args);
|
|
10
13
|
const argsValues = Object.values(args);
|
|
11
14
|
const argsLength = argsKeys.length;
|
|
@@ -47,22 +50,32 @@ 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
|
-
function onError(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
function onError(error) {
|
|
57
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
console.error(`error variant: ${iterations}\r\n${JSON.stringify(variantArgs, null, 2)}`);
|
|
59
|
+
console.error(error);
|
|
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
|
+
if (onErrorCallback) {
|
|
71
|
+
onErrorCallback({
|
|
72
|
+
iteration: iterations,
|
|
73
|
+
variant: variantArgs,
|
|
74
|
+
error,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
throw error;
|
|
78
|
+
});
|
|
66
79
|
}
|
|
67
80
|
function onCompleted() {
|
|
68
81
|
if (logCompleted) {
|
|
@@ -70,45 +83,53 @@ function createTestVariants(test) {
|
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
let prevLogTime = Date.now();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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()) {
|
|
86
|
+
let prevGC_Time = prevLogTime;
|
|
87
|
+
let prevGC_Iterations = iterations;
|
|
88
|
+
let prevGC_IterationsAsync = iterationsAsync;
|
|
89
|
+
function next() {
|
|
90
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
91
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
&&
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
while (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) && (debug || nextVariant())) {
|
|
93
|
+
const now = (logInterval || GC_Interval) && Date.now();
|
|
94
|
+
if (logInterval && now - prevLogTime >= logInterval) {
|
|
95
|
+
// the log is required to prevent the karma browserNoActivityTimeout
|
|
96
|
+
console.log(iterations);
|
|
97
|
+
prevLogTime = now;
|
|
98
|
+
}
|
|
99
|
+
if (GC_Iterations && iterations - prevGC_Iterations >= GC_Iterations
|
|
100
|
+
|| GC_IterationsAsync && iterationsAsync - prevGC_IterationsAsync >= GC_IterationsAsync
|
|
101
|
+
|| GC_Interval && now - prevGC_Time >= GC_Interval) {
|
|
102
|
+
prevGC_Iterations = iterations;
|
|
103
|
+
prevGC_IterationsAsync = iterationsAsync;
|
|
104
|
+
prevGC_Time = now;
|
|
105
|
+
yield garbageCollect_garbageCollect.garbageCollect(1);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const promiseOrIterations = test(variantArgs);
|
|
109
|
+
if (typeof promiseOrIterations === 'object'
|
|
110
|
+
&& promiseOrIterations
|
|
111
|
+
&& typeof promiseOrIterations.then === 'function') {
|
|
112
|
+
const value = yield promiseOrIterations;
|
|
113
|
+
const newIterations = typeof value === 'number' ? value : 1;
|
|
114
|
+
iterationsAsync += newIterations;
|
|
115
|
+
iterations += newIterations;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
101
119
|
}
|
|
102
|
-
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
103
120
|
}
|
|
104
121
|
catch (err) {
|
|
105
|
-
onError(err);
|
|
122
|
+
yield onError(err);
|
|
106
123
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
124
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
125
|
+
throw abortSignal.reason;
|
|
126
|
+
}
|
|
127
|
+
onCompleted();
|
|
128
|
+
yield garbageCollect_garbageCollect.garbageCollect(1);
|
|
129
|
+
return iterations;
|
|
130
|
+
});
|
|
110
131
|
}
|
|
111
|
-
return next(
|
|
132
|
+
return next();
|
|
112
133
|
};
|
|
113
134
|
};
|
|
114
135
|
}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
import { IAbortSignalFast } from '@flemist/abort-controller-fast';
|
|
1
2
|
declare type VariantsArgs<TArgs> = {
|
|
2
3
|
[key in keyof TArgs]: TArgs[key][] | ((args: TArgs) => TArgs[key][]);
|
|
3
4
|
};
|
|
4
5
|
declare type PromiseOrValue<T> = Promise<T> | T;
|
|
5
|
-
declare type TestVariantsCall = (callParams?: TestVariantsCallParams) => PromiseOrValue<number>;
|
|
6
|
+
declare type TestVariantsCall<TArgs> = (callParams?: TestVariantsCallParams<TArgs>) => PromiseOrValue<number>;
|
|
6
7
|
declare type TestVariantsSetArgs<TArgs> = <TAdditionalArgs>(args: VariantsArgs<{
|
|
7
8
|
[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 = {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
}>) => TestVariantsCall<TArgs>;
|
|
10
|
+
export declare type TestVariantsCallParams<TArgs> = {
|
|
11
|
+
/** Wait for garbage collection after iterations */
|
|
12
|
+
GC_Iterations?: number;
|
|
13
|
+
/** Same as GC_Iterations but only for async test variants, required for 10000 and more of Promise rejections */
|
|
14
|
+
GC_IterationsAsync?: number;
|
|
15
|
+
/** Wait for garbage collection after time interval, required to prevent the karma browserDisconnectTimeout */
|
|
16
|
+
GC_Interval?: number;
|
|
13
17
|
/** console log current iterations, required to prevent the karma browserNoActivityTimeout */
|
|
14
18
|
logInterval?: number;
|
|
15
19
|
/** console log iterations on test completed */
|
|
16
20
|
logCompleted?: boolean;
|
|
21
|
+
onError?: (event: {
|
|
22
|
+
iteration: number;
|
|
23
|
+
variant: TArgs;
|
|
24
|
+
error: any;
|
|
25
|
+
}) => void;
|
|
26
|
+
abortSignal?: IAbortSignalFast;
|
|
17
27
|
};
|
|
18
28
|
export declare function createTestVariants<TArgs extends object>(test: (args: TArgs) => Promise<number | void> | number | void): TestVariantsSetArgs<TArgs>;
|
|
19
29
|
export {};
|
|
@@ -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({
|
|
7
|
+
return function testVariantsCall({ GC_Iterations = 1000000, GC_IterationsAsync = 10000, GC_Interval = 1000, logInterval = 5000, logCompleted = true, onError: onErrorCallback = null, abortSignal, } = {}) {
|
|
5
8
|
const argsKeys = Object.keys(args);
|
|
6
9
|
const argsValues = Object.values(args);
|
|
7
10
|
const argsLength = argsKeys.length;
|
|
@@ -43,22 +46,32 @@ 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
|
-
function onError(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
function onError(error) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
console.error(`error variant: ${iterations}\r\n${JSON.stringify(variantArgs, null, 2)}`);
|
|
55
|
+
console.error(error);
|
|
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
|
+
if (onErrorCallback) {
|
|
67
|
+
onErrorCallback({
|
|
68
|
+
iteration: iterations,
|
|
69
|
+
variant: variantArgs,
|
|
70
|
+
error,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
});
|
|
62
75
|
}
|
|
63
76
|
function onCompleted() {
|
|
64
77
|
if (logCompleted) {
|
|
@@ -66,45 +79,53 @@ function createTestVariants(test) {
|
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
let prevLogTime = Date.now();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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()) {
|
|
82
|
+
let prevGC_Time = prevLogTime;
|
|
83
|
+
let prevGC_Iterations = iterations;
|
|
84
|
+
let prevGC_IterationsAsync = iterationsAsync;
|
|
85
|
+
function next() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
87
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
&&
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
while (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) && (debug || nextVariant())) {
|
|
89
|
+
const now = (logInterval || GC_Interval) && Date.now();
|
|
90
|
+
if (logInterval && now - prevLogTime >= logInterval) {
|
|
91
|
+
// the log is required to prevent the karma browserNoActivityTimeout
|
|
92
|
+
console.log(iterations);
|
|
93
|
+
prevLogTime = now;
|
|
94
|
+
}
|
|
95
|
+
if (GC_Iterations && iterations - prevGC_Iterations >= GC_Iterations
|
|
96
|
+
|| GC_IterationsAsync && iterationsAsync - prevGC_IterationsAsync >= GC_IterationsAsync
|
|
97
|
+
|| GC_Interval && now - prevGC_Time >= GC_Interval) {
|
|
98
|
+
prevGC_Iterations = iterations;
|
|
99
|
+
prevGC_IterationsAsync = iterationsAsync;
|
|
100
|
+
prevGC_Time = now;
|
|
101
|
+
yield garbageCollect(1);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const promiseOrIterations = test(variantArgs);
|
|
105
|
+
if (typeof promiseOrIterations === 'object'
|
|
106
|
+
&& promiseOrIterations
|
|
107
|
+
&& typeof promiseOrIterations.then === 'function') {
|
|
108
|
+
const value = yield promiseOrIterations;
|
|
109
|
+
const newIterations = typeof value === 'number' ? value : 1;
|
|
110
|
+
iterationsAsync += newIterations;
|
|
111
|
+
iterations += newIterations;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
97
115
|
}
|
|
98
|
-
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
99
116
|
}
|
|
100
117
|
catch (err) {
|
|
101
|
-
onError(err);
|
|
118
|
+
yield onError(err);
|
|
102
119
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
121
|
+
throw abortSignal.reason;
|
|
122
|
+
}
|
|
123
|
+
onCompleted();
|
|
124
|
+
yield garbageCollect(1);
|
|
125
|
+
return iterations;
|
|
126
|
+
});
|
|
106
127
|
}
|
|
107
|
-
return next(
|
|
128
|
+
return next();
|
|
108
129
|
};
|
|
109
130
|
};
|
|
110
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flemist/test-variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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",
|
|
@@ -32,6 +32,23 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"_prepublishOnly": "pnpm run audit && pnpm run lint && pnpm run build && pnpm run test:mocha:ci && pnpm run test:karma",
|
|
37
|
+
"audit": "pnpm audit --prod",
|
|
38
|
+
"lint": "eslint ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
39
|
+
"lint:fix": "eslint --fix ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
40
|
+
"lint:wizard": "eslint-nibble --cache --multi ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
41
|
+
"build:js": "rimraf dist/lib && cpy \"**/assets/**\" \"../dist/lib/\" --parents --cwd=src && rollup -c",
|
|
42
|
+
"build": "rimraf dist && pnpm run build:js",
|
|
43
|
+
"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/\"",
|
|
44
|
+
"coverage:check": "pnpm run coverage:merge && nyc check-coverage --report-dir tmp/coverage/all/lcov --lines 50 --functions 50 --branches 50 --statements 50",
|
|
45
|
+
"test:mocha": "mocha ./src/**/*.test.*",
|
|
46
|
+
"test:mocha:coverage": "rimraf tmp/coverage/mocha && nyc --all mocha ./src/**/*.test.*",
|
|
47
|
+
"test:mocha:watch": "mocha --watch ./src/**/*.test.*",
|
|
48
|
+
"test:karma": "rimraf tmp/coverage/karma && karma start --single-run --log-level debug",
|
|
49
|
+
"test:mocha:ci": "rimraf tmp/coverage/mocha && nyc --all mocha ./{src,dist/lib}/**/*.test.*",
|
|
50
|
+
"coveralls": "pnpm run coverage:check && nyc report --reporter=text-lcov --temp-dir \"tmp/coverage/merge/\" | coveralls"
|
|
51
|
+
},
|
|
35
52
|
"devDependencies": {
|
|
36
53
|
"@babel/core": "7.18.5",
|
|
37
54
|
"@babel/plugin-syntax-dynamic-import": "7.8.3",
|
|
@@ -41,7 +58,7 @@
|
|
|
41
58
|
"@babel/runtime-corejs3": "7.18.3",
|
|
42
59
|
"@flemist/copy-glob-flat": "0.0.5",
|
|
43
60
|
"@flemist/karma-custom-launcher": "0.0.0",
|
|
44
|
-
"@flemist/test-utils": "0.0.
|
|
61
|
+
"@flemist/test-utils": "0.0.7",
|
|
45
62
|
"@rollup/plugin-alias": "3.1.9",
|
|
46
63
|
"@rollup/plugin-babel": "5.3.1",
|
|
47
64
|
"@rollup/plugin-commonjs": "=21.1.0",
|
|
@@ -55,7 +72,8 @@
|
|
|
55
72
|
"@types/fs-extra": "9.0.13",
|
|
56
73
|
"@types/mocha": "9.1.1",
|
|
57
74
|
"@types/node": "18.0.0",
|
|
58
|
-
"
|
|
75
|
+
"@zerollup/ts-transform-paths": "1.7.18",
|
|
76
|
+
"cpy-cli": "=3.1.1",
|
|
59
77
|
"eslint": "8.18.0",
|
|
60
78
|
"eslint-config-pro": "3.0.14",
|
|
61
79
|
"fs-extra": "10.1.0",
|
|
@@ -82,23 +100,7 @@
|
|
|
82
100
|
"typescript": "^4.7.4"
|
|
83
101
|
},
|
|
84
102
|
"dependencies": {
|
|
103
|
+
"@flemist/abort-controller-fast": "^0.0.5",
|
|
85
104
|
"tslib": "^2.4.0"
|
|
86
|
-
},
|
|
87
|
-
"scripts": {
|
|
88
|
-
"audit": "pnpm audit --prod",
|
|
89
|
-
"lint": "eslint ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
90
|
-
"lint:fix": "eslint --fix ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
91
|
-
"lint:wizard": "eslint-nibble --cache --multi ./**/*.{js,cjs,mjs,ts,tsx}",
|
|
92
|
-
"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",
|
|
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
|
-
"coverage:check": "pnpm run coverage:merge && nyc check-coverage --report-dir tmp/coverage/all/lcov --lines 50 --functions 50 --branches 50 --statements 50",
|
|
97
|
-
"test:mocha": "mocha ./src/**/*.test.*",
|
|
98
|
-
"test:mocha:coverage": "rimraf tmp/coverage/mocha && nyc --all mocha ./src/**/*.test.*",
|
|
99
|
-
"test:mocha:watch": "mocha --watch ./src/**/*.test.*",
|
|
100
|
-
"test:karma": "rimraf tmp/coverage/karma && karma start --single-run --log-level debug",
|
|
101
|
-
"test:mocha:ci": "rimraf tmp/coverage/mocha && nyc --all mocha ./{src,dist/lib}/**/*.test.*",
|
|
102
|
-
"coveralls": "pnpm run coverage:check && nyc report --reporter=text-lcov --temp-dir \"tmp/coverage/merge/\" | coveralls"
|
|
103
105
|
}
|
|
104
|
-
}
|
|
106
|
+
}
|