@vitest/utils 0.32.1 → 0.32.3
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 +79 -15
- package/dist/diff.d.ts +6 -0
- package/dist/diff.js +15 -2
- package/dist/error.js +1 -2
- package/dist/index.d.ts +16 -6
- package/dist/index.js +3 -4
- package/package.json +2 -2
package/dist/chunk-display.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { format as format$1, plugins } from 'pretty-format';
|
2
|
-
import
|
3
|
-
import loupeImport from 'loupe';
|
2
|
+
import { inspect as inspect$1 } from 'loupe';
|
4
3
|
|
5
4
|
const {
|
6
5
|
AsymmetricMatcher,
|
@@ -42,22 +41,87 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
42
41
|
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
43
42
|
}
|
44
43
|
|
45
|
-
const
|
44
|
+
const formatRegExp = /%[sdjifoOcj%]/g;
|
46
45
|
function format(...args) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
if (typeof args[0] !== "string") {
|
47
|
+
const objects = [];
|
48
|
+
for (let i2 = 0; i2 < args.length; i2++)
|
49
|
+
objects.push(inspect(args[i2], { depth: 0, colors: false, compact: 3 }));
|
50
|
+
return objects.join(" ");
|
51
|
+
}
|
52
|
+
const len = args.length;
|
53
|
+
let i = 1;
|
54
|
+
const template = args[0];
|
55
|
+
let str = String(template).replace(formatRegExp, (x) => {
|
56
|
+
if (x === "%%")
|
57
|
+
return "%";
|
58
|
+
if (i >= len)
|
59
|
+
return x;
|
60
|
+
switch (x) {
|
61
|
+
case "%s": {
|
62
|
+
const value = args[i++];
|
63
|
+
if (typeof value === "bigint")
|
64
|
+
return `${value.toString()}n`;
|
65
|
+
if (typeof value === "number" && value === 0 && 1 / value < 0)
|
66
|
+
return "-0";
|
67
|
+
if (typeof value === "object" && value !== null)
|
68
|
+
return inspect(value, { depth: 0, colors: false, compact: 3 });
|
69
|
+
return String(value);
|
70
|
+
}
|
71
|
+
case "%d": {
|
72
|
+
const value = args[i++];
|
73
|
+
if (typeof value === "bigint")
|
74
|
+
return `${value.toString()}n`;
|
75
|
+
return Number(value).toString();
|
76
|
+
}
|
77
|
+
case "%i": {
|
78
|
+
const value = args[i++];
|
79
|
+
if (typeof value === "bigint")
|
80
|
+
return `${value.toString()}n`;
|
81
|
+
return Number.parseInt(String(value)).toString();
|
82
|
+
}
|
83
|
+
case "%f":
|
84
|
+
return Number.parseFloat(String(args[i++])).toString();
|
85
|
+
case "%o":
|
86
|
+
return inspect(args[i++], { showHidden: true, showProxy: true });
|
87
|
+
case "%O":
|
88
|
+
return inspect(args[i++]);
|
89
|
+
case "%c": {
|
90
|
+
i++;
|
91
|
+
return "";
|
92
|
+
}
|
93
|
+
case "%j":
|
94
|
+
try {
|
95
|
+
return JSON.stringify(args[i++]);
|
96
|
+
} catch (err) {
|
97
|
+
const m = err.message;
|
98
|
+
if (
|
99
|
+
// chromium
|
100
|
+
m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")
|
101
|
+
)
|
102
|
+
return "[Circular]";
|
103
|
+
throw err;
|
104
|
+
}
|
105
|
+
default:
|
106
|
+
return x;
|
107
|
+
}
|
56
108
|
});
|
109
|
+
for (let x = args[i]; i < len; x = args[++i]) {
|
110
|
+
if (x === null || typeof x !== "object")
|
111
|
+
str += ` ${x}`;
|
112
|
+
else
|
113
|
+
str += ` ${inspect(x)}`;
|
114
|
+
}
|
115
|
+
return str;
|
116
|
+
}
|
117
|
+
function inspect(obj, options = {}) {
|
118
|
+
if (options.truncate === 0)
|
119
|
+
options.truncate = Number.POSITIVE_INFINITY;
|
120
|
+
return inspect$1(obj, options);
|
57
121
|
}
|
58
122
|
function objDisplay(obj, options = {}) {
|
59
|
-
const truncateThreshold = options.
|
60
|
-
const str =
|
123
|
+
const truncateThreshold = options.truncate ?? 40;
|
124
|
+
const str = inspect(obj, options);
|
61
125
|
const type = Object.prototype.toString.call(obj);
|
62
126
|
if (truncateThreshold && str.length >= truncateThreshold) {
|
63
127
|
if (type === "[object Function]") {
|
@@ -76,4 +140,4 @@ function objDisplay(obj, options = {}) {
|
|
76
140
|
return str;
|
77
141
|
}
|
78
142
|
|
79
|
-
export { format as f,
|
143
|
+
export { format as f, inspect as i, objDisplay as o, stringify as s };
|
package/dist/diff.d.ts
CHANGED
@@ -109,6 +109,12 @@ declare function diffStringsRaw(a: string, b: string, cleanup: boolean): Array<D
|
|
109
109
|
* LICENSE file in the root directory of this source tree.
|
110
110
|
*/
|
111
111
|
|
112
|
+
/**
|
113
|
+
* @param a Expected value
|
114
|
+
* @param b Received value
|
115
|
+
* @param options Diff options
|
116
|
+
* @returns
|
117
|
+
*/
|
112
118
|
declare function diff(a: any, b: any, options?: DiffOptions): string | null;
|
113
119
|
|
114
120
|
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, DiffOptions, DiffOptionsColor, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified };
|
package/dist/diff.js
CHANGED
@@ -41,6 +41,8 @@ const DIFF_DELETE = -1;
|
|
41
41
|
const DIFF_INSERT = 1;
|
42
42
|
const DIFF_EQUAL = 0;
|
43
43
|
class Diff {
|
44
|
+
0;
|
45
|
+
1;
|
44
46
|
constructor(op, text) {
|
45
47
|
this[0] = op;
|
46
48
|
this[1] = text;
|
@@ -726,7 +728,8 @@ function diffLinesRaw(aLines, bLines) {
|
|
726
728
|
for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1)
|
727
729
|
diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
|
728
730
|
};
|
729
|
-
diff$1.default.default
|
731
|
+
const diffSequences = diff$1.default.default || diff$1.default;
|
732
|
+
diffSequences(aLength, bLength, isCommon, foundSubsequence);
|
730
733
|
for (; aIndex !== aLength; aIndex += 1)
|
731
734
|
diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
|
732
735
|
for (; bIndex !== bLength; bIndex += 1)
|
@@ -748,7 +751,8 @@ function diffStrings(a, b) {
|
|
748
751
|
bIndex = bCommon + nCommon;
|
749
752
|
diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
|
750
753
|
};
|
751
|
-
diff$1.default.default
|
754
|
+
const diffSequences = diff$1.default.default || diff$1.default;
|
755
|
+
diffSequences(a.length, b.length, isCommon, foundSubsequence);
|
752
756
|
if (aIndex !== a.length)
|
753
757
|
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
|
754
758
|
if (bIndex !== b.length)
|
@@ -763,6 +767,12 @@ function concatenateRelevantDiffs(op, diffs, changeColor) {
|
|
763
767
|
);
|
764
768
|
}
|
765
769
|
class ChangeBuffer {
|
770
|
+
op;
|
771
|
+
line;
|
772
|
+
// incomplete line
|
773
|
+
lines;
|
774
|
+
// complete lines
|
775
|
+
changeColor;
|
766
776
|
constructor(op, changeColor) {
|
767
777
|
this.op = op;
|
768
778
|
this.line = [];
|
@@ -816,6 +826,9 @@ class ChangeBuffer {
|
|
816
826
|
}
|
817
827
|
}
|
818
828
|
class CommonBuffer {
|
829
|
+
deleteBuffer;
|
830
|
+
insertBuffer;
|
831
|
+
lines;
|
819
832
|
constructor(deleteBuffer, insertBuffer) {
|
820
833
|
this.deleteBuffer = deleteBuffer;
|
821
834
|
this.insertBuffer = insertBuffer;
|
package/dist/error.js
CHANGED
@@ -4,7 +4,6 @@ import { getOwnProperties, getType } from './helpers.js';
|
|
4
4
|
import 'pretty-format';
|
5
5
|
import 'diff-sequences';
|
6
6
|
import './chunk-colors.js';
|
7
|
-
import 'util';
|
8
7
|
import 'loupe';
|
9
8
|
|
10
9
|
const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
|
@@ -81,7 +80,7 @@ function processError(err) {
|
|
81
80
|
if (err.name)
|
82
81
|
err.nameStr = String(err.name);
|
83
82
|
if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0)
|
84
|
-
err.diff = diff(err.
|
83
|
+
err.diff = diff(err.expected, err.actual);
|
85
84
|
if (typeof err.expected !== "string")
|
86
85
|
err.expected = stringify(err.expected, 10);
|
87
86
|
if (typeof err.actual !== "string")
|
package/dist/index.d.ts
CHANGED
@@ -2,7 +2,6 @@ export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnPro
|
|
2
2
|
import { ParsedStack, ErrorWithDiff } from './types.js';
|
3
3
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, MergeInsertions, MutableArray, Nullable } from './types.js';
|
4
4
|
import { PrettyFormatOptions } from 'pretty-format';
|
5
|
-
import util from 'util';
|
6
5
|
|
7
6
|
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
8
7
|
maxLength?: number;
|
@@ -22,11 +21,22 @@ declare function setSafeTimers(): void;
|
|
22
21
|
declare function shuffle<T>(array: T[], seed?: number): T[];
|
23
22
|
|
24
23
|
interface LoupeOptions {
|
25
|
-
|
24
|
+
showHidden?: boolean | undefined;
|
25
|
+
depth?: number | null | undefined;
|
26
|
+
colors?: boolean | undefined;
|
27
|
+
customInspect?: boolean | undefined;
|
28
|
+
showProxy?: boolean | undefined;
|
29
|
+
maxArrayLength?: number | null | undefined;
|
30
|
+
maxStringLength?: number | null | undefined;
|
31
|
+
breakLength?: number | undefined;
|
32
|
+
compact?: boolean | number | undefined;
|
33
|
+
sorted?: boolean | ((a: string, b: string) => number) | undefined;
|
34
|
+
getters?: 'get' | 'set' | boolean | undefined;
|
35
|
+
numericSeparator?: boolean | undefined;
|
36
|
+
truncate?: number;
|
26
37
|
}
|
27
|
-
declare function format(...args:
|
28
|
-
declare function
|
29
|
-
declare function loupeInspect(obj: unknown, options?: LoupeOptions): string;
|
38
|
+
declare function format(...args: unknown[]): string;
|
39
|
+
declare function inspect(obj: unknown, options?: LoupeOptions): any;
|
30
40
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
31
41
|
|
32
42
|
declare const SAFE_TIMERS_SYMBOL: unique symbol;
|
@@ -93,4 +103,4 @@ declare function parseErrorStacktrace(e: ErrorWithDiff, ignore?: (string | RegEx
|
|
93
103
|
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
94
104
|
declare function offsetToLineNumber(source: string, offset: number): number;
|
95
105
|
|
96
|
-
export { ErrorWithDiff, ParsedStack, SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers,
|
106
|
+
export { ErrorWithDiff, ParsedStack, SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, inspect, lineSplitRE, objDisplay, offsetToLineNumber, parseErrorStacktrace, parseSingleStack, parseStacktrace, positionToOffset, setSafeTimers, setupColors, shuffle, stringify };
|
package/dist/index.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import { notNullish, isPrimitive } from './helpers.js';
|
2
2
|
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, noop, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
3
|
-
export { f as format,
|
3
|
+
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
4
4
|
import { S as SAFE_TIMERS_SYMBOL } from './chunk-colors.js';
|
5
5
|
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getColors, g as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
6
6
|
import 'pretty-format';
|
7
|
-
import 'util';
|
8
7
|
import 'loupe';
|
9
8
|
|
10
9
|
function getSafeTimers() {
|
@@ -219,8 +218,8 @@ function parseSingleStack(raw) {
|
|
219
218
|
return {
|
220
219
|
method,
|
221
220
|
file,
|
222
|
-
line: parseInt(lineNumber),
|
223
|
-
column: parseInt(columnNumber)
|
221
|
+
line: Number.parseInt(lineNumber),
|
222
|
+
column: Number.parseInt(columnNumber)
|
224
223
|
};
|
225
224
|
}
|
226
225
|
function parseStacktrace(stack, ignore = stackIgnorePatterns) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.32.
|
4
|
+
"version": "0.32.3",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -44,7 +44,7 @@
|
|
44
44
|
"dependencies": {
|
45
45
|
"diff-sequences": "^29.4.3",
|
46
46
|
"loupe": "^2.3.6",
|
47
|
-
"pretty-format": "^
|
47
|
+
"pretty-format": "^29.5.0"
|
48
48
|
},
|
49
49
|
"scripts": {
|
50
50
|
"build": "rimraf dist && rollup -c",
|