@flemist/test-variants 0.0.9 → 0.0.12

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.
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createTestVariants = require('./createTestVariants.cjs');
5
+ var testVariants_createTestVariants = require('./test-variants/createTestVariants.cjs');
6
6
 
7
7
 
8
8
 
9
- exports.createTestVariants = createTestVariants.createTestVariants;
9
+ exports.createTestVariants = testVariants_createTestVariants.createTestVariants;
@@ -1 +1 @@
1
- export { c as createTestVariants } from './createTestVariants.mjs';
1
+ export { createTestVariants } from './test-variants/createTestVariants.mjs';
@@ -2,8 +2,114 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var createTestVariants = require('../createTestVariants.cjs');
5
+ /* eslint-disable @typescript-eslint/no-shadow */
6
+ function createTestVariants(test) {
7
+ return function testVariantsArgs(args) {
8
+ return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
9
+ const argsKeys = Object.keys(args);
10
+ const argsValues = Object.values(args);
11
+ const argsLength = argsKeys.length;
12
+ const variantArgs = {};
13
+ function getArgValues(nArg) {
14
+ let argValues = argsValues[nArg];
15
+ if (typeof argValues === 'function') {
16
+ argValues = argValues(variantArgs);
17
+ }
18
+ return argValues;
19
+ }
20
+ const indexes = [];
21
+ const values = [];
22
+ for (let nArg = 0; nArg < argsLength; nArg++) {
23
+ indexes[nArg] = -1;
24
+ values[nArg] = [];
25
+ }
26
+ values[0] = getArgValues(0);
27
+ function nextVariant() {
28
+ for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
29
+ const index = indexes[nArg] + 1;
30
+ if (index < values[nArg].length) {
31
+ indexes[nArg] = index;
32
+ variantArgs[argsKeys[nArg]] = values[nArg][index];
33
+ for (nArg++; nArg < argsLength; nArg++) {
34
+ const argValues = getArgValues(nArg);
35
+ if (argValues.length === 0) {
36
+ break;
37
+ }
38
+ indexes[nArg] = 0;
39
+ values[nArg] = argValues;
40
+ variantArgs[argsKeys[nArg]] = argValues[0];
41
+ }
42
+ if (nArg >= argsLength) {
43
+ return true;
44
+ }
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ let iterations = 0;
50
+ let debug = false;
51
+ let debugIteration = 0;
52
+ function onError(err) {
53
+ console.error(JSON.stringify(variantArgs, null, 2));
54
+ // rerun failed variant 5 times for debug
55
+ const time0 = Date.now();
56
+ // eslint-disable-next-line no-debugger
57
+ debugger;
58
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
59
+ console.log('DEBUG ITERATION: ' + debugIteration);
60
+ debug = true;
61
+ next(0);
62
+ debugIteration++;
63
+ }
64
+ throw err;
65
+ }
66
+ function onCompleted() {
67
+ if (logCompleted) {
68
+ console.log('variants: ' + iterations);
69
+ }
70
+ }
71
+ let prevLogTime = Date.now();
72
+ function next(value) {
73
+ const now = (logInterval || pauseInterval) && Date.now();
74
+ if (now) {
75
+ if (now - prevLogTime >= logInterval) {
76
+ // the log is required to prevent the karma browserNoActivityTimeout
77
+ console.log(iterations);
78
+ prevLogTime = now;
79
+ }
80
+ }
81
+ iterations += typeof value === 'number' ? value : 1;
82
+ const syncCallStartTime = pauseInterval && now;
83
+ while (debug || nextVariant()) {
84
+ try {
85
+ const promiseOrIterations = test(variantArgs);
86
+ if (typeof promiseOrIterations === 'object'
87
+ && promiseOrIterations
88
+ && typeof promiseOrIterations.then === 'function') {
89
+ return promiseOrIterations.catch(onError).then(next);
90
+ }
91
+ if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
92
+ const pausePromise = pauseTime
93
+ ? new Promise(resolve => {
94
+ setTimeout(() => {
95
+ resolve(promiseOrIterations);
96
+ }, pauseTime);
97
+ })
98
+ : Promise.resolve(promiseOrIterations);
99
+ return pausePromise.then(next);
100
+ }
101
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
102
+ }
103
+ catch (err) {
104
+ onError(err);
105
+ }
106
+ }
107
+ onCompleted();
108
+ return iterations;
109
+ }
110
+ return next(0);
111
+ };
112
+ };
113
+ }
6
114
 
