@vitest/utils 0.29.6 → 0.29.8
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/helpers.js +19 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/dist/helpers.js
CHANGED
@@ -62,8 +62,25 @@ function clone(val, seen) {
|
|
62
62
|
out = Object.create(Object.getPrototypeOf(val));
|
63
63
|
seen.set(val, out);
|
64
64
|
const props = getOwnProperties(val);
|
65
|
-
for (const k2 of props)
|
66
|
-
|
65
|
+
for (const k2 of props) {
|
66
|
+
const descriptor = Object.getOwnPropertyDescriptor(val, k2);
|
67
|
+
if (!descriptor)
|
68
|
+
continue;
|
69
|
+
const cloned = clone(val[k2], seen);
|
70
|
+
if ("get" in descriptor) {
|
71
|
+
Object.defineProperty(out, k2, {
|
72
|
+
...descriptor,
|
73
|
+
get() {
|
74
|
+
return cloned;
|
75
|
+
}
|
76
|
+
});
|
77
|
+
} else {
|
78
|
+
Object.defineProperty(out, k2, {
|
79
|
+
...descriptor,
|
80
|
+
value: cloned
|
81
|
+
});
|
82
|
+
}
|
83
|
+
}
|
67
84
|
return out;
|
68
85
|
}
|
69
86
|
return val;
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export { assertTypes, clone, createDefer, deepClone, getOwnProperties, getType, isObject, noop, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, MergeInsertions, MutableArray, Nullable } from './types.js';
|
3
3
|
import { PrettyFormatOptions } from 'pretty-format';
|
4
|
+
import util from 'util';
|
4
5
|
|
5
6
|
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
6
7
|
maxLength?: number;
|
@@ -20,7 +21,8 @@ declare function setSafeTimers(): void;
|
|
20
21
|
declare function shuffle<T>(array: T[], seed?: number): T[];
|
21
22
|
|
22
23
|
declare function format(...args: any[]): string;
|
23
|
-
declare function
|
24
|
+
declare function utilInspect(item: unknown, options?: util.InspectOptions): string;
|
25
|
+
declare function loupeInspect(obj: unknown): string;
|
24
26
|
declare function objDisplay(obj: unknown): string;
|
25
27
|
|
26
28
|
declare const SAFE_TIMERS_SYMBOL: unique symbol;
|
@@ -76,4 +78,4 @@ interface ErrorOptions {
|
|
76
78
|
*/
|
77
79
|
declare function createSimpleStackTrace(options?: ErrorOptions): string;
|
78
80
|
|
79
|
-
export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers,
|
81
|
+
export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, loupeInspect, objDisplay, setSafeTimers, setupColors, shuffle, stringify, utilInspect };
|
package/dist/index.js
CHANGED
@@ -111,7 +111,10 @@ const loupe = typeof loupeImport.default === "function" ? loupeImport.default :
|
|
111
111
|
function format(...args) {
|
112
112
|
return util.format(...args);
|
113
113
|
}
|
114
|
-
function
|
114
|
+
function utilInspect(item, options) {
|
115
|
+
return util.inspect(item, options);
|
116
|
+
}
|
117
|
+
function loupeInspect(obj) {
|
115
118
|
return loupe(obj, {
|
116
119
|
depth: 2,
|
117
120
|
truncate: 40
|
@@ -119,7 +122,7 @@ function inspect(obj) {
|
|
119
122
|
}
|
120
123
|
function objDisplay(obj) {
|
121
124
|
const truncateThreshold = 40;
|
122
|
-
const str =
|
125
|
+
const str = loupeInspect(obj);
|
123
126
|
const type = Object.prototype.toString.call(obj);
|
124
127
|
if (str.length >= truncateThreshold) {
|
125
128
|
if (type === "[object Function]") {
|
@@ -222,4 +225,4 @@ function createSimpleStackTrace(options) {
|
|
222
225
|
return stackTrace;
|
223
226
|
}
|
224
227
|
|
225
|
-
export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers,
|
228
|
+
export { SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, loupeInspect, objDisplay, setSafeTimers, setupColors, shuffle, stringify, utilInspect };
|