@vitest/utils 3.0.0-beta.3 → 3.0.0
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-_commonjsHelpers.js +1 -1
- package/dist/diff.d.ts +1 -1
- package/dist/diff.js +13 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -4
- package/dist/source-map.d.ts +20 -1
- package/dist/source-map.js +36 -1
- package/package.json +3 -3
@@ -38,7 +38,7 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
38
38
|
...options
|
39
39
|
});
|
40
40
|
}
|
41
|
-
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
41
|
+
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), { maxLength, ...options }) : result;
|
42
42
|
}
|
43
43
|
const formatRegExp = /%[sdjifoOc%]/g;
|
44
44
|
function format(...args) {
|
package/dist/diff.d.ts
CHANGED
@@ -89,7 +89,7 @@ declare function diffStringsRaw(a: string, b: string, cleanup: boolean, options?
|
|
89
89
|
* @returns {string | null} a string diff
|
90
90
|
*/
|
91
91
|
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
|
92
|
-
declare function printDiffOrStringify(
|
92
|
+
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
|
93
93
|
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
|
94
94
|
replacedActual: any;
|
95
95
|
replacedExpected: any;
|
package/dist/diff.js
CHANGED
@@ -1855,7 +1855,7 @@ const FORMAT_OPTIONS = {
|
|
1855
1855
|
};
|
1856
1856
|
const FALLBACK_FORMAT_OPTIONS = {
|
1857
1857
|
callToJSON: false,
|
1858
|
-
maxDepth:
|
1858
|
+
maxDepth: 8,
|
1859
1859
|
plugins: PLUGINS
|
1860
1860
|
};
|
1861
1861
|
function diff(a, b, options) {
|
@@ -1876,10 +1876,16 @@ function diff(a, b, options) {
|
|
1876
1876
|
omitDifference = expectedType === "string";
|
1877
1877
|
}
|
1878
1878
|
if (expectedType !== getType(b)) {
|
1879
|
+
let truncate2 = function(s) {
|
1880
|
+
return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
|
1881
|
+
};
|
1879
1882
|
const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
|
1880
1883
|
const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
|
1881
|
-
|
1882
|
-
|
1884
|
+
let aDisplay = format(a, formatOptions);
|
1885
|
+
let bDisplay = format(b, formatOptions);
|
1886
|
+
const MAX_LENGTH = 1e5;
|
1887
|
+
aDisplay = truncate2(aDisplay);
|
1888
|
+
bDisplay = truncate2(bDisplay);
|
1883
1889
|
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
|
1884
1890
|
${aDisplay}`;
|
1885
1891
|
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
|
@@ -1976,13 +1982,13 @@ function isReplaceable(obj1, obj2) {
|
|
1976
1982
|
const obj2Type = getType$1(obj2);
|
1977
1983
|
return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
|
1978
1984
|
}
|
1979
|
-
function printDiffOrStringify(
|
1985
|
+
function printDiffOrStringify(received, expected, options) {
|
1980
1986
|
const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
|
1981
1987
|
if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
|
1982
1988
|
if (expected.includes("\n") || received.includes("\n")) {
|
1983
|
-
return diffStringsUnified(
|
1989
|
+
return diffStringsUnified(expected, received, options);
|
1984
1990
|
}
|
1985
|
-
const [diffs] = diffStringsRaw(
|
1991
|
+
const [diffs] = diffStringsRaw(expected, received, true);
|
1986
1992
|
const hasCommonDiff = diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
|
1987
1993
|
const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
|
1988
1994
|
const expectedLine = printLabel(aAnnotation) + printExpected(
|
@@ -1996,7 +2002,7 @@ ${receivedLine}`;
|
|
1996
2002
|
}
|
1997
2003
|
const clonedExpected = deepClone(expected, { forceWritable: true });
|
1998
2004
|
const clonedReceived = deepClone(received, { forceWritable: true });
|
1999
|
-
const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(
|
2005
|
+
const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
|
2000
2006
|
const difference = diff(replacedExpected, replacedActual, options);
|
2001
2007
|
return difference;
|
2002
2008
|
}
|
package/dist/index.d.ts
CHANGED
@@ -48,6 +48,7 @@ interface SafeTimers {
|
|
48
48
|
clearTimeout: typeof clearTimeout;
|
49
49
|
setImmediate: typeof setImmediate;
|
50
50
|
clearImmediate: typeof clearImmediate;
|
51
|
+
queueMicrotask: typeof queueMicrotask;
|
51
52
|
}
|
52
53
|
declare function getSafeTimers(): SafeTimers;
|
53
54
|
declare function setSafeTimers(): void;
|
package/dist/index.js
CHANGED
@@ -607,7 +607,8 @@ function getSafeTimers() {
|
|
607
607
|
clearInterval: safeClearInterval,
|
608
608
|
clearTimeout: safeClearTimeout,
|
609
609
|
setImmediate: safeSetImmediate,
|
610
|
-
clearImmediate: safeClearImmediate
|
610
|
+
clearImmediate: safeClearImmediate,
|
611
|
+
queueMicrotask: safeQueueMicrotask
|
611
612
|
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
612
613
|
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
613
614
|
return {
|
@@ -617,7 +618,8 @@ function getSafeTimers() {
|
|
617
618
|
clearInterval: safeClearInterval,
|
618
619
|
clearTimeout: safeClearTimeout,
|
619
620
|
setImmediate: safeSetImmediate,
|
620
|
-
clearImmediate: safeClearImmediate
|
621
|
+
clearImmediate: safeClearImmediate,
|
622
|
+
queueMicrotask: safeQueueMicrotask
|
621
623
|
};
|
622
624
|
}
|
623
625
|
function setSafeTimers() {
|
@@ -627,7 +629,8 @@ function setSafeTimers() {
|
|
627
629
|
clearInterval: safeClearInterval,
|
628
630
|
clearTimeout: safeClearTimeout,
|
629
631
|
setImmediate: safeSetImmediate,
|
630
|
-
clearImmediate: safeClearImmediate
|
632
|
+
clearImmediate: safeClearImmediate,
|
633
|
+
queueMicrotask: safeQueueMicrotask
|
631
634
|
} = globalThis;
|
632
635
|
const { nextTick: safeNextTick } = globalThis.process || {
|
633
636
|
nextTick: (cb) => cb()
|
@@ -639,7 +642,8 @@ function setSafeTimers() {
|
|
639
642
|
clearInterval: safeClearInterval,
|
640
643
|
clearTimeout: safeClearTimeout,
|
641
644
|
setImmediate: safeSetImmediate,
|
642
|
-
clearImmediate: safeClearImmediate
|
645
|
+
clearImmediate: safeClearImmediate,
|
646
|
+
queueMicrotask: safeQueueMicrotask
|
643
647
|
};
|
644
648
|
globalThis[SAFE_TIMERS_SYMBOL] = timers;
|
645
649
|
}
|
package/dist/source-map.d.ts
CHANGED
@@ -60,6 +60,21 @@ type SourceNeedle = {
|
|
60
60
|
column: number;
|
61
61
|
bias?: Bias;
|
62
62
|
};
|
63
|
+
type EachMapping = {
|
64
|
+
generatedLine: number;
|
65
|
+
generatedColumn: number;
|
66
|
+
source: null;
|
67
|
+
originalLine: null;
|
68
|
+
originalColumn: null;
|
69
|
+
name: null;
|
70
|
+
} | {
|
71
|
+
generatedLine: number;
|
72
|
+
generatedColumn: number;
|
73
|
+
source: string | null;
|
74
|
+
originalLine: number;
|
75
|
+
originalColumn: number;
|
76
|
+
name: string | null;
|
77
|
+
};
|
63
78
|
declare abstract class SourceMap {
|
64
79
|
version: SourceMapV3['version'];
|
65
80
|
file: SourceMapV3['file'];
|
@@ -100,6 +115,10 @@ declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMap
|
|
100
115
|
* Finds the generated line/column position of the provided source/line/column source position.
|
101
116
|
*/
|
102
117
|
declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
118
|
+
/**
|
119
|
+
* Iterates each mapping in generated position order.
|
120
|
+
*/
|
121
|
+
declare function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void;
|
103
122
|
|
104
123
|
interface StackTraceParserOptions {
|
105
124
|
ignoreStackEntries?: (RegExp | string)[];
|
@@ -114,4 +133,4 @@ declare function createStackString(stacks: ParsedStack[]): string;
|
|
114
133
|
declare function parseStacktrace(stack: string, options?: StackTraceParserOptions): ParsedStack[];
|
115
134
|
declare function parseErrorStacktrace(e: ErrorWithDiff, options?: StackTraceParserOptions): ParsedStack[];
|
116
135
|
|
117
|
-
export { type SourceMapInput, type StackTraceParserOptions, TraceMap, createStackString, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
136
|
+
export { type EachMapping, type SourceMapInput, type StackTraceParserOptions, TraceMap, createStackString, eachMapping, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
package/dist/source-map.js
CHANGED
@@ -612,6 +612,40 @@ function generatedPositionFor(map, needle) {
|
|
612
612
|
const { source, line, column, bias } = needle;
|
613
613
|
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
614
614
|
}
|
615
|
+
/**
|
616
|
+
* Iterates each mapping in generated position order.
|
617
|
+
*/
|
618
|
+
function eachMapping(map, cb) {
|
619
|
+
const decoded = decodedMappings(map);
|
620
|
+
const { names, resolvedSources } = map;
|
621
|
+
for (let i = 0; i < decoded.length; i++) {
|
622
|
+
const line = decoded[i];
|
623
|
+
for (let j = 0; j < line.length; j++) {
|
624
|
+
const seg = line[j];
|
625
|
+
const generatedLine = i + 1;
|
626
|
+
const generatedColumn = seg[0];
|
627
|
+
let source = null;
|
628
|
+
let originalLine = null;
|
629
|
+
let originalColumn = null;
|
630
|
+
let name = null;
|
631
|
+
if (seg.length !== 1) {
|
632
|
+
source = resolvedSources[seg[1]];
|
633
|
+
originalLine = seg[2] + 1;
|
634
|
+
originalColumn = seg[3];
|
635
|
+
}
|
636
|
+
if (seg.length === 5)
|
637
|
+
name = names[seg[4]];
|
638
|
+
cb({
|
639
|
+
generatedLine,
|
640
|
+
generatedColumn,
|
641
|
+
source,
|
642
|
+
originalLine,
|
643
|
+
originalColumn,
|
644
|
+
name,
|
645
|
+
});
|
646
|
+
}
|
647
|
+
}
|
648
|
+
}
|
615
649
|
function OMapping(source, line, column, name) {
|
616
650
|
return { source, line, column, name };
|
617
651
|
}
|
@@ -691,6 +725,7 @@ function normalizeWindowsPath(input = "") {
|
|
691
725
|
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
692
726
|
}
|
693
727
|
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
728
|
+
globalThis.process?.platform === "win32" ? ";" : ":";
|
694
729
|
function cwd() {
|
695
730
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
696
731
|
return process.cwd().replace(/\\/g, "/");
|
@@ -955,4 +990,4 @@ function parseErrorStacktrace(e, options = {}) {
|
|
955
990
|
return stackFrames;
|
956
991
|
}
|
957
992
|
|
958
|
-
export { TraceMap, createStackString, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
993
|
+
export { TraceMap, createStackString, eachMapping, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "3.0.0
|
4
|
+
"version": "3.0.0",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -61,8 +61,8 @@
|
|
61
61
|
],
|
62
62
|
"dependencies": {
|
63
63
|
"loupe": "^3.1.2",
|
64
|
-
"tinyrainbow": "^
|
65
|
-
"@vitest/pretty-format": "3.0.0
|
64
|
+
"tinyrainbow": "^2.0.0",
|
65
|
+
"@vitest/pretty-format": "3.0.0"
|
66
66
|
},
|
67
67
|
"devDependencies": {
|
68
68
|
"@jridgewell/trace-mapping": "^0.3.25",
|