7
-
8
-
9
- exports.createTestVariants = createTestVariants.createTestVariants;
115
+ exports.createTestVariants = createTestVariants;
@@ -1 +1,111 @@
1
- export { c as createTestVariants } from '../createTestVariants.mjs';
1
+ /* eslint-disable @typescript-eslint/no-shadow */
2
+ function createTestVariants(test) {
3
+ return function testVariantsArgs(args) {
4
+ return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
5
+ const argsKeys = Object.keys(args);
6
+ const argsValues = Object.values(args);
7
+ const argsLength = argsKeys.length;
8
+ const variantArgs = {};
9
+ function getArgValues(nArg) {
10
+ let argValues = argsValues[nArg];
11
+ if (typeof argValues === 'function') {
12
+ argValues = argValues(variantArgs);
13
+ }
14
+ return argValues;
15
+ }
16
+ const indexes = [];
17
+ const values = [];
18
+ for (let nArg = 0; nArg < argsLength; nArg++) {
19
+ indexes[nArg] = -1;
20
+ values[nArg] = [];
21
+ }
22
+ values[0] = getArgValues(0);
23
+ function nextVariant() {
24
+ for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
25
+ const index = indexes[nArg] + 1;
26
+ if (index < values[nArg].length) {
27
+ indexes[nArg] = index;
28
+ variantArgs[argsKeys[nArg]] = values[nArg][index];
29
+ for (nArg++; nArg < argsLength; nArg++) {
30
+ const argValues = getArgValues(nArg);
31
+ if (argValues.length === 0) {
32
+ break;
33
+ }
34
+ indexes[nArg] = 0;
35
+ values[nArg] = argValues;
36
+ variantArgs[argsKeys[nArg]] = argValues[0];
37
+ }
38
+ if (nArg >= argsLength) {
39
+ return true;
40
+ }
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ let iterations = 0;
46
+ let debug = false;
47
+ let debugIteration = 0;
48
+ function onError(err) {
49
+ console.error(JSON.stringify(variantArgs, null, 2));
50
+ // rerun failed variant 5 times for debug
51
+ const time0 = Date.now();
52
+ // eslint-disable-next-line no-debugger
53
+ debugger;
54
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
55
+ console.log('DEBUG ITERATION: ' + debugIteration);
56
+ debug = true;
57
+ next(0);
58
+ debugIteration++;
59
+ }
60
+ throw err;
61
+ }
62
+ function onCompleted() {
63
+ if (logCompleted) {
64
+ console.log('variants: ' + iterations);
65
+ }
66
+ }
67
+ let prevLogTime = Date.now();
68
+ function next(value) {
69
+ const now = (logInterval || pauseInterval) && Date.now();
70
+ if (now) {
71
+ if (now - prevLogTime >= logInterval) {
72
+ // the log is required to prevent the karma browserNoActivityTimeout
73
+ console.log(iterations);
74
+ prevLogTime = now;
75
+ }
76
+ }
77
+ iterations += typeof value === 'number' ? value : 1;
78
+ const syncCallStartTime = pauseInterval && now;
79
+ while (debug || nextVariant()) {
80
+ try {
81
+ const promiseOrIterations = test(variantArgs);
82
+ if (typeof promiseOrIterations === 'object'
83
+ && promiseOrIterations
84
+ && typeof promiseOrIterations.then === 'function') {
85
+ return promiseOrIterations.catch(onError).then(next);
86
+ }
87
+ if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
88
+ const pausePromise = pauseTime
89
+ ? new Promise(resolve => {
90
+ setTimeout(() => {
91
+ resolve(promiseOrIterations);
92
+ }, pauseTime);
93
+ })
94
+ : Promise.resolve(promiseOrIterations);
95
+ return pausePromise.then(next);
96
+ }
97
+ iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
98
+ }
99
+ catch (err) {
100
+ onError(err);
101
+ }
102
+ }
103
+ onCompleted();
104
+ return iterations;
105
+ }
106
+ return next(0);
107
+ };
108
+ };
109
+ }
110
+
111
+ export { createTestVariants };
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var rdtsc = require('rdtsc');
4
- var createTestVariants = require('../createTestVariants.cjs');
4
+ var testVariants_createTestVariants = require('./createTestVariants.cjs');
5
5
 
