validno 0.2.3 → 0.2.4
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/ValidnoResult.js +11 -1
- package/dist/dev.js +41 -81
- package/dist/utils/errors.js +6 -2
- package/dist/utils/helpers.js +32 -11
- package/dist/utils/validations.js +42 -16
- package/dist/validate.js +16 -17
- package/package.json +1 -1
- package/.eslintrc.cjs +0 -13
- package/.eslintrc.json +0 -16
- package/jest.config.ts +0 -199
package/dist/ValidnoResult.js
CHANGED
|
@@ -8,7 +8,6 @@ class ValidnoResult {
|
|
|
8
8
|
this.errors = (results === null || results === void 0 ? void 0 : results.errors) || [];
|
|
9
9
|
this.byKeys = (results === null || results === void 0 ? void 0 : results.byKeys) || {};
|
|
10
10
|
this.errorsByKeys = (results === null || results === void 0 ? void 0 : results.errorsByKeys) || {};
|
|
11
|
-
this.byKeys = (results === null || results === void 0 ? void 0 : results.byKeys) || {};
|
|
12
11
|
}
|
|
13
12
|
setKeyStatus(key, result) {
|
|
14
13
|
this.byKeys[key] = result;
|
|
@@ -76,5 +75,16 @@ class ValidnoResult {
|
|
|
76
75
|
this.clearEmptyErrorsByKeys();
|
|
77
76
|
return this;
|
|
78
77
|
}
|
|
78
|
+
data() {
|
|
79
|
+
return {
|
|
80
|
+
ok: this.ok,
|
|
81
|
+
missed: this.missed,
|
|
82
|
+
failed: this.failed,
|
|
83
|
+
passed: this.passed,
|
|
84
|
+
errors: this.errors,
|
|
85
|
+
byKeys: this.byKeys,
|
|
86
|
+
errorsByKeys: this.errorsByKeys,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
79
89
|
}
|
|
80
90
|
export default ValidnoResult;
|
package/dist/dev.js
CHANGED
|
@@ -1,91 +1,51 @@
|
|
|
1
1
|
import { Schema } from "./Schema.js";
|
|
2
2
|
const validateConfig = (cfg) => {
|
|
3
3
|
const cfgSchema = new Schema({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type:
|
|
11
|
-
required:
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type: Object,
|
|
15
|
-
required: false,
|
|
16
|
-
},
|
|
17
|
-
getAll: {
|
|
18
|
-
type: Object,
|
|
19
|
-
required: false,
|
|
20
|
-
},
|
|
21
|
-
update: {
|
|
22
|
-
type: Object,
|
|
23
|
-
required: false,
|
|
24
|
-
},
|
|
25
|
-
delete: {
|
|
26
|
-
type: Object,
|
|
27
|
-
required: false,
|
|
28
|
-
},
|
|
29
|
-
deleteMany: {
|
|
30
|
-
type: Object,
|
|
31
|
-
required: false,
|
|
32
|
-
},
|
|
33
|
-
export: {
|
|
34
|
-
type: Object,
|
|
35
|
-
required: false,
|
|
36
|
-
},
|
|
37
|
-
distinct: {
|
|
38
|
-
type: Object,
|
|
39
|
-
required: false,
|
|
40
|
-
},
|
|
41
|
-
custom: {
|
|
42
|
-
type: Array,
|
|
43
|
-
required: false,
|
|
44
|
-
rules: {},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
4
|
+
str1: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true
|
|
7
|
+
},
|
|
8
|
+
str2: {
|
|
9
|
+
deep1: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
47
14
|
});
|
|
48
15
|
const res = cfgSchema.validate(cfg);
|
|
49
16
|
console.log(res);
|
|
50
|
-
if (res.ok !== true) {
|
|
51
|
-
const errorsMsg = res.errors.join('; ');
|
|
52
|
-
throw new Error(errorsMsg);
|
|
53
|
-
}
|
|
54
17
|
};
|
|
55
18
|
const uniTestService = {
|
|
56
|
-
|
|
57
|
-
getAll: {
|
|
58
|
-
isActive: true,
|
|
59
|
-
sort: {
|
|
60
|
-
default: 'createdAt',
|
|
61
|
-
},
|
|
62
|
-
search: {
|
|
63
|
-
fields: ['title'],
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
export: {
|
|
67
|
-
isActive: false,
|
|
68
|
-
},
|
|
69
|
-
get: {
|
|
70
|
-
isActive: true,
|
|
71
|
-
},
|
|
72
|
-
create: null,
|
|
73
|
-
createMany: {
|
|
74
|
-
isActive: true,
|
|
75
|
-
},
|
|
76
|
-
update: {
|
|
77
|
-
isActive: true,
|
|
78
|
-
},
|
|
79
|
-
delete: {
|
|
80
|
-
isActive: true,
|
|
81
|
-
},
|
|
82
|
-
deleteMany: {
|
|
83
|
-
isActive: true,
|
|
84
|
-
},
|
|
85
|
-
distinct: {
|
|
86
|
-
isActive: true,
|
|
87
|
-
fields: ['title', '_id'],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
19
|
+
str1: 'xxxx'
|
|
90
20
|
};
|
|
91
21
|
validateConfig(uniTestService);
|
|
22
|
+
console.log(uniTestService);
|
|
23
|
+
console.log(uniTestService);
|
|
24
|
+
const obj = {
|
|
25
|
+
top: {
|
|
26
|
+
mid1: {
|
|
27
|
+
low1a: false,
|
|
28
|
+
low1b: false
|
|
29
|
+
},
|
|
30
|
+
mid2: {
|
|
31
|
+
low2a: false
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
top2: false
|
|
35
|
+
};
|
|
36
|
+
const setNestedValue = (linkedObj, keysLevels, curLevel, valueToSet) => {
|
|
37
|
+
const lvKey = keysLevels[curLevel];
|
|
38
|
+
if (curLevel < keysLevels.length - 1) {
|
|
39
|
+
if (!linkedObj[lvKey] || typeof linkedObj[lvKey] !== 'object') {
|
|
40
|
+
linkedObj[lvKey] = {};
|
|
41
|
+
}
|
|
42
|
+
return setNestedValue(linkedObj[lvKey], keysLevels, curLevel + 1, valueToSet);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
linkedObj[lvKey] = valueToSet;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const setDeepValue = (obj, keysChain, valueToSet) => {
|
|
49
|
+
const keysLevels = keysChain.split('.');
|
|
50
|
+
setNestedValue(obj, keysLevels, 0, valueToSet);
|
|
51
|
+
};
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _errors = {};
|
|
2
|
-
_errors.getMissingError = (key) =>
|
|
2
|
+
_errors.getMissingError = (key = 'na') => `Отсутствует значение '${key}'`;
|
|
3
3
|
_errors.getErrorDetails = (key, expectedType, receivedValue) => {
|
|
4
4
|
var _a;
|
|
5
5
|
let receivedType = '';
|
|
@@ -9,7 +9,11 @@ _errors.getErrorDetails = (key, expectedType, receivedValue) => {
|
|
|
9
9
|
receivedType = 'null';
|
|
10
10
|
else
|
|
11
11
|
receivedType = ((_a = receivedValue.constructor) === null || _a === void 0 ? void 0 : _a.name) || typeof receivedValue || 'na';
|
|
12
|
-
|
|
12
|
+
const expectedOutput = (expectedType === null || expectedType === void 0 ? void 0 : expectedType.name) || expectedType;
|
|
13
|
+
const receivedOutput = receivedType || 'na';
|
|
14
|
+
if (String(expectedOutput) === String(receivedOutput))
|
|
15
|
+
return '';
|
|
16
|
+
return `Проверьте тип '${key}': ожидался ${expectedOutput}, получен ${receivedOutput}`;
|
|
13
17
|
};
|
|
14
18
|
_errors.joinErrors = (errorsArr, separator = '; ') => {
|
|
15
19
|
return (errorsArr === null || errorsArr === void 0 ? void 0 : errorsArr.join(`${separator}`)) || '';
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defaultSchemaKeys } from "../Schema.js";
|
|
2
|
-
import ValidnoResult from "../ValidnoResult.js";
|
|
3
2
|
import _validations from "./validations.js";
|
|
4
3
|
const _helpers = {};
|
|
5
4
|
_helpers.checkIsNested = (obj) => {
|
|
@@ -13,16 +12,6 @@ _helpers.checkIsNested = (obj) => {
|
|
|
13
12
|
return true;
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
|
-
_helpers.mergeResults = (resultsOld, resultsNew) => {
|
|
17
|
-
const output = new ValidnoResult();
|
|
18
|
-
output.failed = [...resultsOld.failed, ...resultsNew.failed];
|
|
19
|
-
output.errors = [...resultsOld.errors, ...resultsNew.errors];
|
|
20
|
-
output.missed = [...resultsOld.missed, ...resultsNew.missed];
|
|
21
|
-
output.passed = [...resultsOld.passed, ...resultsNew.passed];
|
|
22
|
-
output.byKeys = Object.assign(Object.assign({}, resultsOld.byKeys), resultsNew.byKeys);
|
|
23
|
-
output.errorsByKeys = Object.assign(Object.assign({}, resultsOld.errorsByKeys), resultsNew.errorsByKeys);
|
|
24
|
-
return output;
|
|
25
|
-
};
|
|
26
15
|
_helpers.checkNestedIsMissing = (reqs, data) => {
|
|
27
16
|
const isRequired = reqs.required;
|
|
28
17
|
const isUndef = data === undefined;
|
|
@@ -45,4 +34,36 @@ _helpers.hasMissing = (input) => {
|
|
|
45
34
|
const missingData = (data === undefined || key in data === false || data[key] === undefined);
|
|
46
35
|
return isRequired && missingData;
|
|
47
36
|
};
|
|
37
|
+
_helpers.compareArrs = (v1, v2) => {
|
|
38
|
+
if (v1.length !== v2.length)
|
|
39
|
+
return false;
|
|
40
|
+
return v1.every((el, i) => {
|
|
41
|
+
if (_validations.isObject(el)) {
|
|
42
|
+
return JSON.stringify(el) === JSON.stringify(v2[i]);
|
|
43
|
+
}
|
|
44
|
+
return v2[i] === el;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
_helpers.compareObjs = (obj1, obj2) => {
|
|
48
|
+
function deepEqual(obj1, obj2) {
|
|
49
|
+
if (obj1 === obj2) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const keys1 = Object.keys(obj1);
|
|
56
|
+
const keys2 = Object.keys(obj2);
|
|
57
|
+
if (keys1.length !== keys2.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
for (let key of keys1) {
|
|
61
|
+
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return deepEqual(obj1, obj2);
|
|
68
|
+
};
|
|
48
69
|
export default _helpers;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _helpers from "./helpers.js";
|
|
1
2
|
const _validations = {};
|
|
2
3
|
_validations.isString = (value) => {
|
|
3
4
|
return typeof value === 'string';
|
|
@@ -73,37 +74,55 @@ _validations.lengthMax = (value, max) => {
|
|
|
73
74
|
_validations.isNumberGte = (value, gte) => {
|
|
74
75
|
return typeof value === 'number' && value >= gte;
|
|
75
76
|
};
|
|
77
|
+
_validations.isNumberGt = (value, gt) => {
|
|
78
|
+
return typeof value === 'number' && value > gt;
|
|
79
|
+
};
|
|
76
80
|
_validations.isNumberLte = (value, lte) => {
|
|
77
81
|
return typeof value === 'number' && value <= lte;
|
|
78
82
|
};
|
|
83
|
+
_validations.isNumberLt = (value, lt) => {
|
|
84
|
+
return typeof value === 'number' && value < lt;
|
|
85
|
+
};
|
|
86
|
+
_validations.isDateGte = (date1, date2) => {
|
|
87
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return date1 >= date2;
|
|
91
|
+
};
|
|
92
|
+
_validations.isDateGt = (date1, date2) => {
|
|
93
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return date1 > date2;
|
|
97
|
+
};
|
|
98
|
+
_validations.isDateLte = (date1, date2) => {
|
|
99
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return date1 <= date2;
|
|
103
|
+
};
|
|
104
|
+
_validations.isDateLt = (date1, date2) => {
|
|
105
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return date1 < date2;
|
|
109
|
+
};
|
|
79
110
|
_validations.hasKey = (obj, key) => {
|
|
80
111
|
if (_validations.isObject(obj) === false)
|
|
81
112
|
return false;
|
|
82
113
|
return key in obj;
|
|
83
114
|
};
|
|
84
|
-
const compareArrs = (v1, v2) => {
|
|
85
|
-
if (v1.length !== v2.length)
|
|
86
|
-
return false;
|
|
87
|
-
return v1.every((el, i) => {
|
|
88
|
-
if (_validations.isObject(el)) {
|
|
89
|
-
return JSON.stringify(el) === JSON.stringify(v2[i]);
|
|
90
|
-
}
|
|
91
|
-
return v2[i] === el;
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
115
|
_validations.is = (value, compareTo) => {
|
|
95
116
|
if (value === compareTo) {
|
|
96
117
|
return true;
|
|
97
118
|
}
|
|
98
119
|
const bothArrays = _validations.isArray(value) && _validations.isArray(compareTo);
|
|
99
120
|
if (bothArrays) {
|
|
100
|
-
return compareArrs(value, compareTo);
|
|
121
|
+
return _helpers.compareArrs(value, compareTo);
|
|
101
122
|
}
|
|
102
123
|
const bothObjects = _validations.isObject(value) && _validations.isObject(compareTo);
|
|
103
124
|
if (bothObjects) {
|
|
104
|
-
|
|
105
|
-
const compareToStr = JSON.stringify(compareTo);
|
|
106
|
-
return valueStr === compareToStr;
|
|
125
|
+
return _helpers.compareObjs(value, compareTo);
|
|
107
126
|
}
|
|
108
127
|
const bothDates = _validations.isDate(value) && _validations.isDate(compareTo);
|
|
109
128
|
if (bothDates) {
|
|
@@ -114,14 +133,21 @@ _validations.is = (value, compareTo) => {
|
|
|
114
133
|
_validations.not = (value, not) => {
|
|
115
134
|
return !_validations.is(value, not);
|
|
116
135
|
};
|
|
117
|
-
_validations.isNot = _validations.not;
|
|
118
|
-
_validations.ne = _validations.not;
|
|
119
136
|
_validations.regexTested = (value, regexp) => {
|
|
120
137
|
if (!regexp || regexp instanceof RegExp !== true) {
|
|
121
138
|
throw new Error('regexp argument is incorrect');
|
|
122
139
|
}
|
|
123
140
|
return regexp.test(value);
|
|
124
141
|
};
|
|
142
|
+
_validations.gt = _validations.isNumberGt;
|
|
143
|
+
_validations.gte = _validations.isNumberGte;
|
|
144
|
+
_validations.lte = _validations.isNumberLte;
|
|
145
|
+
_validations.lt = _validations.isNumberLt;
|
|
146
|
+
_validations.eq = _validations.is;
|
|
147
|
+
_validations.isNot = _validations.not;
|
|
148
|
+
_validations.ne = _validations.not;
|
|
149
|
+
_validations.neq = _validations.not;
|
|
150
|
+
_validations.regexpTested = _validations.regexpTested;
|
|
125
151
|
_validations.regex = _validations.regexTested;
|
|
126
152
|
_validations.regexp = _validations.regexTested;
|
|
127
153
|
_validations.test = _validations.regexTested;
|
package/dist/validate.js
CHANGED
|
@@ -5,21 +5,20 @@ import _helpers from "./utils/helpers.js";
|
|
|
5
5
|
import { ErrorKeywords } from "./constants/details.js";
|
|
6
6
|
import ValidnoResult from "./ValidnoResult.js";
|
|
7
7
|
function generateMsg(input) {
|
|
8
|
-
let {
|
|
8
|
+
let { key, deepKey, data, reqs } = input;
|
|
9
9
|
const keyForMsg = deepKey || key;
|
|
10
10
|
const keyTitle = 'title' in reqs ? reqs.title : keyForMsg;
|
|
11
|
-
if (reqs.customMessage
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return _errors.getMissingError(keyForMsg);
|
|
11
|
+
if (!reqs.customMessage)
|
|
12
|
+
return _errors.getMissingError(keyForMsg);
|
|
13
|
+
const errMsg = reqs.customMessage({
|
|
14
|
+
keyword: ErrorKeywords.Missing,
|
|
15
|
+
value: data[key],
|
|
16
|
+
key: keyForMsg,
|
|
17
|
+
title: keyTitle,
|
|
18
|
+
reqs: reqs,
|
|
19
|
+
schema: this.schema
|
|
20
|
+
});
|
|
21
|
+
return errMsg;
|
|
23
22
|
}
|
|
24
23
|
function handleDeepKey(input) {
|
|
25
24
|
const { results, key, deepKey, data, reqs } = input;
|
|
@@ -98,7 +97,7 @@ export function handleKey(input) {
|
|
|
98
97
|
return results.finish();
|
|
99
98
|
}
|
|
100
99
|
function validate(schema, data, keysToCheck) {
|
|
101
|
-
const
|
|
100
|
+
const output = new ValidnoResult();
|
|
102
101
|
const hasKeysToCheck = _helpers.areKeysLimited(keysToCheck);
|
|
103
102
|
const schemaKeys = Object.entries(schema.schema);
|
|
104
103
|
for (const [key, reqs] of schemaKeys) {
|
|
@@ -106,10 +105,10 @@ function validate(schema, data, keysToCheck) {
|
|
|
106
105
|
if (!toBeValidated)
|
|
107
106
|
continue;
|
|
108
107
|
const keyResult = handleKey.call(this, { key, data, reqs });
|
|
109
|
-
|
|
108
|
+
output.merge(keyResult);
|
|
110
109
|
}
|
|
111
|
-
|
|
112
|
-
return
|
|
110
|
+
output.finish();
|
|
111
|
+
return output;
|
|
113
112
|
}
|
|
114
113
|
;
|
|
115
114
|
export default validate;
|
package/package.json
CHANGED
package/.eslintrc.cjs
DELETED
package/.eslintrc.json
DELETED
package/jest.config.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {Config} from 'jest';
|
|
7
|
-
|
|
8
|
-
const config: Config = {
|
|
9
|
-
// All imported modules in your tests should be mocked automatically
|
|
10
|
-
// automock: false,
|
|
11
|
-
|
|
12
|
-
// Stop running tests after `n` failures
|
|
13
|
-
// bail: 0,
|
|
14
|
-
|
|
15
|
-
// The directory where Jest should store its cached dependency information
|
|
16
|
-
// cacheDirectory: "C:\\Users\\lesha\\AppData\\Local\\Temp\\jest",
|
|
17
|
-
|
|
18
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
19
|
-
clearMocks: true,
|
|
20
|
-
|
|
21
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
22
|
-
collectCoverage: false,
|
|
23
|
-
|
|
24
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
25
|
-
// collectCoverageFrom: undefined,
|
|
26
|
-
|
|
27
|
-
// The directory where Jest should output its coverage files
|
|
28
|
-
coverageDirectory: "coverage",
|
|
29
|
-
|
|
30
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
31
|
-
// coveragePathIgnorePatterns: [
|
|
32
|
-
// "\\\\node_modules\\\\"
|
|
33
|
-
// ],
|
|
34
|
-
|
|
35
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
36
|
-
coverageProvider: "v8",
|
|
37
|
-
|
|
38
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
39
|
-
// coverageReporters: [
|
|
40
|
-
// "json",
|
|
41
|
-
// "text",
|
|
42
|
-
// "lcov",
|
|
43
|
-
// "clover"
|
|
44
|
-
// ],
|
|
45
|
-
|
|
46
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
47
|
-
// coverageThreshold: undefined,
|
|
48
|
-
|
|
49
|
-
// A path to a custom dependency extractor
|
|
50
|
-
// dependencyExtractor: undefined,
|
|
51
|
-
|
|
52
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
53
|
-
// errorOnDeprecated: false,
|
|
54
|
-
|
|
55
|
-
// The default configuration for fake timers
|
|
56
|
-
// fakeTimers: {
|
|
57
|
-
// "enableGlobally": false
|
|
58
|
-
// },
|
|
59
|
-
|
|
60
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
61
|
-
// forceCoverageMatch: [],
|
|
62
|
-
|
|
63
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
64
|
-
// globalSetup: undefined,
|
|
65
|
-
|
|
66
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
67
|
-
// globalTeardown: undefined,
|
|
68
|
-
|
|
69
|
-
// A set of global variables that need to be available in all test environments
|
|
70
|
-
// globals: {},
|
|
71
|
-
|
|
72
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
73
|
-
// maxWorkers: "50%",
|
|
74
|
-
|
|
75
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
76
|
-
// moduleDirectories: [
|
|
77
|
-
// "node_modules"
|
|
78
|
-
// ],
|
|
79
|
-
|
|
80
|
-
// An array of file extensions your modules use
|
|
81
|
-
// moduleFileExtensions: [
|
|
82
|
-
// "js",
|
|
83
|
-
// "mjs",
|
|
84
|
-
// "cjs",
|
|
85
|
-
// "jsx",
|
|
86
|
-
// "ts",
|
|
87
|
-
// "tsx",
|
|
88
|
-
// "json",
|
|
89
|
-
// "node"
|
|
90
|
-
// ],
|
|
91
|
-
|
|
92
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
93
|
-
// moduleNameMapper: {},
|
|
94
|
-
|
|
95
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
96
|
-
// modulePathIgnorePatterns: [],
|
|
97
|
-
|
|
98
|
-
// Activates notifications for test results
|
|
99
|
-
// notify: false,
|
|
100
|
-
|
|
101
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
102
|
-
// notifyMode: "failure-change",
|
|
103
|
-
|
|
104
|
-
// A preset that is used as a base for Jest's configuration
|
|
105
|
-
// preset: undefined,
|
|
106
|
-
|
|
107
|
-
// Run tests from one or more projects
|
|
108
|
-
// projects: undefined,
|
|
109
|
-
|
|
110
|
-
// Use this configuration option to add custom reporters to Jest
|
|
111
|
-
// reporters: undefined,
|
|
112
|
-
|
|
113
|
-
// Automatically reset mock state before every test
|
|
114
|
-
// resetMocks: false,
|
|
115
|
-
|
|
116
|
-
// Reset the module registry before running each individual test
|
|
117
|
-
// resetModules: false,
|
|
118
|
-
|
|
119
|
-
// A path to a custom resolver
|
|
120
|
-
// resolver: undefined,
|
|
121
|
-
|
|
122
|
-
// Automatically restore mock state and implementation before every test
|
|
123
|
-
// restoreMocks: false,
|
|
124
|
-
|
|
125
|
-
// The root directory that Jest should scan for tests and modules within
|
|
126
|
-
// rootDir: undefined,
|
|
127
|
-
|
|
128
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
129
|
-
// roots: [
|
|
130
|
-
// "<rootDir>"
|
|
131
|
-
// ],
|
|
132
|
-
|
|
133
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
134
|
-
// runner: "jest-runner",
|
|
135
|
-
|
|
136
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
137
|
-
// setupFiles: [],
|
|
138
|
-
|
|
139
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
140
|
-
// setupFilesAfterEnv: [],
|
|
141
|
-
|
|
142
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
143
|
-
// slowTestThreshold: 5,
|
|
144
|
-
|
|
145
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
146
|
-
// snapshotSerializers: [],
|
|
147
|
-
|
|
148
|
-
// The test environment that will be used for testing
|
|
149
|
-
// testEnvironment: "jest-environment-node",
|
|
150
|
-
|
|
151
|
-
// Options that will be passed to the testEnvironment
|
|
152
|
-
// testEnvironmentOptions: {},
|
|
153
|
-
|
|
154
|
-
// Adds a location field to test results
|
|
155
|
-
// testLocationInResults: false,
|
|
156
|
-
|
|
157
|
-
// The glob patterns Jest uses to detect test files
|
|
158
|
-
// testMatch: [
|
|
159
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
160
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
161
|
-
// ],
|
|
162
|
-
|
|
163
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
164
|
-
// testPathIgnorePatterns: [
|
|
165
|
-
// "\\\\node_modules\\\\"
|
|
166
|
-
// ],
|
|
167
|
-
|
|
168
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
169
|
-
// testRegex: [],
|
|
170
|
-
|
|
171
|
-
// This option allows the use of a custom results processor
|
|
172
|
-
// testResultsProcessor: undefined,
|
|
173
|
-
|
|
174
|
-
// This option allows use of a custom test runner
|
|
175
|
-
// testRunner: "jest-circus/runner",
|
|
176
|
-
|
|
177
|
-
// A map from regular expressions to paths to transformers
|
|
178
|
-
// transform: undefined,
|
|
179
|
-
|
|
180
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
181
|
-
// transformIgnorePatterns: [
|
|
182
|
-
// "\\\\node_modules\\\\",
|
|
183
|
-
// "\\.pnp\\.[^\\\\]+$"
|
|
184
|
-
// ],
|
|
185
|
-
|
|
186
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
187
|
-
// unmockedModulePathPatterns: undefined,
|
|
188
|
-
|
|
189
|
-
// Indicates whether each individual test should be reported during the run
|
|
190
|
-
// verbose: undefined,
|
|
191
|
-
|
|
192
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
193
|
-
// watchPathIgnorePatterns: [],
|
|
194
|
-
|
|
195
|
-
// Whether to use watchman for file crawling
|
|
196
|
-
// watchman: true,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export default config;
|