@vitest/utils 2.0.0-beta.1 → 2.0.0-beta.11
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/ast.js +65 -34
- package/dist/chunk-colors.js +15 -8
- package/dist/chunk-display.js +26 -14
- package/dist/diff.js +140 -63
- package/dist/error.js +61 -28
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +44 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -11
- package/dist/source-map.js +68 -30
- package/package.json +5 -2
package/dist/helpers.js
CHANGED
@@ -4,8 +4,11 @@ function notNullish(v) {
|
|
4
4
|
function assertTypes(value, name, types) {
|
5
5
|
const receivedType = typeof value;
|
6
6
|
const pass = types.includes(receivedType);
|
7
|
-
if (!pass)
|
8
|
-
throw new TypeError(
|
7
|
+
if (!pass) {
|
8
|
+
throw new TypeError(
|
9
|
+
`${name} value must be ${types.join(" or ")}, received "${receivedType}"`
|
10
|
+
);
|
11
|
+
}
|
9
12
|
}
|
10
13
|
function isPrimitive(value) {
|
11
14
|
return value === null || typeof value !== "function" && typeof value !== "object";
|
@@ -15,17 +18,21 @@ function slash(path) {
|
|
15
18
|
}
|
16
19
|
function parseRegexp(input) {
|
17
20
|
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
|
18
|
-
if (!m)
|
21
|
+
if (!m) {
|
19
22
|
return /$^/;
|
20
|
-
|
23
|
+
}
|
24
|
+
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
|
21
25
|
return RegExp(input);
|
26
|
+
}
|
22
27
|
return new RegExp(m[2], m[3]);
|
23
28
|
}
|
24
29
|
function toArray(array) {
|
25
|
-
if (array === null || array === void 0)
|
30
|
+
if (array === null || array === void 0) {
|
26
31
|
array = [];
|
27
|
-
|
32
|
+
}
|
33
|
+
if (Array.isArray(array)) {
|
28
34
|
return array;
|
35
|
+
}
|
29
36
|
return [array];
|
30
37
|
}
|
31
38
|
function isObject(item) {
|
@@ -44,8 +51,9 @@ function collectOwnProperties(obj, collector) {
|
|
44
51
|
}
|
45
52
|
function getOwnProperties(obj) {
|
46
53
|
const ownProps = /* @__PURE__ */ new Set();
|
47
|
-
if (isFinalObj(obj))
|
54
|
+
if (isFinalObj(obj)) {
|
48
55
|
return [];
|
56
|
+
}
|
49
57
|
collectOwnProperties(obj, ownProps);
|
50
58
|
return Array.from(ownProps);
|
51
59
|
}
|
@@ -56,12 +64,15 @@ function deepClone(val, options = defaultCloneOptions) {
|
|
56
64
|
}
|
57
65
|
function clone(val, seen, options = defaultCloneOptions) {
|
58
66
|
let k, out;
|
59
|
-
if (seen.has(val))
|
67
|
+
if (seen.has(val)) {
|
60
68
|
return seen.get(val);
|
69
|
+
}
|
61
70
|
if (Array.isArray(val)) {
|
62
71
|
out = Array(k = val.length);
|
63
72
|
seen.set(val, out);
|
64
|
-
while (k--)
|
73
|
+
while (k--) {
|
74
|
+
out[k] = clone(val[k], seen, options);
|
75
|
+
}
|
65
76
|
return out;
|
66
77
|
}
|
67
78
|
if (Object.prototype.toString.call(val) === "[object Object]") {
|
@@ -70,8 +81,9 @@ function clone(val, seen, options = defaultCloneOptions) {
|
|
70
81
|
const props = getOwnProperties(val);
|
71
82
|
for (const k2 of props) {
|
72
83
|
const descriptor = Object.getOwnPropertyDescriptor(val, k2);
|
73
|
-
if (!descriptor)
|
84
|
+
if (!descriptor) {
|
74
85
|
continue;
|
86
|
+
}
|
75
87
|
const cloned = clone(val[k2], seen, options);
|
76
88
|
if (options.forceWritable) {
|
77
89
|
Object.defineProperty(out, k2, {
|
@@ -105,8 +117,9 @@ function objectAttr(source, path, defaultValue = void 0) {
|
|
105
117
|
let result = source;
|
106
118
|
for (const p of paths) {
|
107
119
|
result = Object(result)[p];
|
108
|
-
if (result === void 0)
|
120
|
+
if (result === void 0) {
|
109
121
|
return defaultValue;
|
122
|
+
}
|
110
123
|
}
|
111
124
|
return result;
|
112
125
|
}
|
@@ -133,21 +146,35 @@ function getCallLastIndex(code) {
|
|
133
146
|
const char = code[charIndex];
|
134
147
|
const isCharString = char === '"' || char === "'" || char === "`";
|
135
148
|
if (isCharString && beforeChar !== "\\") {
|
136
|
-
if (inString === char)
|
149
|
+
if (inString === char) {
|
137
150
|
inString = null;
|
138
|
-
else if (!inString)
|
151
|
+
} else if (!inString) {
|
139
152
|
inString = char;
|
153
|
+
}
|
140
154
|
}
|
141
155
|
if (!inString) {
|
142
|
-
if (char === "(")
|
156
|
+
if (char === "(") {
|
143
157
|
startedBracers++;
|
144
|
-
|
158
|
+
}
|
159
|
+
if (char === ")") {
|
145
160
|
endedBracers++;
|
161
|
+
}
|
146
162
|
}
|
147
|
-
if (startedBracers && endedBracers && startedBracers === endedBracers)
|
163
|
+
if (startedBracers && endedBracers && startedBracers === endedBracers) {
|
148
164
|
return charIndex;
|
165
|
+
}
|
149
166
|
}
|
150
167
|
return null;
|
151
168
|
}
|
169
|
+
function isNegativeNaN(val) {
|
170
|
+
if (!Number.isNaN(val)) {
|
171
|
+
return false;
|
172
|
+
}
|
173
|
+
const f64 = new Float64Array(1);
|
174
|
+
f64[0] = val;
|
175
|
+
const u32 = new Uint32Array(f64.buffer);
|
176
|
+
const isNegative = u32[1] >>> 31 === 1;
|
177
|
+
return isNegative;
|
178
|
+
}
|
152
179
|
|
153
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
180
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
|
3
3
|
import { PrettyFormatOptions } from 'pretty-format';
|
4
4
|
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
3
3
|
import { S as SAFE_TIMERS_SYMBOL, g as getColors } from './chunk-colors.js';
|
4
4
|
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
@@ -14,9 +14,7 @@ function getSafeTimers() {
|
|
14
14
|
setImmediate: safeSetImmediate,
|
15
15
|
clearImmediate: safeClearImmediate
|
16
16
|
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
17
|
-
const {
|
18
|
-
nextTick: safeNextTick
|
19
|
-
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
17
|
+
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
20
18
|
return {
|
21
19
|
nextTick: safeNextTick,
|
22
20
|
setTimeout: safeSetTimeout,
|
@@ -36,9 +34,9 @@ function setSafeTimers() {
|
|
36
34
|
setImmediate: safeSetImmediate,
|
37
35
|
clearImmediate: safeClearImmediate
|
38
36
|
} = globalThis;
|
39
|
-
const {
|
40
|
-
nextTick:
|
41
|
-
}
|
37
|
+
const { nextTick: safeNextTick } = globalThis.process || {
|
38
|
+
nextTick: (cb) => cb()
|
39
|
+
};
|
42
40
|
const timers = {
|
43
41
|
nextTick: safeNextTick,
|
44
42
|
setTimeout: safeSetTimeout,
|
@@ -69,7 +67,7 @@ function shuffle(array, seed = RealDate.now()) {
|
|
69
67
|
}
|
70
68
|
|
71
69
|
function createSimpleStackTrace(options) {
|
72
|
-
const { message = "error", stackTraceLimit = 1 } = options || {};
|
70
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
73
71
|
const limit = Error.stackTraceLimit;
|
74
72
|
const prepareStackTrace = Error.prepareStackTrace;
|
75
73
|
Error.stackTraceLimit = stackTraceLimit;
|
@@ -86,10 +84,12 @@ function positionToOffset(source, lineNumber, columnNumber) {
|
|
86
84
|
const lines = source.split(lineSplitRE);
|
87
85
|
const nl = /\r\n/.test(source) ? 2 : 1;
|
88
86
|
let start = 0;
|
89
|
-
if (lineNumber > lines.length)
|
87
|
+
if (lineNumber > lines.length) {
|
90
88
|
return source.length;
|
91
|
-
|
89
|
+
}
|
90
|
+
for (let i = 0; i < lineNumber - 1; i++) {
|
92
91
|
start += lines[i].length + nl;
|
92
|
+
}
|
93
93
|
return start + columnNumber;
|
94
94
|
}
|
95
95
|
function offsetToLineNumber(source, offset) {
|
@@ -104,8 +104,9 @@ function offsetToLineNumber(source, offset) {
|
|
104
104
|
let line = 0;
|
105
105
|
for (; line < lines.length; line++) {
|
106
106
|
const lineLength = lines[line].length + nl;
|
107
|
-
if (counted + lineLength >= offset)
|
107
|
+
if (counted + lineLength >= offset) {
|
108
108
|
break;
|
109
|
+
}
|
109
110
|
counted += lineLength;
|
110
111
|
}
|
111
112
|
return line + 1;
|
package/dist/source-map.js
CHANGED
@@ -760,8 +760,8 @@ function generatedPosition(map, source, line, column, bias, all) {
|
|
760
760
|
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
761
761
|
}
|
762
762
|
|
763
|
-
const CHROME_IE_STACK_REGEXP = /^\s*at .*(
|
764
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(
|
763
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
764
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
765
765
|
const stackIgnorePatterns = [
|
766
766
|
"node:internal",
|
767
767
|
/\/packages\/\w+\/dist\//,
|
@@ -773,40 +773,59 @@ const stackIgnorePatterns = [
|
|
773
773
|
"/node_modules/chai/",
|
774
774
|
"/node_modules/tinypool/",
|
775
775
|
"/node_modules/tinyspy/",
|
776
|
-
|
777
|
-
/
|
776
|
+
// browser related deps
|
777
|
+
"/deps/",
|
778
|
+
/node:\w+/,
|
779
|
+
/__vitest_test__/,
|
780
|
+
/__vitest_browser__/,
|
781
|
+
/\/deps\/vitest_/
|
778
782
|
];
|
779
783
|
function extractLocation(urlLike) {
|
780
|
-
if (!urlLike.includes(":"))
|
784
|
+
if (!urlLike.includes(":")) {
|
781
785
|
return [urlLike];
|
786
|
+
}
|
782
787
|
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
783
788
|
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
784
|
-
if (!parts)
|
789
|
+
if (!parts) {
|
785
790
|
return [urlLike];
|
791
|
+
}
|
786
792
|
let url = parts[1];
|
793
|
+
if (url.startsWith("async ")) {
|
794
|
+
url = url.slice(6);
|
795
|
+
}
|
787
796
|
if (url.startsWith("http:") || url.startsWith("https:")) {
|
788
797
|
const urlObj = new URL(url);
|
789
798
|
url = urlObj.pathname;
|
790
799
|
}
|
791
800
|
if (url.startsWith("/@fs/")) {
|
792
|
-
|
801
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
802
|
+
url = url.slice(isWindows ? 5 : 4);
|
793
803
|
}
|
794
804
|
return [url, parts[2] || void 0, parts[3] || void 0];
|
795
805
|
}
|
796
806
|
function parseSingleFFOrSafariStack(raw) {
|
797
807
|
let line = raw.trim();
|
798
|
-
if (SAFARI_NATIVE_CODE_REGEXP.test(line))
|
808
|
+
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
|
799
809
|
return null;
|
800
|
-
|
801
|
-
|
802
|
-
|
810
|
+
}
|
811
|
+
if (line.includes(" > eval")) {
|
812
|
+
line = line.replace(
|
813
|
+
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
|
814
|
+
":$1"
|
815
|
+
);
|
816
|
+
}
|
817
|
+
if (!line.includes("@") && !line.includes(":")) {
|
803
818
|
return null;
|
804
|
-
|
819
|
+
}
|
820
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
805
821
|
const matches = line.match(functionNameRegex);
|
806
822
|
const functionName = matches && matches[1] ? matches[1] : void 0;
|
807
|
-
const [url, lineNumber, columnNumber] = extractLocation(
|
808
|
-
|
823
|
+
const [url, lineNumber, columnNumber] = extractLocation(
|
824
|
+
line.replace(functionNameRegex, "")
|
825
|
+
);
|
826
|
+
if (!url || !lineNumber || !columnNumber) {
|
809
827
|
return null;
|
828
|
+
}
|
810
829
|
return {
|
811
830
|
file: url,
|
812
831
|
method: functionName || "",
|
@@ -816,31 +835,40 @@ function parseSingleFFOrSafariStack(raw) {
|
|
816
835
|
}
|
817
836
|
function parseSingleStack(raw) {
|
818
837
|
const line = raw.trim();
|
819
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
838
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
820
839
|
return parseSingleFFOrSafariStack(line);
|
840
|
+
}
|
821
841
|
return parseSingleV8Stack(line);
|
822
842
|
}
|
823
843
|
function parseSingleV8Stack(raw) {
|
824
844
|
let line = raw.trim();
|
825
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
845
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
826
846
|
return null;
|
827
|
-
|
847
|
+
}
|
848
|
+
if (line.includes("(eval ")) {
|
828
849
|
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
850
|
+
}
|
829
851
|
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
830
852
|
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
831
853
|
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
832
|
-
const [url, lineNumber, columnNumber] = extractLocation(
|
854
|
+
const [url, lineNumber, columnNumber] = extractLocation(
|
855
|
+
location ? location[1] : sanitizedLine
|
856
|
+
);
|
833
857
|
let method = location && sanitizedLine || "";
|
834
858
|
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
835
|
-
if (!file || !lineNumber || !columnNumber)
|
859
|
+
if (!file || !lineNumber || !columnNumber) {
|
836
860
|
return null;
|
837
|
-
|
861
|
+
}
|
862
|
+
if (method.startsWith("async ")) {
|
838
863
|
method = method.slice(6);
|
839
|
-
|
864
|
+
}
|
865
|
+
if (file.startsWith("file://")) {
|
840
866
|
file = file.slice(7);
|
867
|
+
}
|
841
868
|
file = resolve$2(file);
|
842
|
-
if (method)
|
869
|
+
if (method) {
|
843
870
|
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
871
|
+
}
|
844
872
|
return {
|
845
873
|
method,
|
846
874
|
file,
|
@@ -851,17 +879,22 @@ function parseSingleV8Stack(raw) {
|
|
851
879
|
function parseStacktrace(stack, options = {}) {
|
852
880
|
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
853
881
|
let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
854
|
-
if (ignoreStackEntries.length)
|
855
|
-
stacks = stacks.filter(
|
882
|
+
if (ignoreStackEntries.length) {
|
883
|
+
stacks = stacks.filter(
|
884
|
+
(stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
|
885
|
+
);
|
886
|
+
}
|
856
887
|
return stacks.map((stack2) => {
|
857
888
|
var _a;
|
858
889
|
const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
|
859
|
-
if (!map || typeof map !== "object" || !map.version)
|
890
|
+
if (!map || typeof map !== "object" || !map.version) {
|
860
891
|
return stack2;
|
892
|
+
}
|
861
893
|
const traceMap = new TraceMap(map);
|
862
894
|
const { line, column } = originalPositionFor(traceMap, stack2);
|
863
|
-
if (line != null && column != null)
|
895
|
+
if (line != null && column != null) {
|
864
896
|
return { ...stack2, line, column };
|
897
|
+
}
|
865
898
|
return stack2;
|
866
899
|
});
|
867
900
|
}
|
@@ -872,14 +905,19 @@ function parseV8Stacktrace(stack) {
|
|
872
905
|
return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
|
873
906
|
}
|
874
907
|
function parseErrorStacktrace(e, options = {}) {
|
875
|
-
if (!e || isPrimitive(e))
|
908
|
+
if (!e || isPrimitive(e)) {
|
876
909
|
return [];
|
877
|
-
|
910
|
+
}
|
911
|
+
if (e.stacks) {
|
878
912
|
return e.stacks;
|
913
|
+
}
|
879
914
|
const stackStr = e.stack || e.stackStr || "";
|
880
915
|
let stackFrames = parseStacktrace(stackStr, options);
|
881
|
-
if (options.frameFilter)
|
882
|
-
stackFrames = stackFrames.filter(
|
916
|
+
if (options.frameFilter) {
|
917
|
+
stackFrames = stackFrames.filter(
|
918
|
+
(f) => options.frameFilter(e, f) !== false
|
919
|
+
);
|
920
|
+
}
|
883
921
|
e.stacks = stackFrames;
|
884
922
|
return stackFrames;
|
885
923
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.0-beta.
|
4
|
+
"version": "2.0.0-beta.11",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -47,6 +47,9 @@
|
|
47
47
|
"types": "./dist/index.d.ts",
|
48
48
|
"typesVersions": {
|
49
49
|
"*": {
|
50
|
+
"ast": [
|
51
|
+
"dist/ast.d.ts"
|
52
|
+
],
|
50
53
|
"source-map": [
|
51
54
|
"dist/source-map.d.ts"
|
52
55
|
]
|
@@ -59,7 +62,7 @@
|
|
59
62
|
"dependencies": {
|
60
63
|
"diff-sequences": "^29.6.3",
|
61
64
|
"estree-walker": "^3.0.3",
|
62
|
-
"loupe": "^3.1.
|
65
|
+
"loupe": "^3.1.1",
|
63
66
|
"pretty-format": "^29.7.0"
|
64
67
|
},
|
65
68
|
"devDependencies": {
|