@flemist/test-variants 0.0.6 → 0.0.9
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
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
!function(e){"use strict"
|
|
2
2
|
;e.createTestVariants=function(e){
|
|
3
3
|
return function(t){return function(n){
|
|
4
|
-
var
|
|
5
|
-
;function
|
|
6
|
-
;return"function"==typeof t&&(t=t(
|
|
7
|
-
for(var
|
|
8
|
-
;function
|
|
9
|
-
;if(t<
|
|
10
|
-
for(
|
|
11
|
-
;if(0===n.length)break;
|
|
12
|
-
if(e>=
|
|
13
|
-
;var
|
|
14
|
-
console.error(JSON.stringify(
|
|
4
|
+
var o=void 0===n?{}:n,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(t),p=Object.values(t),y=s.length,g={}
|
|
5
|
+
;function h(e){var t=p[e]
|
|
6
|
+
;return"function"==typeof t&&(t=t(g)),t}
|
|
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 t=b[e]+1
|
|
9
|
+
;if(t<d[e].length){
|
|
10
|
+
for(b[e]=t,g[s[e]]=d[e][t],e++;e<y;e++){var n=h(e)
|
|
11
|
+
;if(0===n.length)break;b[e]=0,d[e]=n,g[s[e]]=n[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))
|
|
15
15
|
;var t=Date.now()
|
|
16
|
-
;throw Date.now()-t>50&&
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
;for(var
|
|
16
|
+
;throw Date.now()-t>50&&O<5&&(console.log("DEBUG ITERATION: "+O),
|
|
17
|
+
j=!0,P(0),O++),e}var I=Date.now();function P(t){
|
|
18
|
+
var n=(c||u)&&Date.now()
|
|
19
|
+
;n&&n-I>=c&&(console.log(D),I=n),D+="number"==typeof t?t:1
|
|
20
|
+
;for(var o=u&&n,r=function(){try{var t=e(g)
|
|
21
21
|
;if("object"==typeof t&&t&&"function"==typeof t.then)return{
|
|
22
|
-
value:t.
|
|
23
|
-
;if(
|
|
24
|
-
value:(
|
|
25
|
-
setTimeout((function(){e(t)}),
|
|
26
|
-
})):Promise.resolve(t)).then(
|
|
27
|
-
;
|
|
28
|
-
};w
|
|
29
|
-
;if("object"==typeof
|
|
30
|
-
return D
|
|
22
|
+
value:t.catch(T).then(P)}
|
|
23
|
+
;if(o&&Date.now()-o>=u)return{
|
|
24
|
+
value:(i?new Promise((function(e){
|
|
25
|
+
setTimeout((function(){e(t)}),i)
|
|
26
|
+
})):Promise.resolve(t)).then(P)}
|
|
27
|
+
;D+="number"==typeof t?t: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)}}
|
|
31
32
|
},Object.defineProperty(e,"__esModule",{value:!0})
|
|
32
33
|
}({});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
4
4
|
function createTestVariants(test) {
|
|
5
5
|
return function testVariantsArgs(args) {
|
|
6
|
-
return function testVariantsCall({ pauseInterval, pauseTime = 10, } = {}) {
|
|
6
|
+
return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
|
|
7
7
|
const argsKeys = Object.keys(args);
|
|
8
8
|
const argsValues = Object.values(args);
|
|
9
9
|
const argsLength = argsKeys.length;
|
|
@@ -49,37 +49,43 @@ function createTestVariants(test) {
|
|
|
49
49
|
let debugIteration = 0;
|
|
50
50
|
function onError(err) {
|
|
51
51
|
console.error(JSON.stringify(variantArgs, null, 2));
|
|
52
|
-
console.error(err)
|
|
52
|
+
// console.error(err)
|
|
53
53
|
// rerun failed variant 5 times for debug
|
|
54
54
|
const time0 = Date.now();
|
|
55
55
|
// eslint-disable-next-line no-debugger
|
|
56
56
|
debugger;
|
|
57
57
|
if (Date.now() - time0 > 50 && debugIteration < 5) {
|
|
58
|
+
console.log('DEBUG ITERATION: ' + debugIteration);
|
|
58
59
|
debug = true;
|
|
59
60
|
next(0);
|
|
60
61
|
debugIteration++;
|
|
61
62
|
}
|
|
62
63
|
throw err;
|
|
63
64
|
}
|
|
65
|
+
function onCompleted() {
|
|
66
|
+
if (logCompleted) {
|
|
67
|
+
console.log('variants: ' + iterations);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
64
70
|
let prevLogTime = Date.now();
|
|
65
71
|
function next(value) {
|
|
66
|
-
const now = pauseInterval && Date.now();
|
|
72
|
+
const now = (logInterval || pauseInterval) && Date.now();
|
|
67
73
|
if (now) {
|
|
68
|
-
if (now - prevLogTime >=
|
|
74
|
+
if (now - prevLogTime >= logInterval) {
|
|
69
75
|
// the log is required to prevent the karma browserNoActivityTimeout
|
|
70
76
|
console.log(iterations);
|
|
71
77
|
prevLogTime = now;
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
iterations += typeof value === 'number' ? value : 1;
|
|
75
|
-
const syncCallStartTime = now;
|
|
81
|
+
const syncCallStartTime = pauseInterval && now;
|
|
76
82
|
while (debug || nextVariant()) {
|
|
77
83
|
try {
|
|
78
84
|
const promiseOrIterations = test(variantArgs);
|
|
79
85
|
if (typeof promiseOrIterations === 'object'
|
|
80
86
|
&& promiseOrIterations
|
|
81
87
|
&& typeof promiseOrIterations.then === 'function') {
|
|
82
|
-
return promiseOrIterations.
|
|
88
|
+
return promiseOrIterations.catch(onError).then(next);
|
|
83
89
|
}
|
|
84
90
|
if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
|
|
85
91
|
const pausePromise = pauseTime
|
|
@@ -97,6 +103,7 @@ function createTestVariants(test) {
|
|
|
97
103
|
onError(err);
|
|
98
104
|
}
|
|
99
105
|
}
|
|
106
|
+
onCompleted();
|
|
100
107
|
return iterations;
|
|
101
108
|
}
|
|
102
109
|
return next(0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
2
2
|
function createTestVariants(test) {
|
|
3
3
|
return function testVariantsArgs(args) {
|
|
4
|
-
return function testVariantsCall({ pauseInterval, pauseTime = 10, } = {}) {
|
|
4
|
+
return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
|
|
5
5
|
const argsKeys = Object.keys(args);
|
|
6
6
|
const argsValues = Object.values(args);
|
|
7
7
|
const argsLength = argsKeys.length;
|
|
@@ -47,37 +47,43 @@ function createTestVariants(test) {
|
|
|
47
47
|
let debugIteration = 0;
|
|
48
48
|
function onError(err) {
|
|
49
49
|
console.error(JSON.stringify(variantArgs, null, 2));
|
|
50
|
-
console.error(err)
|
|
50
|
+
// console.error(err)
|
|
51
51
|
// rerun failed variant 5 times for debug
|
|
52
52
|
const time0 = Date.now();
|
|
53
53
|
// eslint-disable-next-line no-debugger
|
|
54
54
|
debugger;
|
|
55
55
|
if (Date.now() - time0 > 50 && debugIteration < 5) {
|
|
56
|
+
console.log('DEBUG ITERATION: ' + debugIteration);
|
|
56
57
|
debug = true;
|
|
57
58
|
next(0);
|
|
58
59
|
debugIteration++;
|
|
59
60
|
}
|
|
60
61
|
throw err;
|
|
61
62
|
}
|
|
63
|
+
function onCompleted() {
|
|
64
|
+
if (logCompleted) {
|
|
65
|
+
console.log('variants: ' + iterations);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
62
68
|
let prevLogTime = Date.now();
|
|
63
69
|
function next(value) {
|
|
64
|
-
const now = pauseInterval && Date.now();
|
|
70
|
+
const now = (logInterval || pauseInterval) && Date.now();
|
|
65
71
|
if (now) {
|
|
66
|
-
if (now - prevLogTime >=
|
|
72
|
+
if (now - prevLogTime >= logInterval) {
|
|
67
73
|
// the log is required to prevent the karma browserNoActivityTimeout
|
|
68
74
|
console.log(iterations);
|
|
69
75
|
prevLogTime = now;
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
iterations += typeof value === 'number' ? value : 1;
|
|
73
|
-
const syncCallStartTime = now;
|
|
79
|
+
const syncCallStartTime = pauseInterval && now;
|
|
74
80
|
while (debug || nextVariant()) {
|
|
75
81
|
try {
|
|
76
82
|
const promiseOrIterations = test(variantArgs);
|
|
77
83
|
if (typeof promiseOrIterations === 'object'
|
|
78
84
|
&& promiseOrIterations
|
|
79
85
|
&& typeof promiseOrIterations.then === 'function') {
|
|
80
|
-
return promiseOrIterations.
|
|
86
|
+
return promiseOrIterations.catch(onError).then(next);
|
|
81
87
|
}
|
|
82
88
|
if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
|
|
83
89
|
const pausePromise = pauseTime
|
|
@@ -95,6 +101,7 @@ function createTestVariants(test) {
|
|
|
95
101
|
onError(err);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
104
|
+
onCompleted();
|
|
98
105
|
return iterations;
|
|
99
106
|
}
|
|
100
107
|
return next(0);
|
|
@@ -7,9 +7,13 @@ 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
|
|
10
|
+
/** pause test, required to prevent the karma browserDisconnectTimeout */
|
|
11
11
|
pauseInterval?: number;
|
|
12
12
|
pauseTime?: number;
|
|
13
|
+
/** console log current iterations, required to prevent the karma browserNoActivityTimeout */
|
|
14
|
+
logInterval?: number;
|
|
15
|
+
/** console log iterations on test completed */
|
|
16
|
+
logCompleted?: boolean;
|
|
13
17
|
};
|
|
14
18
|
export declare function createTestVariants<TArgs extends object>(test: (args: TArgs) => Promise<number | void> | number | void): TestVariantsSetArgs<TArgs>;
|
|
15
19
|
export {};
|