@vitest/utils 4.0.0-beta.10 → 4.0.0-beta.12
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.js +5 -4
- package/dist/display.d.ts +28 -0
- package/dist/display.js +727 -0
- package/dist/error.d.ts +2 -3
- package/dist/error.js +6 -126
- package/dist/helpers.d.ts +6 -2
- 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 -79
- 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 -120
- package/dist/source-map.js +160 -535
- package/dist/timers.d.ts +18 -0
- package/dist/timers.js +32 -0
- package/package.json +30 -6
- package/dist/chunk-helpers.js +0 -329
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
|
|
2
|
+
const IS_COLLECTION_SYMBOL = "@@__IMMUTABLE_ITERABLE__@@";
|
|
3
|
+
function isImmutable(v) {
|
|
4
|
+
return v && (v[IS_COLLECTION_SYMBOL] || v[IS_RECORD_SYMBOL]);
|
|
5
|
+
}
|
|
6
|
+
const OBJECT_PROTO = Object.getPrototypeOf({});
|
|
7
|
+
function getUnserializableMessage(err) {
|
|
8
|
+
if (err instanceof Error) {
|
|
9
|
+
return `<unserializable>: ${err.message}`;
|
|
10
|
+
}
|
|
11
|
+
if (typeof err === "string") {
|
|
12
|
+
return `<unserializable>: ${err}`;
|
|
13
|
+
}
|
|
14
|
+
return "<unserializable>";
|
|
15
|
+
}
|
|
16
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
|
|
17
|
+
function serializeValue(val, seen = new WeakMap()) {
|
|
18
|
+
if (!val || typeof val === "string") {
|
|
19
|
+
return val;
|
|
20
|
+
}
|
|
21
|
+
if (val instanceof Error && "toJSON" in val && typeof val.toJSON === "function") {
|
|
22
|
+
const jsonValue = val.toJSON();
|
|
23
|
+
if (jsonValue && jsonValue !== val && typeof jsonValue === "object") {
|
|
24
|
+
if (typeof val.message === "string") {
|
|
25
|
+
safe(() => jsonValue.message ?? (jsonValue.message = normalizeErrorMessage(val.message)));
|
|
26
|
+
}
|
|
27
|
+
if (typeof val.stack === "string") {
|
|
28
|
+
safe(() => jsonValue.stack ?? (jsonValue.stack = val.stack));
|
|
29
|
+
}
|
|
30
|
+
if (typeof val.name === "string") {
|
|
31
|
+
safe(() => jsonValue.name ?? (jsonValue.name = val.name));
|
|
32
|
+
}
|
|
33
|
+
if (val.cause != null) {
|
|
34
|
+
safe(() => jsonValue.cause ?? (jsonValue.cause = serializeValue(val.cause, seen)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return serializeValue(jsonValue, seen);
|
|
38
|
+
}
|
|
39
|
+
if (typeof val === "function") {
|
|
40
|
+
return `Function<${val.name || "anonymous"}>`;
|
|
41
|
+
}
|
|
42
|
+
if (typeof val === "symbol") {
|
|
43
|
+
return val.toString();
|
|
44
|
+
}
|
|
45
|
+
if (typeof val !== "object") {
|
|
46
|
+
return val;
|
|
47
|
+
}
|
|
48
|
+
if (typeof Buffer !== "undefined" && val instanceof Buffer) {
|
|
49
|
+
return `<Buffer(${val.length}) ...>`;
|
|
50
|
+
}
|
|
51
|
+
if (typeof Uint8Array !== "undefined" && val instanceof Uint8Array) {
|
|
52
|
+
return `<Uint8Array(${val.length}) ...>`;
|
|
53
|
+
}
|
|
54
|
+
// cannot serialize immutables as immutables
|
|
55
|
+
if (isImmutable(val)) {
|
|
56
|
+
return serializeValue(val.toJSON(), seen);
|
|
57
|
+
}
|
|
58
|
+
if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction") {
|
|
59
|
+
return "Promise";
|
|
60
|
+
}
|
|
61
|
+
if (typeof Element !== "undefined" && val instanceof Element) {
|
|
62
|
+
return val.tagName;
|
|
63
|
+
}
|
|
64
|
+
if (typeof val.toJSON === "function") {
|
|
65
|
+
return serializeValue(val.toJSON(), seen);
|
|
66
|
+
}
|
|
67
|
+
if (seen.has(val)) {
|
|
68
|
+
return seen.get(val);
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(val)) {
|
|
71
|
+
// eslint-disable-next-line unicorn/no-new-array -- we need to keep sparse arrays ([1,,3])
|
|
72
|
+
const clone = new Array(val.length);
|
|
73
|
+
seen.set(val, clone);
|
|
74
|
+
val.forEach((e, i) => {
|
|
75
|
+
try {
|
|
76
|
+
clone[i] = serializeValue(e, seen);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
clone[i] = getUnserializableMessage(err);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return clone;
|
|
82
|
+
} else {
|
|
83
|
+
// Objects with `Error` constructors appear to cause problems during worker communication
|
|
84
|
+
// using `MessagePort`, so the serialized error object is being recreated as plain object.
|
|
85
|
+
const clone = Object.create(null);
|
|
86
|
+
seen.set(val, clone);
|
|
87
|
+
let obj = val;
|
|
88
|
+
while (obj && obj !== OBJECT_PROTO) {
|
|
89
|
+
Object.getOwnPropertyNames(obj).forEach((key) => {
|
|
90
|
+
if (key in clone) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
clone[key] = serializeValue(val[key], seen);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
// delete in case it has a setter from prototype that might throw
|
|
97
|
+
delete clone[key];
|
|
98
|
+
clone[key] = getUnserializableMessage(err);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
obj = Object.getPrototypeOf(obj);
|
|
102
|
+
}
|
|
103
|
+
if (val instanceof Error) {
|
|
104
|
+
safe(() => val.message = normalizeErrorMessage(val.message));
|
|
105
|
+
}
|
|
106
|
+
return clone;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function safe(fn) {
|
|
110
|
+
try {
|
|
111
|
+
return fn();
|
|
112
|
+
} catch {}
|
|
113
|
+
}
|
|
114
|
+
function normalizeErrorMessage(message) {
|
|
115
|
+
return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { serializeValue };
|
package/dist/source-map.d.ts
CHANGED
|
@@ -1,129 +1,11 @@
|
|
|
1
1
|
import { TestError, ParsedStack } from './types.js';
|
|
2
2
|
|
|
3
|
-
type GeneratedColumn = number;
|
|
4
|
-
type SourcesIndex = number;
|
|
5
|
-
type SourceLine = number;
|
|
6
|
-
type SourceColumn = number;
|
|
7
|
-
type NamesIndex = number;
|
|
8
|
-
type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
|
9
|
-
|
|
10
|
-
interface SourceMapV3 {
|
|
11
|
-
file?: string | null;
|
|
12
|
-
names: string[];
|
|
13
|
-
sourceRoot?: string;
|
|
14
|
-
sources: (string | null)[];
|
|
15
|
-
sourcesContent?: (string | null)[];
|
|
16
|
-
version: 3;
|
|
17
|
-
ignoreList?: number[];
|
|
18
|
-
}
|
|
19
|
-
interface EncodedSourceMap extends SourceMapV3 {
|
|
20
|
-
mappings: string;
|
|
21
|
-
}
|
|
22
|
-
interface DecodedSourceMap extends SourceMapV3 {
|
|
23
|
-
mappings: SourceMapSegment[][];
|
|
24
|
-
}
|
|
25
3
|
type OriginalMapping = {
|
|
26
4
|
source: string | null;
|
|
27
5
|
line: number;
|
|
28
6
|
column: number;
|
|
29
7
|
name: string | null;
|
|
30
8
|
};
|
|
31
|
-
type InvalidOriginalMapping = {
|
|
32
|
-
source: null;
|
|
33
|
-
line: null;
|
|
34
|
-
column: null;
|
|
35
|
-
name: null;
|
|
36
|
-
};
|
|
37
|
-
type GeneratedMapping = {
|
|
38
|
-
line: number;
|
|
39
|
-
column: number;
|
|
40
|
-
};
|
|
41
|
-
type InvalidGeneratedMapping = {
|
|
42
|
-
line: null;
|
|
43
|
-
column: null;
|
|
44
|
-
};
|
|
45
|
-
type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
|
46
|
-
type XInput = {
|
|
47
|
-
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
|
48
|
-
};
|
|
49
|
-
type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
|
50
|
-
type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
51
|
-
type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
|
52
|
-
type Needle = {
|
|
53
|
-
line: number;
|
|
54
|
-
column: number;
|
|
55
|
-
bias?: Bias;
|
|
56
|
-
};
|
|
57
|
-
type SourceNeedle = {
|
|
58
|
-
source: string;
|
|
59
|
-
line: number;
|
|
60
|
-
column: number;
|
|
61
|
-
bias?: Bias;
|
|
62
|
-
};
|
|
63
|
-
type EachMapping = {
|
|
64
|
-
generatedLine: number;
|
|
65
|
-
generatedColumn: number;
|
|
66
|
-
source: null;
|
|
67
|
-
originalLine: null;
|
|
68
|
-
originalColumn: null;
|
|
69
|
-
name: null;
|
|
70
|
-
} | {
|
|
71
|
-
generatedLine: number;
|
|
72
|
-
generatedColumn: number;
|
|
73
|
-
source: string | null;
|
|
74
|
-
originalLine: number;
|
|
75
|
-
originalColumn: number;
|
|
76
|
-
name: string | null;
|
|
77
|
-
};
|
|
78
|
-
declare abstract class SourceMap {
|
|
79
|
-
version: SourceMapV3['version'];
|
|
80
|
-
file: SourceMapV3['file'];
|
|
81
|
-
names: SourceMapV3['names'];
|
|
82
|
-
sourceRoot: SourceMapV3['sourceRoot'];
|
|
83
|
-
sources: SourceMapV3['sources'];
|
|
84
|
-
sourcesContent: SourceMapV3['sourcesContent'];
|
|
85
|
-
resolvedSources: SourceMapV3['sources'];
|
|
86
|
-
ignoreList: SourceMapV3['ignoreList'];
|
|
87
|
-
}
|
|
88
|
-
type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
|
|
89
|
-
type RoArray<T> = Ro<T>[];
|
|
90
|
-
type RoObject<T> = {
|
|
91
|
-
[K in keyof T]: T[K] | Ro<T[K]>;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
declare const LEAST_UPPER_BOUND = -1;
|
|
95
|
-
declare const GREATEST_LOWER_BOUND = 1;
|
|
96
|
-
|
|
97
|
-
declare class TraceMap implements SourceMap {
|
|
98
|
-
version: SourceMapV3['version'];
|
|
99
|
-
file: SourceMapV3['file'];
|
|
100
|
-
names: SourceMapV3['names'];
|
|
101
|
-
sourceRoot: SourceMapV3['sourceRoot'];
|
|
102
|
-
sources: SourceMapV3['sources'];
|
|
103
|
-
sourcesContent: SourceMapV3['sourcesContent'];
|
|
104
|
-
ignoreList: SourceMapV3['ignoreList'];
|
|
105
|
-
resolvedSources: string[];
|
|
106
|
-
private _encoded;
|
|
107
|
-
private _decoded;
|
|
108
|
-
private _decodedMemo;
|
|
109
|
-
private _bySources;
|
|
110
|
-
private _bySourceMemos;
|
|
111
|
-
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
115
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
116
|
-
* `source-map` library.
|
|
117
|
-
*/
|
|
118
|
-
declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
|
|
119
|
-
/**
|
|
120
|
-
* Finds the generated line/column position of the provided source/line/column source position.
|
|
121
|
-
*/
|
|
122
|
-
declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
|
123
|
-
/**
|
|
124
|
-
* Iterates each mapping in generated position order.
|
|
125
|
-
*/
|
|
126
|
-
declare function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void;
|
|
127
9
|
|
|
128
10
|
interface StackTraceParserOptions {
|
|
129
11
|
ignoreStackEntries?: (RegExp | string)[];
|
|
@@ -139,6 +21,35 @@ declare function parseSingleV8Stack(raw: string): ParsedStack | null;
|
|
|
139
21
|
declare function createStackString(stacks: ParsedStack[]): string;
|
|
140
22
|
declare function parseStacktrace(stack: string, options?: StackTraceParserOptions): ParsedStack[];
|
|
141
23
|
declare function parseErrorStacktrace(e: TestError | Error, options?: StackTraceParserOptions): ParsedStack[];
|
|
24
|
+
interface SourceMapLike {
|
|
25
|
+
version: number;
|
|
26
|
+
mappings?: string;
|
|
27
|
+
names?: string[];
|
|
28
|
+
sources?: string[];
|
|
29
|
+
sourcesContent?: string[];
|
|
30
|
+
sourceRoot?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Needle {
|
|
33
|
+
line: number;
|
|
34
|
+
column: number;
|
|
35
|
+
}
|
|
36
|
+
declare class DecodedMap {
|
|
37
|
+
map: SourceMapLike;
|
|
38
|
+
_encoded: string;
|
|
39
|
+
_decoded: undefined | number[][][];
|
|
40
|
+
_decodedMemo: Stats;
|
|
41
|
+
url: string;
|
|
42
|
+
version: number;
|
|
43
|
+
names: string[];
|
|
44
|
+
resolvedSources: string[];
|
|
45
|
+
constructor(map: SourceMapLike, from: string);
|
|
46
|
+
}
|
|
47
|
+
interface Stats {
|
|
48
|
+
lastKey: number;
|
|
49
|
+
lastNeedle: number;
|
|
50
|
+
lastIndex: number;
|
|
51
|
+
}
|
|
52
|
+
declare function getOriginalPosition(map: DecodedMap, needle: Needle): OriginalMapping | null;
|
|
142
53
|
|
|
143
|
-
export {
|
|
144
|
-
export type {
|
|
54
|
+
export { DecodedMap, createStackString, stackIgnorePatterns as defaultStackIgnorePatterns, getOriginalPosition, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
|
55
|
+
export type { StackTraceParserOptions };
|