@vitest/utils 4.0.15 → 4.0.17
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/diff.js +14 -2
- package/dist/display.d.ts +2 -1
- package/dist/display.js +22 -7
- package/package.json +2 -2
package/dist/diff.js
CHANGED
|
@@ -2149,11 +2149,23 @@ function replaceAsymmetricMatcher(actual, expected, actualReplaced = new WeakSet
|
|
|
2149
2149
|
const actualValue = actual[key];
|
|
2150
2150
|
if (isAsymmetricMatcher(expectedValue)) {
|
|
2151
2151
|
if (expectedValue.asymmetricMatch(actualValue)) {
|
|
2152
|
-
actual
|
|
2152
|
+
// When matcher matches, replace expected with actual value
|
|
2153
|
+
// so they appear the same in the diff
|
|
2154
|
+
expected[key] = actualValue;
|
|
2155
|
+
} else if ("sample" in expectedValue && expectedValue.sample !== undefined && isReplaceable(actualValue, expectedValue.sample)) {
|
|
2156
|
+
// For container matchers (ArrayContaining, ObjectContaining), unwrap and recursively process
|
|
2157
|
+
// Matcher doesn't match: unwrap but keep structure to show mismatch
|
|
2158
|
+
const replaced = replaceAsymmetricMatcher(actualValue, expectedValue.sample, actualReplaced, expectedReplaced);
|
|
2159
|
+
actual[key] = replaced.replacedActual;
|
|
2160
|
+
expected[key] = replaced.replacedExpected;
|
|
2153
2161
|
}
|
|
2154
2162
|
} else if (isAsymmetricMatcher(actualValue)) {
|
|
2155
2163
|
if (actualValue.asymmetricMatch(expectedValue)) {
|
|
2156
|
-
|
|
2164
|
+
actual[key] = expectedValue;
|
|
2165
|
+
} else if ("sample" in actualValue && actualValue.sample !== undefined && isReplaceable(actualValue.sample, expectedValue)) {
|
|
2166
|
+
const replaced = replaceAsymmetricMatcher(actualValue.sample, expectedValue, actualReplaced, expectedReplaced);
|
|
2167
|
+
actual[key] = replaced.replacedActual;
|
|
2168
|
+
expected[key] = replaced.replacedExpected;
|
|
2157
2169
|
}
|
|
2158
2170
|
} else if (isReplaceable(actualValue, expectedValue)) {
|
|
2159
2171
|
const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
|
package/dist/display.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ interface StringifyOptions extends PrettyFormatOptions {
|
|
|
21
21
|
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: StringifyOptions): string;
|
|
22
22
|
declare const formatRegExp: RegExp;
|
|
23
23
|
declare function format(...args: unknown[]): string;
|
|
24
|
+
declare function browserFormat(...args: unknown[]): string;
|
|
24
25
|
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
|
25
26
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
|
26
27
|
|
|
27
|
-
export { format, formatRegExp, inspect, objDisplay, stringify };
|
|
28
|
+
export { browserFormat, format, formatRegExp, inspect, objDisplay, stringify };
|
|
28
29
|
export type { LoupeOptions, StringifyOptions };
|
package/dist/display.js
CHANGED
|
@@ -609,11 +609,20 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
|
609
609
|
}) : result;
|
|
610
610
|
}
|
|
611
611
|
const formatRegExp = /%[sdjifoOc%]/g;
|
|
612
|
-
function
|
|
612
|
+
function baseFormat(args, options = {}) {
|
|
613
|
+
const formatArg = (item, inspecOptions) => {
|
|
614
|
+
if (options.prettifyObject) {
|
|
615
|
+
return stringify(item, undefined, {
|
|
616
|
+
printBasicPrototype: false,
|
|
617
|
+
escapeString: false
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return inspect(item, inspecOptions);
|
|
621
|
+
};
|
|
613
622
|
if (typeof args[0] !== "string") {
|
|
614
623
|
const objects = [];
|
|
615
624
|
for (let i = 0; i < args.length; i++) {
|
|
616
|
-
objects.push(
|
|
625
|
+
objects.push(formatArg(args[i], {
|
|
617
626
|
depth: 0,
|
|
618
627
|
colors: false
|
|
619
628
|
}));
|
|
@@ -643,7 +652,7 @@ function format(...args) {
|
|
|
643
652
|
if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
|
|
644
653
|
return value.toString();
|
|
645
654
|
}
|
|
646
|
-
return
|
|
655
|
+
return formatArg(value, {
|
|
647
656
|
depth: 0,
|
|
648
657
|
colors: false
|
|
649
658
|
});
|
|
@@ -665,11 +674,11 @@ function format(...args) {
|
|
|
665
674
|
return Number.parseInt(String(value)).toString();
|
|
666
675
|
}
|
|
667
676
|
case "%f": return Number.parseFloat(String(args[i++])).toString();
|
|
668
|
-
case "%o": return
|
|
677
|
+
case "%o": return formatArg(args[i++], {
|
|
669
678
|
showHidden: true,
|
|
670
679
|
showProxy: true
|
|
671
680
|
});
|
|
672
|
-
case "%O": return
|
|
681
|
+
case "%O": return formatArg(args[i++]);
|
|
673
682
|
case "%c": {
|
|
674
683
|
i++;
|
|
675
684
|
return "";
|
|
@@ -690,11 +699,17 @@ function format(...args) {
|
|
|
690
699
|
if (x === null || typeof x !== "object") {
|
|
691
700
|
str += ` ${x}`;
|
|
692
701
|
} else {
|
|
693
|
-
str += ` ${
|
|
702
|
+
str += ` ${formatArg(x)}`;
|
|
694
703
|
}
|
|
695
704
|
}
|
|
696
705
|
return str;
|
|
697
706
|
}
|
|
707
|
+
function format(...args) {
|
|
708
|
+
return baseFormat(args);
|
|
709
|
+
}
|
|
710
|
+
function browserFormat(...args) {
|
|
711
|
+
return baseFormat(args, { prettifyObject: true });
|
|
712
|
+
}
|
|
698
713
|
function inspect(obj, options = {}) {
|
|
699
714
|
if (options.truncate === 0) {
|
|
700
715
|
options.truncate = Number.POSITIVE_INFINITY;
|
|
@@ -724,4 +739,4 @@ function objDisplay(obj, options = {}) {
|
|
|
724
739
|
return str;
|
|
725
740
|
}
|
|
726
741
|
|
|
727
|
-
export { format, formatRegExp, inspect, objDisplay, stringify };
|
|
742
|
+
export { browserFormat, format, formatRegExp, inspect, objDisplay, stringify };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.17",
|
|
5
5
|
"description": "Shared Vitest utility functions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
],
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"tinyrainbow": "^3.0.3",
|
|
85
|
-
"@vitest/pretty-format": "4.0.
|
|
85
|
+
"@vitest/pretty-format": "4.0.17"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@jridgewell/trace-mapping": "0.3.31",
|