@vitest/utils 4.0.0-beta.8 → 4.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 -154
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +49 -0
- package/dist/diff.d.ts +0 -11
- package/dist/diff.js +7 -5
- package/dist/display.d.ts +28 -0
- package/dist/display.js +727 -0
- package/dist/error.d.ts +2 -4
- package/dist/error.js +6 -126
- package/dist/helpers.d.ts +6 -3
- package/dist/helpers.js +295 -1
- package/dist/highlight.d.ts +9 -0
- package/dist/highlight.js +538 -0
- package/dist/index.d.ts +4 -82
- package/dist/index.js +0 -632
- package/dist/offset.d.ts +5 -0
- package/dist/offset.js +32 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +118 -0
- package/dist/source-map.d.ts +31 -122
- package/dist/source-map.js +163 -538
- package/dist/timers.d.ts +18 -0
- package/dist/timers.js +32 -0
- package/package.json +30 -13
- package/dist/chunk-helpers.js +0 -329
|
@@ -1,158 +1,5 @@
|
|
|
1
|
-
import { plugins, format as format$1 } from '@vitest/pretty-format';
|
|
2
|
-
import * as loupe from 'loupe';
|
|
3
|
-
|
|
4
|
-
const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
|
|
5
|
-
const PLUGINS = [
|
|
6
|
-
ReactTestComponent,
|
|
7
|
-
ReactElement,
|
|
8
|
-
DOMElement,
|
|
9
|
-
DOMCollection,
|
|
10
|
-
Immutable,
|
|
11
|
-
AsymmetricMatcher
|
|
12
|
-
];
|
|
13
|
-
function stringify(object, maxDepth = 10, { maxLength,...options } = {}) {
|
|
14
|
-
const MAX_LENGTH = maxLength ?? 1e4;
|
|
15
|
-
let result;
|
|
16
|
-
try {
|
|
17
|
-
result = format$1(object, {
|
|
18
|
-
maxDepth,
|
|
19
|
-
escapeString: false,
|
|
20
|
-
plugins: PLUGINS,
|
|
21
|
-
...options
|
|
22
|
-
});
|
|
23
|
-
} catch {
|
|
24
|
-
result = format$1(object, {
|
|
25
|
-
callToJSON: false,
|
|
26
|
-
maxDepth,
|
|
27
|
-
escapeString: false,
|
|
28
|
-
plugins: PLUGINS,
|
|
29
|
-
...options
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
|
|
33
|
-
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
|
|
34
|
-
maxLength,
|
|
35
|
-
...options
|
|
36
|
-
}) : result;
|
|
37
|
-
}
|
|
38
|
-
const formatRegExp = /%[sdjifoOc%]/g;
|
|
39
|
-
function format(...args) {
|
|
40
|
-
if (typeof args[0] !== "string") {
|
|
41
|
-
const objects = [];
|
|
42
|
-
for (let i = 0; i < args.length; i++) {
|
|
43
|
-
objects.push(inspect(args[i], {
|
|
44
|
-
depth: 0,
|
|
45
|
-
colors: false
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
return objects.join(" ");
|
|
49
|
-
}
|
|
50
|
-
const len = args.length;
|
|
51
|
-
let i = 1;
|
|
52
|
-
const template = args[0];
|
|
53
|
-
let str = String(template).replace(formatRegExp, (x) => {
|
|
54
|
-
if (x === "%%") {
|
|
55
|
-
return "%";
|
|
56
|
-
}
|
|
57
|
-
if (i >= len) {
|
|
58
|
-
return x;
|
|
59
|
-
}
|
|
60
|
-
switch (x) {
|
|
61
|
-
case "%s": {
|
|
62
|
-
const value = args[i++];
|
|
63
|
-
if (typeof value === "bigint") {
|
|
64
|
-
return `${value.toString()}n`;
|
|
65
|
-
}
|
|
66
|
-
if (typeof value === "number" && value === 0 && 1 / value < 0) {
|
|
67
|
-
return "-0";
|
|
68
|
-
}
|
|
69
|
-
if (typeof value === "object" && value !== null) {
|
|
70
|
-
if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
|
|
71
|
-
return value.toString();
|
|
72
|
-
}
|
|
73
|
-
return inspect(value, {
|
|
74
|
-
depth: 0,
|
|
75
|
-
colors: false
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return String(value);
|
|
79
|
-
}
|
|
80
|
-
case "%d": {
|
|
81
|
-
const value = args[i++];
|
|
82
|
-
if (typeof value === "bigint") {
|
|
83
|
-
return `${value.toString()}n`;
|
|
84
|
-
}
|
|
85
|
-
return Number(value).toString();
|
|
86
|
-
}
|
|
87
|
-
case "%i": {
|
|
88
|
-
const value = args[i++];
|
|
89
|
-
if (typeof value === "bigint") {
|
|
90
|
-
return `${value.toString()}n`;
|
|
91
|
-
}
|
|
92
|
-
return Number.parseInt(String(value)).toString();
|
|
93
|
-
}
|
|
94
|
-
case "%f": return Number.parseFloat(String(args[i++])).toString();
|
|
95
|
-
case "%o": return inspect(args[i++], {
|
|
96
|
-
showHidden: true,
|
|
97
|
-
showProxy: true
|
|
98
|
-
});
|
|
99
|
-
case "%O": return inspect(args[i++]);
|
|
100
|
-
case "%c": {
|
|
101
|
-
i++;
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
case "%j": try {
|
|
105
|
-
return JSON.stringify(args[i++]);
|
|
106
|
-
} catch (err) {
|
|
107
|
-
const m = err.message;
|
|
108
|
-
if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) {
|
|
109
|
-
return "[Circular]";
|
|
110
|
-
}
|
|
111
|
-
throw err;
|
|
112
|
-
}
|
|
113
|
-
default: return x;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
for (let x = args[i]; i < len; x = args[++i]) {
|
|
117
|
-
if (x === null || typeof x !== "object") {
|
|
118
|
-
str += ` ${x}`;
|
|
119
|
-
} else {
|
|
120
|
-
str += ` ${inspect(x)}`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return str;
|
|
124
|
-
}
|
|
125
|
-
function inspect(obj, options = {}) {
|
|
126
|
-
if (options.truncate === 0) {
|
|
127
|
-
options.truncate = Number.POSITIVE_INFINITY;
|
|
128
|
-
}
|
|
129
|
-
return loupe.inspect(obj, options);
|
|
130
|
-
}
|
|
131
|
-
function objDisplay(obj, options = {}) {
|
|
132
|
-
if (typeof options.truncate === "undefined") {
|
|
133
|
-
options.truncate = 40;
|
|
134
|
-
}
|
|
135
|
-
const str = inspect(obj, options);
|
|
136
|
-
const type = Object.prototype.toString.call(obj);
|
|
137
|
-
if (options.truncate && str.length >= options.truncate) {
|
|
138
|
-
if (type === "[object Function]") {
|
|
139
|
-
const fn = obj;
|
|
140
|
-
return !fn.name ? "[Function]" : `[Function: ${fn.name}]`;
|
|
141
|
-
} else if (type === "[object Array]") {
|
|
142
|
-
return `[ Array(${obj.length}) ]`;
|
|
143
|
-
} else if (type === "[object Object]") {
|
|
144
|
-
const keys = Object.keys(obj);
|
|
145
|
-
const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", ");
|
|
146
|
-
return `{ Object (${kstr}) }`;
|
|
147
|
-
} else {
|
|
148
|
-
return str;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return str;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
1
|
function getDefaultExportFromCjs (x) {
|
|
155
2
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
156
3
|
}
|
|
157
4
|
|
|
158
|
-
export {
|
|
5
|
+
export { getDefaultExportFromCjs as g };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const KNOWN_ASSET_TYPES: string[];
|
|
2
|
+
declare const KNOWN_ASSET_RE: RegExp;
|
|
3
|
+
declare const CSS_LANGS_RE: RegExp;
|
|
4
|
+
/**
|
|
5
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
6
|
+
*/
|
|
7
|
+
declare const VALID_ID_PREFIX = "/@id/";
|
|
8
|
+
/**
|
|
9
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
10
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
11
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
12
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
13
|
+
* virtual modules and regular files.
|
|
14
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
15
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
16
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
17
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
18
|
+
*/
|
|
19
|
+
declare const NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
20
|
+
|
|
21
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// TODO: this is all copy pasted from Vite - can they expose a module that exports only constants?
|
|
2
|
+
const KNOWN_ASSET_TYPES = [
|
|
3
|
+
"apng",
|
|
4
|
+
"bmp",
|
|
5
|
+
"png",
|
|
6
|
+
"jpe?g",
|
|
7
|
+
"jfif",
|
|
8
|
+
"pjpeg",
|
|
9
|
+
"pjp",
|
|
10
|
+
"gif",
|
|
11
|
+
"svg",
|
|
12
|
+
"ico",
|
|
13
|
+
"webp",
|
|
14
|
+
"avif",
|
|
15
|
+
"mp4",
|
|
16
|
+
"webm",
|
|
17
|
+
"ogg",
|
|
18
|
+
"mp3",
|
|
19
|
+
"wav",
|
|
20
|
+
"flac",
|
|
21
|
+
"aac",
|
|
22
|
+
"woff2?",
|
|
23
|
+
"eot",
|
|
24
|
+
"ttf",
|
|
25
|
+
"otf",
|
|
26
|
+
"webmanifest",
|
|
27
|
+
"pdf",
|
|
28
|
+
"txt"
|
|
29
|
+
];
|
|
30
|
+
const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
|
|
31
|
+
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
32
|
+
/**
|
|
33
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
34
|
+
*/
|
|
35
|
+
const VALID_ID_PREFIX = `/@id/`;
|
|
36
|
+
/**
|
|
37
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
38
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
39
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
40
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
41
|
+
* virtual modules and regular files.
|
|
42
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
43
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
44
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
45
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
46
|
+
*/
|
|
47
|
+
const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
48
|
+
|
|
49
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
|
package/dist/diff.d.ts
CHANGED
|
@@ -61,13 +61,8 @@ declare class Diff {
|
|
|
61
61
|
* LICENSE file in the root directory of this source tree.
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
-
// Compare two arrays of strings line-by-line. Format as comparison lines.
|
|
65
64
|
declare function diffLinesUnified(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): string;
|
|
66
|
-
// Given two pairs of arrays of strings:
|
|
67
|
-
// Compare the pair of comparison arrays line-by-line.
|
|
68
|
-
// Format the corresponding lines in the pair of displayable arrays.
|
|
69
65
|
declare function diffLinesUnified2(aLinesDisplay: Array<string>, bLinesDisplay: Array<string>, aLinesCompare: Array<string>, bLinesCompare: Array<string>, options?: DiffOptions): string;
|
|
70
|
-
// Compare two arrays of strings line-by-line.
|
|
71
66
|
declare function diffLinesRaw(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): [Array<Diff>, boolean];
|
|
72
67
|
|
|
73
68
|
/**
|
|
@@ -77,15 +72,9 @@ declare function diffLinesRaw(aLines: Array<string>, bLines: Array<string>, opti
|
|
|
77
72
|
* LICENSE file in the root directory of this source tree.
|
|
78
73
|
*/
|
|
79
74
|
|
|
80
|
-
// Compare two strings character-by-character.
|
|
81
|
-
// Format as comparison lines in which changed substrings have inverse colors.
|
|
82
75
|
declare function diffStringsUnified(a: string, b: string, options?: DiffOptions): string;
|
|
83
|
-
// Compare two strings character-by-character.
|
|
84
|
-
// Optionally clean up small common substrings, also known as chaff.
|
|
85
76
|
declare function diffStringsRaw(a: string, b: string, cleanup: boolean, options?: DiffOptions): [Array<Diff>, boolean];
|
|
86
77
|
|
|
87
|
-
// Generate a string that will highlight the difference between two values
|
|
88
|
-
// with green and red. (similar to how github does code diffing)
|
|
89
78
|
/**
|
|
90
79
|
* @param a Expected value
|
|
91
80
|
* @param b Received value
|
package/dist/diff.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { plugins, format } from '@vitest/pretty-format';
|
|
2
2
|
import c from 'tinyrainbow';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
3
|
+
import { stringify } from './display.js';
|
|
4
|
+
import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
|
|
5
|
+
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
|
6
|
+
import './constants.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Diff Match and Patch
|
|
@@ -332,6 +333,7 @@ function diff_cleanupSemanticLossless(diffs) {
|
|
|
332
333
|
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
|
333
334
|
*/
|
|
334
335
|
function diff_cleanupMerge(diffs) {
|
|
336
|
+
var _diffs$at;
|
|
335
337
|
// Add a dummy entry at the end.
|
|
336
338
|
diffs.push(new Diff(DIFF_EQUAL, ""));
|
|
337
339
|
let pointer = 0;
|
|
@@ -402,7 +404,7 @@ function diff_cleanupMerge(diffs) {
|
|
|
402
404
|
break;
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
|
-
if (diffs
|
|
407
|
+
if (((_diffs$at = diffs.at(-1)) === null || _diffs$at === void 0 ? void 0 : _diffs$at[1]) === "") {
|
|
406
408
|
diffs.pop();
|
|
407
409
|
}
|
|
408
410
|
// Second pass: look for single edits surrounded on both sides by equalities
|
|
@@ -1300,7 +1302,7 @@ function requireBuild () {
|
|
|
1300
1302
|
return build;
|
|
1301
1303
|
}
|
|
1302
1304
|
|
|
1303
|
-
var buildExports = requireBuild();
|
|
1305
|
+
var buildExports = /*@__PURE__*/ requireBuild();
|
|
1304
1306
|
var diffSequences = /*@__PURE__*/getDefaultExportFromCjs(buildExports);
|
|
1305
1307
|
|
|
1306
1308
|
function formatTrailingSpaces(line, trailingSpaceFormatter) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
2
|
+
|
|
3
|
+
type Inspect = (value: unknown, options: Options) => string;
|
|
4
|
+
interface Options {
|
|
5
|
+
showHidden: boolean;
|
|
6
|
+
depth: number;
|
|
7
|
+
colors: boolean;
|
|
8
|
+
customInspect: boolean;
|
|
9
|
+
showProxy: boolean;
|
|
10
|
+
maxArrayLength: number;
|
|
11
|
+
breakLength: number;
|
|
12
|
+
truncate: number;
|
|
13
|
+
seen: unknown[];
|
|
14
|
+
inspect: Inspect;
|
|
15
|
+
stylize: (value: string, styleType: string) => string;
|
|
16
|
+
}
|
|
17
|
+
type LoupeOptions = Partial<Options>;
|
|
18
|
+
interface StringifyOptions extends PrettyFormatOptions {
|
|
19
|
+
maxLength?: number;
|
|
20
|
+
}
|
|
21
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
|
|
22
|
+
declare const formatRegExp: RegExp;
|
|
23
|
+
declare function format(...args: unknown[]): string;
|
|
24
|
+
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
|
25
|
+
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
|
26
|
+
|
|
27
|
+
export { format, formatRegExp, inspect, objDisplay, stringify };
|
|
28
|
+
export type { LoupeOptions, StringifyOptions };
|