@vitest/utils 0.31.4 → 0.32.1
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 -0
- package/dist/diff.d.ts +108 -8
- package/dist/diff.js +1043 -102
- package/dist/error.d.ts +8 -0
- package/dist/error.js +145 -0
- package/dist/index.js +5 -78
- package/error.d.ts +1 -0
- package/package.json +6 -2
@@ -0,0 +1,79 @@
|
|
1
|
+
import { format as format$1, plugins } from 'pretty-format';
|
2
|
+
import util from 'util';
|
3
|
+
import loupeImport from 'loupe';
|
4
|
+
|
5
|
+
const {
|
6
|
+
AsymmetricMatcher,
|
7
|
+
DOMCollection,
|
8
|
+
DOMElement,
|
9
|
+
Immutable,
|
10
|
+
ReactElement,
|
11
|
+
ReactTestComponent
|
12
|
+
} = plugins;
|
13
|
+
const PLUGINS = [
|
14
|
+
ReactTestComponent,
|
15
|
+
ReactElement,
|
16
|
+
DOMElement,
|
17
|
+
DOMCollection,
|
18
|
+
Immutable,
|
19
|
+
AsymmetricMatcher
|
20
|
+
];
|
21
|
+
function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
22
|
+
const MAX_LENGTH = maxLength ?? 1e4;
|
23
|
+
let result;
|
24
|
+
try {
|
25
|
+
result = format$1(object, {
|
26
|
+
maxDepth,
|
27
|
+
escapeString: false,
|
28
|
+
// min: true,
|
29
|
+
plugins: PLUGINS,
|
30
|
+
...options
|
31
|
+
});
|
32
|
+
} catch {
|
33
|
+
result = format$1(object, {
|
34
|
+
callToJSON: false,
|
35
|
+
maxDepth,
|
36
|
+
escapeString: false,
|
37
|
+
// min: true,
|
38
|
+
plugins: PLUGINS,
|
39
|
+
...options
|
40
|
+
});
|
41
|
+
}
|
42
|
+
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
43
|
+
}
|
44
|
+
|
45
|
+
const loupe = typeof loupeImport.default === "function" ? loupeImport.default : loupeImport;
|
46
|
+
function format(...args) {
|
47
|
+
return util.format(...args);
|
48
|
+
}
|
49
|
+
function utilInspect(item, options) {
|
50
|
+
return util.inspect(item, options);
|
51
|
+
}
|
52
|
+
function loupeInspect(obj, options = {}) {
|
53
|
+
return loupe(obj, {
|
54
|
+
depth: 2,
|
55
|
+
truncate: options.truncateThreshold === 0 ? Infinity : options.truncateThreshold ?? 40
|
56
|
+
});
|
57
|
+
}
|
58
|
+
function objDisplay(obj, options = {}) {
|
59
|
+
const truncateThreshold = options.truncateThreshold ?? 40;
|
60
|
+
const str = loupeInspect(obj, options);
|
61
|
+
const type = Object.prototype.toString.call(obj);
|
62
|
+
if (truncateThreshold && str.length >= truncateThreshold) {
|
63
|
+
if (type === "[object Function]") {
|
64
|
+
const fn = obj;
|
65
|
+
return !fn.name || fn.name === "" ? "[Function]" : `[Function: ${fn.name}]`;
|
66
|
+
} else if (type === "[object Array]") {
|
67
|
+
return `[ Array(${obj.length}) ]`;
|
68
|
+
} else if (type === "[object Object]") {
|
69
|
+
const keys = Object.keys(obj);
|
70
|
+
const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", ");
|
71
|
+
return `{ Object (${kstr}) }`;
|
72
|
+
} else {
|
73
|
+
return str;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return str;
|
77
|
+
}
|
78
|
+
|
79
|
+
export { format as f, loupeInspect as l, objDisplay as o, stringify as s, utilInspect as u };
|
package/dist/diff.d.ts
CHANGED
@@ -1,14 +1,114 @@
|
|
1
|
+
import { CompareKeys } from 'pretty-format';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Diff Match and Patch
|
5
|
+
* Copyright 2018 The diff-match-patch Authors.
|
6
|
+
* https://github.com/google/diff-match-patch
|
7
|
+
*
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
* you may not use this file except in compliance with the License.
|
10
|
+
* You may obtain a copy of the License at
|
11
|
+
*
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
* See the License for the specific language governing permissions and
|
18
|
+
* limitations under the License.
|
19
|
+
*/
|
20
|
+
/**
|
21
|
+
* @fileoverview Computes the difference between two texts to create a patch.
|
22
|
+
* Applies the patch onto another text, allowing for errors.
|
23
|
+
* @author fraser@google.com (Neil Fraser)
|
24
|
+
*/
|
25
|
+
/**
|
26
|
+
* CHANGES by pedrottimark to diff_match_patch_uncompressed.ts file:
|
27
|
+
*
|
28
|
+
* 1. Delete anything not needed to use diff_cleanupSemantic method
|
29
|
+
* 2. Convert from prototype properties to var declarations
|
30
|
+
* 3. Convert Diff to class from constructor and prototype
|
31
|
+
* 4. Add type annotations for arguments and return values
|
32
|
+
* 5. Add exports
|
33
|
+
*/
|
34
|
+
/**
|
35
|
+
* The data structure representing a diff is an array of tuples:
|
36
|
+
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
|
37
|
+
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
|
38
|
+
*/
|
39
|
+
declare const DIFF_DELETE = -1;
|
40
|
+
declare const DIFF_INSERT = 1;
|
41
|
+
declare const DIFF_EQUAL = 0;
|
42
|
+
/**
|
43
|
+
* Class representing one diff tuple.
|
44
|
+
* Attempts to look like a two-element array (which is what this used to be).
|
45
|
+
* @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.
|
46
|
+
* @param {string} text Text to be deleted, inserted, or retained.
|
47
|
+
* @constructor
|
48
|
+
*/
|
49
|
+
declare class Diff {
|
50
|
+
0: number;
|
51
|
+
1: string;
|
52
|
+
constructor(op: number, text: string);
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
57
|
+
*
|
58
|
+
* This source code is licensed under the MIT license found in the
|
59
|
+
* LICENSE file in the root directory of this source tree.
|
60
|
+
*/
|
61
|
+
|
62
|
+
type DiffOptionsColor = (arg: string) => string;
|
1
63
|
interface DiffOptions {
|
2
|
-
|
64
|
+
aAnnotation?: string;
|
65
|
+
aColor?: DiffOptionsColor;
|
66
|
+
aIndicator?: string;
|
67
|
+
bAnnotation?: string;
|
68
|
+
bColor?: DiffOptionsColor;
|
69
|
+
bIndicator?: string;
|
70
|
+
changeColor?: DiffOptionsColor;
|
71
|
+
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
72
|
+
commonColor?: DiffOptionsColor;
|
73
|
+
commonIndicator?: string;
|
74
|
+
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
75
|
+
contextLines?: number;
|
76
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
77
|
+
expand?: boolean;
|
78
|
+
includeChangeCounts?: boolean;
|
79
|
+
omitAnnotationLines?: boolean;
|
80
|
+
patchColor?: DiffOptionsColor;
|
81
|
+
compareKeys?: CompareKeys;
|
3
82
|
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
86
|
+
*
|
87
|
+
* This source code is licensed under the MIT license found in the
|
88
|
+
* LICENSE file in the root directory of this source tree.
|
89
|
+
*/
|
90
|
+
|
91
|
+
declare function diffLinesUnified(aLines: Array<string>, bLines: Array<string>, options?: DiffOptions): string;
|
92
|
+
declare function diffLinesUnified2(aLinesDisplay: Array<string>, bLinesDisplay: Array<string>, aLinesCompare: Array<string>, bLinesCompare: Array<string>, options?: DiffOptions): string;
|
93
|
+
declare function diffLinesRaw(aLines: Array<string>, bLines: Array<string>): Array<Diff>;
|
94
|
+
|
4
95
|
/**
|
5
|
-
*
|
96
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
97
|
+
*
|
98
|
+
* This source code is licensed under the MIT license found in the
|
99
|
+
* LICENSE file in the root directory of this source tree.
|
100
|
+
*/
|
101
|
+
|
102
|
+
declare function diffStringsUnified(a: string, b: string, options?: DiffOptions): string;
|
103
|
+
declare function diffStringsRaw(a: string, b: string, cleanup: boolean): Array<Diff>;
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
6
107
|
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
* @param {String} expected
|
10
|
-
* @return {string} The diff.
|
108
|
+
* This source code is licensed under the MIT license found in the
|
109
|
+
* LICENSE file in the root directory of this source tree.
|
11
110
|
*/
|
12
|
-
declare function unifiedDiff(actual: unknown, expected: unknown, options?: DiffOptions): string;
|
13
111
|
|
14
|
-
|
112
|
+
declare function diff(a: any, b: any, options?: DiffOptions): string | null;
|
113
|
+
|
114
|
+
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, DiffOptions, DiffOptionsColor, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified };
|