@flemist/test-variants 0.0.4 → 0.0.7
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/README.md
CHANGED
|
@@ -18,7 +18,8 @@ const count = await testVariants({
|
|
|
18
18
|
b: ['3', '4'],
|
|
19
19
|
c: [true, false],
|
|
20
20
|
})({
|
|
21
|
-
|
|
21
|
+
pauseInterval: 10000, // pause after each 10 seconds and log inerations count, it needed for karma tests
|
|
22
|
+
pauseTime: 10, // continue after 10 milliseconds
|
|
22
23
|
})
|
|
23
24
|
|
|
24
25
|
// result == [
|
package/dist/bundle/browser.js
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
!function(
|
|
2
|
-
;
|
|
3
|
-
return function(
|
|
4
|
-
var
|
|
5
|
-
;function
|
|
6
|
-
;return"function"==typeof
|
|
7
|
-
for(var
|
|
8
|
-
;function
|
|
9
|
-
;if(
|
|
10
|
-
for(
|
|
11
|
-
;if(0===
|
|
12
|
-
if(
|
|
13
|
-
;var
|
|
14
|
-
console.error(JSON.stringify(
|
|
15
|
-
;var
|
|
16
|
-
;throw Date.now()-
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
;
|
|
20
|
-
;
|
|
21
|
-
;
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
!function(e){"use strict"
|
|
2
|
+
;e.createTestVariants=function(e){
|
|
3
|
+
return function(t){return function(n){
|
|
4
|
+
var r=void 0===n?{}:n,o=r.pauseInterval,u=void 0===o?1e3:o,a=r.pauseTime,i=void 0===a?10:a,f=r.logInterval,c=void 0===f?1e4:f,v=Object.keys(t),l=Object.values(t),s=v.length,y={}
|
|
5
|
+
;function h(e){var t=l[e]
|
|
6
|
+
;return"function"==typeof t&&(t=t(y)),t}
|
|
7
|
+
for(var p=[],b=[],w=0;w<s;w++)p[w]=-1,b[w]=[]
|
|
8
|
+
;function d(){for(var e=s-1;e>=0;e--){var t=p[e]+1
|
|
9
|
+
;if(t<b[e].length){
|
|
10
|
+
for(p[e]=t,y[v[e]]=b[e][t],e++;e<s;e++){var n=h(e)
|
|
11
|
+
;if(0===n.length)break;p[e]=0,b[e]=n,y[v[e]]=n[0]}
|
|
12
|
+
if(e>=s)return!0}}return!1}b[0]=h(0)
|
|
13
|
+
;var g=0,m=!1,j=0;function D(e){
|
|
14
|
+
console.error(JSON.stringify(y,null,2)),console.error(e)
|
|
15
|
+
;var t=Date.now()
|
|
16
|
+
;throw Date.now()-t>50&&j<5&&(m=!0,P(0),j++),e}
|
|
17
|
+
var O=Date.now();function P(t){
|
|
18
|
+
var n=(c||u)&&Date.now()
|
|
19
|
+
;n&&n-O>=c&&(console.log(g),O=n),g+="number"==typeof t?t:1
|
|
20
|
+
;for(var r=u&&n,o=function(){try{var t=e(y)
|
|
21
|
+
;if("object"==typeof t&&t&&"function"==typeof t.then)return{
|
|
22
|
+
value:t.then(P).catch(D)}
|
|
23
|
+
;if(r&&Date.now()-r>=u)return{
|
|
24
|
+
value:(i?new Promise((function(e){
|
|
25
|
+
setTimeout((function(){e(t)}),i)
|
|
26
|
+
})):Promise.resolve(t)).then(P)}
|
|
27
|
+
;g+="number"==typeof t?t:1}catch(e){D(e)}
|
|
28
|
+
};m||d();){var a=o()
|
|
29
|
+
;if("object"==typeof a)return a.value}return g}
|
|
30
|
+
return P(0)}}
|
|
31
|
+
},Object.defineProperty(e,"__esModule",{value:!0})
|
|
24
32
|
}({});
|
|
@@ -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({
|
|
6
|
+
return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, } = {}) {
|
|
7
7
|
const argsKeys = Object.keys(args);
|
|
8
8
|
const argsValues = Object.values(args);
|
|
9
9
|
const argsLength = argsKeys.length;
|
|
@@ -61,9 +61,18 @@ function createTestVariants(test) {
|
|
|
61
61
|
}
|
|
62
62
|
throw err;
|
|
63
63
|
}
|
|
64
|
+
let prevLogTime = Date.now();
|
|
64
65
|
function next(value) {
|
|
66
|
+
const now = (logInterval || pauseInterval) && Date.now();
|
|
67
|
+
if (now) {
|
|
68
|
+
if (now - prevLogTime >= logInterval) {
|
|
69
|
+
// the log is required to prevent the karma browserNoActivityTimeout
|
|
70
|
+
console.log(iterations);
|
|
71
|
+
prevLogTime = now;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
65
74
|
iterations += typeof value === 'number' ? value : 1;
|
|
66
|
-
const
|
|
75
|
+
const syncCallStartTime = pauseInterval && now;
|
|
67
76
|
while (debug || nextVariant()) {
|
|
68
77
|
try {
|
|
69
78
|
const promiseOrIterations = test(variantArgs);
|
|
@@ -72,8 +81,15 @@ function createTestVariants(test) {
|
|
|
72
81
|
&& typeof promiseOrIterations.then === 'function') {
|
|
73
82
|
return promiseOrIterations.then(next).catch(onError);
|
|
74
83
|
}
|
|
75
|
-
if (
|
|
76
|
-
|
|
84
|
+
if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
|
|
85
|
+
const pausePromise = pauseTime
|
|
86
|
+
? new Promise(resolve => {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
resolve(promiseOrIterations);
|
|
89
|
+
}, pauseTime);
|
|
90
|
+
})
|
|
91
|
+
: Promise.resolve(promiseOrIterations);
|
|
92
|
+
return pausePromise.then(next);
|
|
77
93
|
}
|
|
78
94
|
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
79
95
|
}
|
|
@@ -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({
|
|
4
|
+
return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, } = {}) {
|
|
5
5
|
const argsKeys = Object.keys(args);
|
|
6
6
|
const argsValues = Object.values(args);
|
|
7
7
|
const argsLength = argsKeys.length;
|
|
@@ -59,9 +59,18 @@ function createTestVariants(test) {
|
|
|
59
59
|
}
|
|
60
60
|
throw err;
|
|
61
61
|
}
|
|
62
|
+
let prevLogTime = Date.now();
|
|
62
63
|
function next(value) {
|
|
64
|
+
const now = (logInterval || pauseInterval) && Date.now();
|
|
65
|
+
if (now) {
|
|
66
|
+
if (now - prevLogTime >= logInterval) {
|
|
67
|
+
// the log is required to prevent the karma browserNoActivityTimeout
|
|
68
|
+
console.log(iterations);
|
|
69
|
+
prevLogTime = now;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
63
72
|
iterations += typeof value === 'number' ? value : 1;
|
|
64
|
-
const
|
|
73
|
+
const syncCallStartTime = pauseInterval && now;
|
|
65
74
|
while (debug || nextVariant()) {
|
|
66
75
|
try {
|
|
67
76
|
const promiseOrIterations = test(variantArgs);
|
|
@@ -70,8 +79,15 @@ function createTestVariants(test) {
|
|
|
70
79
|
&& typeof promiseOrIterations.then === 'function') {
|
|
71
80
|
return promiseOrIterations.then(next).catch(onError);
|
|
72
81
|
}
|
|
73
|
-
if (
|
|
74
|
-
|
|
82
|
+
if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
|
|
83
|
+
const pausePromise = pauseTime
|
|
84
|
+
? new Promise(resolve => {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
resolve(promiseOrIterations);
|
|
87
|
+
}, pauseTime);
|
|
88
|
+
})
|
|
89
|
+
: Promise.resolve(promiseOrIterations);
|
|
90
|
+
return pausePromise.then(next);
|
|
75
91
|
}
|
|
76
92
|
iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
|
|
77
93
|
}
|
|
@@ -7,7 +7,11 @@ 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
|
-
|
|
10
|
+
/** pause test, required to prevent the karma browserDisconnectTimeout */
|
|
11
|
+
pauseInterval?: number;
|
|
12
|
+
pauseTime?: number;
|
|
13
|
+
/** console log current iterations, required to prevent the karma browserNoActivityTimeout */
|
|
14
|
+
logInterval?: number;
|
|
11
15
|
};
|
|
12
16
|
export declare function createTestVariants<TArgs extends object>(test: (args: TArgs) => Promise<number | void> | number | void): TestVariantsSetArgs<TArgs>;
|
|
13
17
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flemist/test-variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
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": "
|
|
44
|
+
"@flemist/test-utils": "0.0.5",
|
|
45
45
|
"@rollup/plugin-alias": "3.1.9",
|
|
46
46
|
"@rollup/plugin-babel": "5.3.1",
|
|
47
47
|
"@rollup/plugin-commonjs": "22.0.0",
|