@flemist/test-variants 0.0.0 → 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Unlimited Free Licence
2
+
3
+ Point one: Everyone can do whatever they want with this code, except to limit others from using point one.
4
+ Point two: Whoever and whatever does with this code, it does not entail any obligations for anyone to the author.
5
+ Point three: The author is not responsible for anything.
package/README.md CHANGED
@@ -60,6 +60,10 @@ const count = await testVariants({
60
60
  })
61
61
  ```
62
62
 
63
+ # License
64
+
65
+ [Unlimited Free](LICENSE)
66
+
63
67
  [npm-image]: https://img.shields.io/npm/v/@flemist/test-variants.svg
64
68
  [npm-url]: https://npmjs.org/package/@flemist/test-variants
65
69
  [downloads-image]: https://img.shields.io/npm/dm/@flemist/test-variants.svg
@@ -1,22 +1,24 @@
1
1
  !function(r){"use strict";function t(r,t){
2
- return function(n){
3
- var e=Object.keys(n),o=Object.values(n),c=e.length,f={}
4
- ;function u(r){var t=o[r]
5
- ;return"function"==typeof t&&(t=t(f)),t}
6
- for(var a=[],i=[],s=0;s<c;s++)a[s]=-1,i[s]=[]
7
- ;function v(){for(var r=c-1;r>=0;r--){var t=a[r]+1
8
- ;if(t<i[r].length){
9
- for(a[r]=t,f[e[r]]=i[r][t],r++;r<c;r++){var n=u(r)
10
- ;if(0===n.length)break;a[r]=0,i[r]=n,f[e[r]]=n[0]}
11
- if(r>=c)return!0}}return!1}i[0]=u(0);var l=0
12
- ;function h(t){
13
- console.error(JSON.stringify(f,null,2)),console.error(t)
14
- ;var n=Date.now()
15
- ;if(Date.now()-n>5)for(var e=0;e<5;e++)try{r(f)
16
- }catch(r){}throw t}return function n(){
17
- for(;v();)try{l++;var e=r(f)
18
- ;if(e&&"function"==typeof e.then)return t&&h(new Error("Unexpected Promise result for sync test function")),
19
- e.then(n).catch(h)}catch(r){h(r)}return l}()}}
2
+ return function(e){
3
+ var n=Object.keys(e),o=Object.values(e),u=n.length,c={}
4
+ ;function f(r){var t=o[r]
5
+ ;return"function"==typeof t&&(t=t(c)),t}
6
+ for(var i=[],a=[],s=0;s<u;s++)i[s]=-1,a[s]=[]
7
+ ;function l(){for(var r=u-1;r>=0;r--){var t=i[r]+1
8
+ ;if(t<a[r].length){
9
+ for(i[r]=t,c[n[r]]=a[r][t],r++;r<u;r++){var e=f(r)
10
+ ;if(0===e.length)break;i[r]=0,a[r]=e,c[n[r]]=e[0]}
11
+ if(r>=u)return!0}}return!1}a[0]=f(0)
12
+ ;var v=0,y=!1,h=0;function b(r){
13
+ console.error(JSON.stringify(c,null,2)),console.error(r)
14
+ ;var t=Date.now()
15
+ ;throw Date.now()-t>50&&h<5&&(y=!0,p(0),h++),r}
16
+ function p(e){
17
+ for(v+="number"==typeof e?e:1;y||l();)try{
18
+ var n=r(c)
19
+ ;if("object"==typeof n&&n&&"function"==typeof n.then)return t&&b(new Error("Unexpected Promise result for sync test function")),
20
+ n.then(p).catch(b);v+="number"==typeof n?n:1
21
+ }catch(r){b(r)}return v}return p(0)}}
20
22
  r.createTestVariants=function(r){return t(r,!1)
21
23
  },r.createTestVariantsSync=function(r){
22
24
  return t(r,!0)
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable @typescript-eslint/no-shadow */
4
+ function _createTestVariants(test, sync) {
5
+ return function _testVariants(args) {
6
+ const argsKeys = Object.keys(args);
7
+ const argsValues = Object.values(args);
8
+ const argsLength = argsKeys.length;
9
+ const variantArgs = {};
10
+ function getArgValues(nArg) {
11
+ let argValues = argsValues[nArg];
12
+ if (typeof argValues === 'function') {
13
+ argValues = argValues(variantArgs);
14
+ }
15
+ return argValues;
16
+ }
17
+ const indexes = [];
18
+ const values = [];
19
+ for (let nArg = 0; nArg < argsLength; nArg++) {
20
+ indexes[nArg] = -1;
21
+ values[nArg] = [];
22
+ }
23
+ values[0] = getArgValues(0);
24
+ function nextVariant() {
25
+ for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
26
+ const index = indexes[nArg] + 1;
27
+ if (index < values[nArg].length) {
28
+ indexes[nArg] = index;
29
+ variantArgs[argsKeys[nArg]] = values[nArg][index];
30
+ for (nArg++; nArg < argsLength; nArg++) {
31
+ const argValues = getArgValues(nArg);
32
+ if (argValues.length === 0) {
33
+ break;
34
+ }
35
+ indexes[nArg] = 0;
36
+ values[nArg] = argValues;
37
+ variantArgs[argsKeys[nArg]] = argValues[0];
38
+ }
39
+ if (nArg >= argsLength) {
40
+ return true;
41
+ }
42
+ }
43
+ }
44
+ return false;
45
+ }
46
+ let iterations = 0;
47
+ let debug = false;
48
+ let debugIteration = 0;
49
+ function onError(err) {
50
+ console.error(JSON.stringify(variantArgs, null, 2));
51
+ console.error(err);
52
+ // rerun failed variant 5 times for debug
53
+ const time0 = Date.now();
54
+ // eslint-disable-next-line no-debugger
55
+ debugger;
56
+ if (Date.now() - time0 > 50 && debugIteration < 5) {
57
+ debug = true;
58
+ next(0);
59
+ debugIteration++;
60
+ }
61
+ throw err;
62
+ }
63
+ function next(value) {
64
+ iterations += typeof value === 'number' ? value : 1;
65
+ while (debug || nextVariant()) {
66
+ try {
67
+ const promise = test(variantArgs);
68
+ if (typeof promise === 'object' && promise && typeof promise.then === 'function') {
69
+ if (sync) {
70
+ onError(new Error('Unexpected Promise result for sync test function'));
71
+ }
72
+ return promise.then(next).catch(onError);
73
+ }
74
+ else {
75
+ iterations += typeof promise === 'number' ? promise : 1;
76
+ }
77
+ }
78
+ catch (err) {
79
+ onError(err);
80
+ }
81
+ }
82
+ return iterations;
83
+ }
84
+ return next(0);
85
+ };
86
+ }
87
+ function createTestVariantsSync(test) {
88
+ return _createTestVariants(test, true);
89
+ }
90
+ function createTestVariants(test) {
91
+ return _createTestVariants(test, false);
92
+ }
93
+
94
+ exports.createTestVariants = createTestVariants;
95
+ exports.createTestVariantsSync = createTestVariantsSync;
@@ -0,0 +1,19 @@
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;
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var testVariants_createTestVariants = require('./test-variants/createTestVariants.cjs');
5
+ var createTestVariants = require('./createTestVariants.cjs');
6
6
 
7
7
 
8
8
 
9
- exports.createTestVariants = testVariants_createTestVariants.createTestVariants;
10
- exports.createTestVariantsSync = testVariants_createTestVariants.createTestVariantsSync;
9
+ exports.createTestVariants = createTestVariants.createTestVariants;
10
+ exports.createTestVariantsSync = createTestVariants.createTestVariantsSync;
@@ -2,97 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /* eslint-disable @typescript-eslint/no-shadow */
6
- function _createTestVariants(test, sync) {
7
- return function _testVariants(args) {
8
- const argsKeys = Object.keys(args);
9
- const argsValues = Object.values(args);
10
- const argsLength = argsKeys.length;
11
- const variantArgs = {};
12
- function getArgValues(nArg) {
13
- let argValues = argsValues[nArg];
14
- if (typeof argValues === 'function') {
15
- argValues = argValues(variantArgs);
16
- }
17
- return argValues;
18
- }
19
- const indexes = [];
20
- const values = [];
21
- for (let nArg = 0; nArg < argsLength; nArg++) {
22
- indexes[nArg] = -1;
23
- values[nArg] = [];
24
- }
25
- values[0] = getArgValues(0);
26
- function nextVariant() {
27
- for (let nArg = argsLength - 1; nArg >= 0; nArg--) {
28
- const index = indexes[nArg] + 1;
29
- if (index < values[nArg].length) {
30
- indexes[nArg] = index;
31
- variantArgs[argsKeys[nArg]] = values[nArg][index];
32
- for (nArg++; nArg < argsLength; nArg++) {
33
- const argValues = getArgValues(nArg);
34
- if (argValues.length === 0) {
35
- break;
36
- }
37
- indexes[nArg] = 0;
38
- values[nArg] = argValues;
39
- variantArgs[argsKeys[nArg]] = argValues[0];
40
- }
41
- if (nArg >= argsLength) {
42
- return true;
43
- }
44
- }
45
- }
46
- return false;
47
- }
48
- let iteration = 0;
49
- function onError(err) {
50
- console.error(JSON.stringify(variantArgs, null, 2));
51
- console.error(err);
52
- // rerun failed variant 5 times for debug
53
- const time0 = Date.now();
54
- // eslint-disable-next-line no-debugger
55
- debugger;
56
- if (Date.now() - time0 > 5) {
57
- for (let i = 0; i < 5; i++) {
58
- try {
59
- test(variantArgs);
60
- }
61
- catch (_a) {
62
- // eslint-disable-next-line no-debugger
63
- debugger;
64
- }
65
- }
66
- }
67
- throw err;
68
- }
69
- const next = function next() {
70
- while (nextVariant()) {
71
- try {
72
- iteration++;
73
- const promise = test(variantArgs);
74
- if (promise && typeof promise.then === 'function') {
75
- if (sync) {
76
- onError(new Error('Unexpected Promise result for sync test function'));
77
- }
78
- return promise.then(next).catch(onError);
79
- }
80
- }
81
- catch (err) {
82
- onError(err);
83
- }
84
- }
85
- return iteration;
86
- };
87
- return next();
88
- };
89
- }
90
- function createTestVariantsSync(test) {
91
- return _createTestVariants(test, true);
92
- }
93
- function createTestVariants(test) {
94
- return _createTestVariants(test, false);
95
- }
5
+ var createTestVariants = require('../createTestVariants.cjs');
96
6
 
97
- exports.createTestVariants = createTestVariants;
98
- exports.createTestVariantsSync = createTestVariantsSync;
7
+
8
+
9
+ exports.createTestVariants = createTestVariants.createTestVariants;
10
+ exports.createTestVariantsSync = createTestVariants.createTestVariantsSync;
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var rdtsc = require('rdtsc');
4
- var testVariants_createTestVariants = require('./createTestVariants.cjs');
4
+ var createTestVariants = require('../createTestVariants.cjs');
5
5
 
6
6
  describe('test > testVariants perf', function () {
7
7
  this.timeout(300000);
8
8
  it('sync/async', function () {
9
- const testVariantsAsync = testVariants_createTestVariants.createTestVariants(({ a, b, c }) => {
9
+ const testVariantsAsync = createTestVariants.createTestVariants(({ a, b, c }) => {
10
10
  });
11
- const testVariantsSync = testVariants_createTestVariants.createTestVariantsSync(({ a, b, c }) => {
11
+ const testVariantsSync = createTestVariants.createTestVariantsSync(({ a, b, c }) => {
12
12
  });
13
13
  const args = {
14
14
  a: [1, 2],
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@flemist/test-variants",
3
- "version": "0.0.0",
3
+ "version": "0.0.3",
4
4
  "description": "Runs a test function with all possible combinations of its parameters.",
5
5
  "main": "dist/node/index.cjs",
6
6
  "types": "dist/node/index.d.ts",
7
7
  "engines": {
8
- "yarn": "^1.22"
8
+ "node": ">=9.3.0",
9
+ "pnpm": "^7.1.6"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -18,82 +19,84 @@
18
19
  "enumeration",
19
20
  "helper"
20
21
  ],
21
- "author": "NikolayMakhonin",
22
- "license": "ISC",
22
+ "author": {
23
+ "name": "Nikolay Makhonin",
24
+ "url": "https://github.com/NikolayMakhonin/"
25
+ },
26
+ "license": "Unlimited Free",
23
27
  "bugs": {
24
28
  "url": "https://github.com/NikolayMakhonin/test-variants/issues"
25
29
  },
26
- "homepage": "https://github.com/NikolayMakhonin/test-variants#readme",
30
+ "homepage": "https://github.com/NikolayMakhonin/test-variants",
27
31
  "publishConfig": {
28
32
  "access": "public"
29
33
  },
30
- "scripts": {
31
- "prepublishOnly": "yarn build && yarn run test:mocha:ci && yarn run test:karma",
32
- "lint": "eslint \"./src/**/*.{ts,js,cjs,mjs}\"",
33
- "lint:fix": "eslint --fix \"./src/**/*.{ts,js,cjs,mjs}\"",
34
- "build:js": "rollup -c && cpy \"**/assets/**\" \"../dist/\" --parents --cwd=src",
35
- "build:types": "tsc --outDir dist/node --declaration",
36
- "build": "rimraf dist && yarn run build:js && yarn run build:types",
37
- "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/\"",
38
- "coverage:check": "yarn run coverage:merge && nyc check-coverage --report-dir tmp/coverage/all/lcov --lines 50 --functions 50 --branches 50 --statements 50",
39
- "test:mocha": "mocha ./src/**/*.test.ts",
40
- "test:mocha:coverage": "rimraf tmp/coverage/mocha && nyc --all mocha ./src/**/*.test.ts",
41
- "test:mocha:watch": "mocha --watch ./src/**/*.test.ts",
42
- "test:karma": "rimraf tmp/coverage/karma && karma start --single-run --log-level debug",
43
- "test:mocha:ci": "rimraf tmp/coverage/mocha && nyc --all mocha ./src/**/*.test.ts ./dist/**/*.test.cjs",
44
- "coveralls": "yarn run coverage:check && nyc report --reporter=text-lcov --temp-dir \"tmp/coverage/merge/\" | coveralls"
45
- },
46
34
  "devDependencies": {
47
- "@babel/core": "^7.18.0",
35
+ "@babel/core": "^7.18.5",
48
36
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
49
- "@babel/plugin-transform-classes": "^7.17.12",
50
- "@babel/plugin-transform-runtime": "^7.18.0",
51
- "@babel/preset-env": "^7.18.0",
52
- "@babel/runtime-corejs3": "^7.18.0",
37
+ "@babel/plugin-transform-classes": "^7.18.4",
38
+ "@babel/plugin-transform-runtime": "^7.18.5",
39
+ "@babel/preset-env": "^7.18.2",
40
+ "@babel/runtime-corejs3": "^7.18.3",
53
41
  "@flemist/copy-glob-flat": "^0.0.5",
54
42
  "@flemist/karma-custom-launcher": "^0.0.0",
55
43
  "@rollup/plugin-alias": "^3.1.9",
56
44
  "@rollup/plugin-babel": "^5.3.1",
57
- "@rollup/plugin-commonjs": "^21.0.3",
45
+ "@rollup/plugin-commonjs": "^22.0.0",
58
46
  "@rollup/plugin-inject": "^4.0.4",
59
47
  "@rollup/plugin-json": "^4.1.0",
60
48
  "@rollup/plugin-multi-entry": "^4.1.0",
61
- "@rollup/plugin-node-resolve": "^13.1.3",
49
+ "@rollup/plugin-node-resolve": "^13.3.0",
62
50
  "@rollup/plugin-replace": "^4.0.0",
63
- "@rollup/plugin-typescript": "^8.3.1",
51
+ "@rollup/plugin-typescript": "^8.3.3",
64
52
  "@types/assert": "^1.5.6",
65
53
  "@types/fs-extra": "^9.0.13",
66
- "@types/mocha": "^9.1.0",
67
- "@types/node": "^17.0.23",
68
- "@typescript-eslint/eslint-plugin": "^5.17.0",
69
- "@typescript-eslint/parser": "^5.17.0",
70
- "cpy-cli": "^3.1.1",
71
- "eslint": "^8.12.0",
72
- "eslint-config-pro": "^2.1.1",
73
- "fs-extra": "^10.0.1",
54
+ "@types/mocha": "^9.1.1",
55
+ "@types/node": "^18.0.0",
56
+ "cpy-cli": "^4.1.0",
57
+ "eslint": "^8.17.0",
58
+ "eslint-config-pro": "^3.0.12",
59
+ "fs-extra": "^10.1.0",
74
60
  "globby": "^11.1.0",
75
- "karma": "^6.3.20",
61
+ "karma": "^6.4.0",
76
62
  "karma-chrome-launcher": "^3.1.1",
77
63
  "karma-coverage": "^2.2.0",
78
64
  "karma-firefox-launcher": "^2.1.2",
79
65
  "karma-mocha": "^2.0.1",
80
66
  "karma-safari-launcher": "^1.0.0",
81
67
  "mocha": "^9.2.2",
82
- "nodemon": "^2.0.15",
68
+ "nodemon": "^2.0.16",
83
69
  "nyc": "^15.1.0",
84
70
  "rdtsc": "^2.0.0",
85
71
  "rimraf": "^3.0.2",
86
- "rollup": "^2.70.1",
72
+ "rollup": "^2.75.6",
87
73
  "rollup-plugin-delete": "^2.0.0",
88
74
  "rollup-plugin-istanbul": "^3.0.0",
89
75
  "rollup-plugin-multi-input": "^1.3.1",
90
76
  "rollup-plugin-node-polyfills": "^0.2.1",
91
77
  "rollup-plugin-terser": "^7.0.2",
92
- "ts-node": "^10.7.0",
93
- "tsconfig-paths": "^3.14.1",
94
- "typescript": "^4.6.4"
78
+ "ts-node": "^10.8.1",
79
+ "tsconfig-paths": "^4.0.0",
80
+ "typescript": "^4.7.3"
95
81
  },
96
82
  "dependencies": {
97
- "tslib": "^2.3.1"
83
+ "tslib": "^2.4.0"
84
+ },
85
+ "scripts": {
86
+ "audit": "pnpm audit --prod",
87
+ "lint": "eslint ./**/*.{js,cjs,mjs,ts,tsx}",
88
+ "lint:fix": "eslint --fix ./**/*.{js,cjs,mjs,ts,tsx}",
89
+ "lint:wizard": "eslint-nibble --cache --multi ./**/*.{js,cjs,mjs,ts,tsx}",
90
+ "build:js": "rollup -c && cpy \"**/assets/**\" \"../dist/\" --parents --cwd=src",
91
+ "build:types": "tsc --outDir dist/node --declaration",
92
+ "build": "rimraf dist && pnpm run build:js && pnpm run build:types",
93
+ "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/\"",
94
+ "coverage:check": "pnpm run coverage:merge && nyc check-coverage --report-dir tmp/coverage/all/lcov --lines 50 --functions 50 --branches 50 --statements 50",
95
+ "test:mocha": "mocha ./src/**/*.test.*",
96
+ "test:mocha:coverage": "rimraf tmp/coverage/mocha && nyc --all mocha ./src/**/*.test.*",
97
+ "test:mocha:watch": "mocha --watch ./src/**/*.test.*",
98
+ "test:karma": "rimraf tmp/coverage/karma && karma start --single-run --log-level debug",
99
+ "test:mocha:ci": "rimraf tmp/coverage/mocha && nyc --all mocha ./{src,dist/node}/**/*.test.*",
100
+ "coveralls": "pnpm run coverage:check && nyc report --reporter=text-lcov --temp-dir \"tmp/coverage/merge/\" | coveralls"
98
101
  }
99
- }
102
+ }