@naturalcycles/js-lib 14.168.0 → 14.168.2
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/error/assert.js +12 -14
- package/dist/string/stringifyAny.js +1 -1
- package/dist-esm/error/assert.js +12 -14
- package/dist-esm/string/stringifyAny.js +1 -1
- package/package.json +1 -1
- package/src/error/assert.ts +14 -14
- package/src/string/stringifyAny.ts +1 -1
package/dist/error/assert.js
CHANGED
|
@@ -36,13 +36,10 @@ exports._assert = _assert;
|
|
|
36
36
|
*/
|
|
37
37
|
function _assertEquals(actual, expected, message, errorData) {
|
|
38
38
|
if (actual !== expected) {
|
|
39
|
-
const msg =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join('\n');
|
|
39
|
+
const msg = message ||
|
|
40
|
+
['not equal', `expected: ${(0, __1._stringifyAny)(expected)}`, `got : ${(0, __1._stringifyAny)(actual)}`]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join('\n');
|
|
46
43
|
throw new AssertionError(msg, {
|
|
47
44
|
userFriendly: true,
|
|
48
45
|
...errorData,
|
|
@@ -58,13 +55,14 @@ exports._assertEquals = _assertEquals;
|
|
|
58
55
|
*/
|
|
59
56
|
function _assertDeepEquals(actual, expected, message, errorData) {
|
|
60
57
|
if (!(0, __1._deepEquals)(actual, expected)) {
|
|
61
|
-
const msg =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
const msg = message ||
|
|
59
|
+
[
|
|
60
|
+
`not deeply equal`,
|
|
61
|
+
`expected: ${(0, __1._stringifyAny)(expected)}`,
|
|
62
|
+
`got : ${(0, __1._stringifyAny)(actual)}`,
|
|
63
|
+
]
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join('\n');
|
|
68
66
|
throw new AssertionError(msg, {
|
|
69
67
|
userFriendly: true,
|
|
70
68
|
...errorData,
|
|
@@ -78,7 +78,7 @@ function _stringifyAny(obj, opt = {}) {
|
|
|
78
78
|
// Error that has no `data`, but has `code` property
|
|
79
79
|
s += `\ncode: ${obj.code}`;
|
|
80
80
|
}
|
|
81
|
-
if (opt.includeErrorData && (0, error_util_1._isErrorObject)(obj)) {
|
|
81
|
+
if (opt.includeErrorData && (0, error_util_1._isErrorObject)(obj) && Object.keys(obj.data).length) {
|
|
82
82
|
s += '\n' + _stringifyAny(obj.data, opt);
|
|
83
83
|
}
|
|
84
84
|
if (opt.includeErrorStack && obj.stack) {
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -29,13 +29,10 @@ message, errorData) {
|
|
|
29
29
|
*/
|
|
30
30
|
export function _assertEquals(actual, expected, message, errorData) {
|
|
31
31
|
if (actual !== expected) {
|
|
32
|
-
const msg =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
]
|
|
37
|
-
.filter(Boolean)
|
|
38
|
-
.join('\n');
|
|
32
|
+
const msg = message ||
|
|
33
|
+
['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('\n');
|
|
39
36
|
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -47,13 +44,14 @@ export function _assertEquals(actual, expected, message, errorData) {
|
|
|
47
44
|
*/
|
|
48
45
|
export function _assertDeepEquals(actual, expected, message, errorData) {
|
|
49
46
|
if (!_deepEquals(actual, expected)) {
|
|
50
|
-
const msg =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
const msg = message ||
|
|
48
|
+
[
|
|
49
|
+
`not deeply equal`,
|
|
50
|
+
`expected: ${_stringifyAny(expected)}`,
|
|
51
|
+
`got : ${_stringifyAny(actual)}`,
|
|
52
|
+
]
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.join('\n');
|
|
57
55
|
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
58
56
|
}
|
|
59
57
|
}
|
|
@@ -74,7 +74,7 @@ export function _stringifyAny(obj, opt = {}) {
|
|
|
74
74
|
// Error that has no `data`, but has `code` property
|
|
75
75
|
s += `\ncode: ${obj.code}`;
|
|
76
76
|
}
|
|
77
|
-
if (opt.includeErrorData && _isErrorObject(obj)) {
|
|
77
|
+
if (opt.includeErrorData && _isErrorObject(obj) && Object.keys(obj.data).length) {
|
|
78
78
|
s += '\n' + _stringifyAny(obj.data, opt);
|
|
79
79
|
}
|
|
80
80
|
if (opt.includeErrorStack && obj.stack) {
|
package/package.json
CHANGED
package/src/error/assert.ts
CHANGED
|
@@ -43,13 +43,11 @@ export function _assertEquals<T>(
|
|
|
43
43
|
errorData?: ErrorData,
|
|
44
44
|
): asserts actual is T {
|
|
45
45
|
if (actual !== expected) {
|
|
46
|
-
const msg =
|
|
47
|
-
message ||
|
|
48
|
-
`expected: ${_stringifyAny(expected)}`,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.filter(Boolean)
|
|
52
|
-
.join('\n')
|
|
46
|
+
const msg =
|
|
47
|
+
message ||
|
|
48
|
+
['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.join('\n')
|
|
53
51
|
|
|
54
52
|
throw new AssertionError(msg, {
|
|
55
53
|
userFriendly: true,
|
|
@@ -71,13 +69,15 @@ export function _assertDeepEquals<T>(
|
|
|
71
69
|
errorData?: ErrorData,
|
|
72
70
|
): asserts actual is T {
|
|
73
71
|
if (!_deepEquals(actual, expected)) {
|
|
74
|
-
const msg =
|
|
75
|
-
message ||
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
const msg =
|
|
73
|
+
message ||
|
|
74
|
+
[
|
|
75
|
+
`not deeply equal`,
|
|
76
|
+
`expected: ${_stringifyAny(expected)}`,
|
|
77
|
+
`got : ${_stringifyAny(actual)}`,
|
|
78
|
+
]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join('\n')
|
|
81
81
|
|
|
82
82
|
throw new AssertionError(msg, {
|
|
83
83
|
userFriendly: true,
|
|
@@ -122,7 +122,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
|
|
|
122
122
|
s += `\ncode: ${(obj as any).code}`
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
if (opt.includeErrorData && _isErrorObject(obj)) {
|
|
125
|
+
if (opt.includeErrorData && _isErrorObject(obj) && Object.keys(obj.data).length) {
|
|
126
126
|
s += '\n' + _stringifyAny(obj.data, opt)
|
|
127
127
|
}
|
|
128
128
|
|