@vitest/utils 2.0.2 → 2.0.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/chunk-display.js +1 -2
- package/dist/helpers.d.ts +11 -1
- package/dist/helpers.js +13 -1
- package/dist/index.d.ts +16 -30
- package/dist/index.js +3 -18
- package/package.json +2 -2
package/dist/chunk-display.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { format as format$1, plugins } from '@vitest/pretty-format';
|
2
1
|
import * as loupe from 'loupe';
|
2
|
+
import { format as format$1, plugins } from '@vitest/pretty-format';
|
3
3
|
|
4
4
|
const {
|
5
5
|
AsymmetricMatcher,
|
@@ -40,7 +40,6 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
40
40
|
}
|
41
41
|
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
42
42
|
}
|
43
|
-
|
44
43
|
const formatRegExp = /%[sdjifoOc%]/g;
|
45
44
|
function format(...args) {
|
46
45
|
if (typeof args[0] !== "string") {
|
package/dist/helpers.d.ts
CHANGED
@@ -3,6 +3,16 @@ import { Nullable, Arrayable } from './types.js';
|
|
3
3
|
interface CloneOptions {
|
4
4
|
forceWritable?: boolean;
|
5
5
|
}
|
6
|
+
interface ErrorOptions {
|
7
|
+
message?: string;
|
8
|
+
stackTraceLimit?: number;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Get original stacktrace without source map support the most performant way.
|
12
|
+
* - Create only 1 stack frame.
|
13
|
+
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
|
14
|
+
*/
|
15
|
+
declare function createSimpleStackTrace(options?: ErrorOptions): string;
|
6
16
|
declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
|
7
17
|
declare function assertTypes(value: unknown, name: string, types: string[]): void;
|
8
18
|
declare function isPrimitive(value: unknown): boolean;
|
@@ -33,4 +43,4 @@ declare function createDefer<T>(): DeferPromise<T>;
|
|
33
43
|
declare function getCallLastIndex(code: string): number | null;
|
34
44
|
declare function isNegativeNaN(val: number): boolean;
|
35
45
|
|
36
|
-
export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
46
|
+
export { type DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/helpers.js
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
function createSimpleStackTrace(options) {
|
2
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
3
|
+
const limit = Error.stackTraceLimit;
|
4
|
+
const prepareStackTrace = Error.prepareStackTrace;
|
5
|
+
Error.stackTraceLimit = stackTraceLimit;
|
6
|
+
Error.prepareStackTrace = (e) => e.stack;
|
7
|
+
const err = new Error(message);
|
8
|
+
const stackTrace = err.stack || "";
|
9
|
+
Error.prepareStackTrace = prepareStackTrace;
|
10
|
+
Error.stackTraceLimit = limit;
|
11
|
+
return stackTrace;
|
12
|
+
}
|
1
13
|
function notNullish(v) {
|
2
14
|
return v != null;
|
3
15
|
}
|
@@ -177,4 +189,4 @@ function isNegativeNaN(val) {
|
|
177
189
|
return isNegative;
|
178
190
|
}
|
179
191
|
|
180
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
192
|
+
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/index.d.ts
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
|
-
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
|
1
|
+
export { DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
3
2
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
4
3
|
import { Colors } from 'tinyrainbow';
|
4
|
+
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
setImmediate: any;
|
17
|
-
clearImmediate: any;
|
18
|
-
};
|
6
|
+
interface SafeTimers {
|
7
|
+
nextTick: (cb: () => void) => void;
|
8
|
+
setTimeout: typeof setTimeout;
|
9
|
+
setInterval: typeof setInterval;
|
10
|
+
clearInterval: typeof clearInterval;
|
11
|
+
clearTimeout: typeof clearTimeout;
|
12
|
+
setImmediate: typeof setImmediate;
|
13
|
+
clearImmediate: typeof clearImmediate;
|
14
|
+
}
|
15
|
+
declare function getSafeTimers(): SafeTimers;
|
19
16
|
declare function setSafeTimers(): void;
|
20
17
|
|
21
18
|
declare function shuffle<T>(array: T[], seed?: number): T[];
|
@@ -35,24 +32,13 @@ interface Options {
|
|
35
32
|
stylize: (value: string, styleType: string) => string;
|
36
33
|
}
|
37
34
|
type LoupeOptions = Partial<Options>;
|
35
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
36
|
+
maxLength?: number;
|
37
|
+
}): string;
|
38
38
|
declare function format(...args: unknown[]): string;
|
39
39
|
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
40
40
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
41
41
|
|
42
|
-
declare const SAFE_TIMERS_SYMBOL: unique symbol;
|
43
|
-
declare const SAFE_COLORS_SYMBOL: unique symbol;
|
44
|
-
|
45
|
-
interface ErrorOptions {
|
46
|
-
message?: string;
|
47
|
-
stackTraceLimit?: number;
|
48
|
-
}
|
49
|
-
/**
|
50
|
-
* Get original stacktrace without source map support the most performant way.
|
51
|
-
* - Create only 1 stack frame.
|
52
|
-
* - Rewrite prepareStackTrace to bypass "support-stack-trace" (usually takes ~250ms).
|
53
|
-
*/
|
54
|
-
declare function createSimpleStackTrace(options?: ErrorOptions): string;
|
55
|
-
|
56
42
|
declare const lineSplitRE: RegExp;
|
57
43
|
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
58
44
|
declare function offsetToLineNumber(source: string, offset: number): number;
|
@@ -63,4 +49,4 @@ interface HighlightOptions {
|
|
63
49
|
}
|
64
50
|
declare function highlight(code: string, options?: HighlightOptions): string;
|
65
51
|
|
66
|
-
export {
|
52
|
+
export { type SafeTimers, format, getSafeTimers, highlight, inspect, lineSplitRE, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle, stringify };
|
package/dist/index.js
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
3
3
|
import c from 'tinyrainbow';
|
4
|
-
import '@vitest/pretty-format';
|
5
4
|
import 'loupe';
|
5
|
+
import '@vitest/pretty-format';
|
6
6
|
|
7
7
|
const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
|
8
|
-
const SAFE_COLORS_SYMBOL = Symbol("vitest:SAFE_COLORS");
|
9
|
-
|
10
8
|
function getSafeTimers() {
|
11
9
|
const {
|
12
10
|
setTimeout: safeSetTimeout,
|
@@ -68,19 +66,6 @@ function shuffle(array, seed = RealDate.now()) {
|
|
68
66
|
return array;
|
69
67
|
}
|
70
68
|
|
71
|
-
function createSimpleStackTrace(options) {
|
72
|
-
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
73
|
-
const limit = Error.stackTraceLimit;
|
74
|
-
const prepareStackTrace = Error.prepareStackTrace;
|
75
|
-
Error.stackTraceLimit = stackTraceLimit;
|
76
|
-
Error.prepareStackTrace = (e) => e.stack;
|
77
|
-
const err = new Error(message);
|
78
|
-
const stackTrace = err.stack || "";
|
79
|
-
Error.prepareStackTrace = prepareStackTrace;
|
80
|
-
Error.stackTraceLimit = limit;
|
81
|
-
return stackTrace;
|
82
|
-
}
|
83
|
-
|
84
69
|
const lineSplitRE = /\r?\n/;
|
85
70
|
function positionToOffset(source, lineNumber, columnNumber) {
|
86
71
|
const lines = source.split(lineSplitRE);
|
@@ -643,4 +628,4 @@ function highlight(code, options = { jsx: false }) {
|
|
643
628
|
});
|
644
629
|
}
|
645
630
|
|
646
|
-
export {
|
631
|
+
export { getSafeTimers, highlight, lineSplitRE, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.
|
4
|
+
"version": "2.0.4",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -63,7 +63,7 @@
|
|
63
63
|
"estree-walker": "^3.0.3",
|
64
64
|
"loupe": "^3.1.1",
|
65
65
|
"tinyrainbow": "^1.2.0",
|
66
|
-
"@vitest/pretty-format": "2.0.
|
66
|
+
"@vitest/pretty-format": "2.0.4"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
69
|
"@jridgewell/trace-mapping": "^0.3.25",
|