6
6
  describe('test > testVariants perf', function () {
7
7
  this.timeout(300000);
8
8
  it('sync', function () {
9
9
  let value = 0;
10
- const testVariantsSync = createTestVariants.createTestVariants(({ a, b, c }) => {
10
+ const testVariantsSync = testVariants_createTestVariants.createTestVariants(({ a, b, c }) => {
11
11
  if (a === 1 && b === '4' && c === false) {
12
12
  value++;
13
13
  }
@@ -1,5 +1,5 @@
1
1
  import { calcPerformance } from 'rdtsc';
2
- import { c as createTestVariants } from '../createTestVariants.mjs';
2
+ import { createTestVariants } from './createTestVariants.mjs';
3
3
 
4
4
  describe('test > testVariants perf', function () {
5
5
  this.timeout(300000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "0.0.9",
3
+ "version": "0.0.12",
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",
@@ -44,7 +44,7 @@
44
44
  "@flemist/test-utils": "0.0.5",
45
45
  "@rollup/plugin-alias": "3.1.9",
46
46
  "@rollup/plugin-babel": "5.3.1",
47
- "@rollup/plugin-commonjs": "22.0.0",
47
+ "@rollup/plugin-commonjs": "=21.1.0",
48
48
  "@rollup/plugin-inject": "4.0.4",
49
49
  "@rollup/plugin-json": "4.1.0",
50
50
  "@rollup/plugin-multi-entry": "4.1.0",
@@ -57,7 +57,7 @@
57
57
  "@types/node": "18.0.0",
58
58
  "cpy-cli": "3.1.1",
59
59
  "eslint": "8.18.0",
60
- "eslint-config-pro": "3.0.13",
60
+ "eslint-config-pro": "3.0.14",
61
61
  "fs-extra": "10.1.0",
62
62
  "globby": "=11.1.0",
63
63
  "karma": "6.4.0",
@@ -71,7 +71,7 @@
71
71
  "nyc": "15.1.0",
72
72
  "rdtsc": "2.0.0",
73
73
  "rimraf": "3.0.2",
74
- "rollup": "2.75.6",
74
+ "rollup": "2.75.7",
75
75
  "rollup-plugin-delete": "2.0.0",
76
76
  "rollup-plugin-istanbul": "3.0.0",
77
77
  "rollup-plugin-multi-input": "1.3.1",
@@ -1,114 +0,0 @@
1
- 'use strict';
2
-
3
- /* eslint-disable @typescript-eslint/no-shadow */
4
- function createTestVariants(test) {
5
- return function testVariantsArgs(args) {
6
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
7
- const argsKeys = Object.keys(args);
8
- const argsValues = Object.values(args);
9
- const argsLength = argsKeys.length;
10
- const variantArgs = {};
11
- function getArgValues(nArg) {
12
- let argValues = argsValues[nArg];
13
- if (typeof argValues === 'function') {
14
- argValues = argValues(variantArgs);
15
- }
16
- return argValues;
17
- }
18
- const indexes = [];
19
- const values = [];
20
- for (let nArg = 0; nArg < argsLength; nArg++) {
21
- indexes[nArg] = -1;
22
- values[nArg] = [];
23
- }
24
- values[0] = getArgValues(0);
25
- function nextVariant() {
26
- for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
27
- const index = indexes[nArg] + 1;
28
- if (index < values[nArg].length) {
29
- indexes[nArg] = index;
30
- variantArgs[argsKeys[nArg]] = values[nArg][index];
31
- for (nArg++; nArg < argsLength; nArg++) {
32
- const argValues = getArgValues(nArg);
33
- if (argValues.length === 0) {
34
- break;
35
- }
36
- indexes[nArg] = 0;
37
- values[nArg] = argValues;
38
- variantArgs[argsKeys[nArg]] = argValues[0];
39
- }
40
- if (nArg >= argsLength) {
41
- return true;
42
- }
43
- }
44
- }
45
- return false;
46
- }
47
- let iterations = 0;
48
- let debug = false;
49
- let debugIteration = 0;
50
- function onError(err) {
51
- console.error(JSON.stringify(variantArgs, null, 2));
52
- // console.error(err)
53
- // rerun failed variant 5 times for debug
54
- const time0 = Date.now();
55
- // eslint-disable-next-line no-debugger
56
- debugger;
57
- if (Date.now() - time0 > 50 && debugIteration < 5) {
58
- console.log('DEBUG ITERATION: ' + debugIteration);
59
- debug = true;
60
- next(0);
61
- debugIteration++;
62
- }
63
- throw err;
64
- }
65
- function onCompleted() {
66
- if (logCompleted) {
67
- console.log('variants: ' + iterations);
68
- }
69
- }
70
- let prevLogTime = Date.now();
71
- function next(value) {
72
- const now = (logInterval || pauseInterval) && Date.now();
73
- if (now) {
74
- if (now - prevLogTime >= logInterval) {
75
- // the log is required to prevent the karma browserNoActivityTimeout
76
- console.log(iterations);
77
- prevLogTime = now;
78
- }
79
- }
80
- iterations += typeof value === 'number' ? value : 1;
81
- const syncCallStartTime = pauseInterval && now;
82
- while (debug || nextVariant()) {
83
- try {
84
- const promiseOrIterations = test(variantArgs);
85
- if (typeof promiseOrIterations === 'object'
86
- && promiseOrIterations
87
- && typeof promiseOrIterations.then === 'function') {
88
- return promiseOrIterations.catch(onError).then(next);
89
- }
90
- if (syncCallStartTime && Date.now() - syncCallStartTime >= pauseInterval) {
91
- const pausePromise = pauseTime
92
- ? new Promise(resolve => {
93
- setTimeout(() => {
94
- resolve(promiseOrIterations);
95
- }, pauseTime);
96
- })
97
- : Promise.resolve(promiseOrIterations);
98
- return pausePromise.then(next);
99
- }
100
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
101
- }
102
- catch (err) {
103
- onError(err);
104
- }
105
- }
106
- onCompleted();
107
- return iterations;
108
- }
109
- return next(0);
110
- };
111
- };
112
- }
113
-
114
- exports.createTestVariants = createTestVariants;
@@ -1,112 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-shadow */
2
- function createTestVariants(test) {
3
- return function testVariantsArgs(args) {
4
- return function testVariantsCall({ pauseInterval = 1000, pauseTime = 10, logInterval = 10000, logCompleted = true, } = {}) {
5
- const argsKeys = Object.keys(args);
6
- const argsValues = Object.values(args);
7
- const argsLength = argsKeys.length;
8
- const variantArgs = {};
9
- function getArgValues(nArg) {
10
- let argValues = argsValues[nArg];
11
- if (typeof argValues === 'function') {
12
- argValues = argValues(variantArgs);
13
- }
14
- return argValues;
15
- }
16
- const indexes = [];
17
- const values = [];
18
- for (let nArg = 0; nArg < argsLength; nArg++) {
19
- indexes[nArg] = -1;
20
- values[nArg] = [];
21
- }
22
- values[0] = getArgValues(0);
23
- function nextVariant() {
24
- for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
25
- const index = indexes[nArg] + 1;
26
- if (index < values[nArg].length) {
27
- indexes[nArg] = index;
28
- variantArgs[argsKeys[nArg]] = values[nArg][index];
29
- for (nArg++; nArg < argsLength; nArg++) {
30
- const argValues = getArgValues(nArg);
31
- if (argValues.length === 0) {
32
- break;
33
- }
34
- indexes[nArg] = 0;
35
- values[nArg] = argValues;
36
- variantArgs[argsKeys[nArg]] = argValues[0];
37
- }
38
- if (nArg >= argsLength) {
39
- return true;
40
- }
41
- }
42
- }
43
- return false;
44
- }
45
- let iterations = 0;
46
- let debug = false;
47
- let debugIteration = 0;
48
- function onError(err) {
49
- console.error(JSON.stringify(variantArgs, null, 2));
50
- // console.error(err)
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;
62
- }
63
- function onCompleted() {
64
- if (logCompleted) {
65
- console.log('variants: ' + iterations);
66
- }
67
- }
68
- 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()) {
81
- 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);
97
- }
98
- iterations += typeof promiseOrIterations === 'number' ? promiseOrIterations : 1;
99
- }
100
- catch (err) {
101
- onError(err);
102
- }
103
- }
104
- onCompleted();
105
- return iterations;
106
- }
107
- return next(0);
108
- };
109
- };
110
- }
111
-
112
- export { createTestVariants as c };
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- function delay(milliseconds, abortSignal) {
4
- return new Promise(resolve => {
5
- if (abortSignal && abortSignal.aborted) {
6
- resolve();
7
- return;
8
- }
9
- const timer = setTimeout(resolve, milliseconds);
10
- if (abortSignal) {
11
- abortSignal.addEventListener('abort', () => {
12
- clearTimeout(timer);
13
- resolve();
14
- });
15
- }
16
- });
17
- }
18
-
19
- exports.delay = delay;
@@ -1,17 +0,0 @@
1
- function delay(milliseconds, abortSignal) {
2
- return new Promise(resolve => {
3
- if (abortSignal && abortSignal.aborted) {
4
- resolve();
5
- return;
6
- }
7
- const timer = setTimeout(resolve, milliseconds);
8
- if (abortSignal) {
9
- abortSignal.addEventListener('abort', () => {
10
- clearTimeout(timer);
11
- resolve();
12
- });
13
- }
14
- });
15
- }
16
-
17
- export { delay as d };