@vitest/utils 4.0.0-beta.1 → 4.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/LICENSE +1 -1
- package/dist/chunk-_commonjsHelpers.js +1 -154
- package/dist/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +49 -0
- package/dist/diff.d.ts +2 -13
- package/dist/diff.js +6 -4
- package/dist/display.d.ts +28 -0
- package/dist/display.js +727 -0
- package/dist/error.d.ts +2 -4
- package/dist/error.js +5 -125
- package/dist/helpers.d.ts +22 -5
- package/dist/helpers.js +60 -16
- package/dist/highlight.d.ts +9 -0
- package/dist/highlight.js +538 -0
- package/dist/index.d.ts +4 -61
- package/dist/index.js +0 -632
- package/dist/offset.d.ts +5 -0
- package/dist/offset.js +32 -0
- package/dist/resolver.d.ts +7 -0
- package/dist/resolver.js +71 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +118 -0
- package/dist/source-map.d.ts +33 -117
- package/dist/source-map.js +245 -763
- package/dist/timers.d.ts +18 -0
- package/dist/timers.js +32 -0
- package/dist/types.d.ts +1 -1
- package/package.json +32 -11
package/dist/resolver.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { j as join, d as dirname } from './chunk-pathe.M-eThtNZ.js';
|
|
3
|
+
|
|
4
|
+
const packageCache = new Map();
|
|
5
|
+
function findNearestPackageData(basedir) {
|
|
6
|
+
const originalBasedir = basedir;
|
|
7
|
+
while (basedir) {
|
|
8
|
+
var _tryStatSync;
|
|
9
|
+
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
10
|
+
if (cached) {
|
|
11
|
+
return cached;
|
|
12
|
+
}
|
|
13
|
+
const pkgPath = join(basedir, "package.json");
|
|
14
|
+
if ((_tryStatSync = tryStatSync(pkgPath)) === null || _tryStatSync === void 0 ? void 0 : _tryStatSync.isFile()) {
|
|
15
|
+
const pkgData = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, "utf8")));
|
|
16
|
+
if (packageCache) {
|
|
17
|
+
setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
18
|
+
}
|
|
19
|
+
return pkgData;
|
|
20
|
+
}
|
|
21
|
+
const nextBasedir = dirname(basedir);
|
|
22
|
+
if (nextBasedir === basedir) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
basedir = nextBasedir;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
function stripBomTag(content) {
|
|
30
|
+
if (content.charCodeAt(0) === 65279) {
|
|
31
|
+
return content.slice(1);
|
|
32
|
+
}
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
function tryStatSync(file) {
|
|
36
|
+
try {
|
|
37
|
+
// The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
|
|
38
|
+
return fs.statSync(file, { throwIfNoEntry: false });
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
function getCachedData(cache, basedir, originalBasedir) {
|
|
42
|
+
const pkgData = cache.get(getFnpdCacheKey(basedir));
|
|
43
|
+
if (pkgData) {
|
|
44
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
45
|
+
cache.set(getFnpdCacheKey(dir), pkgData);
|
|
46
|
+
});
|
|
47
|
+
return pkgData;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function setCacheData(cache, data, basedir, originalBasedir) {
|
|
51
|
+
cache.set(getFnpdCacheKey(basedir), data);
|
|
52
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
53
|
+
cache.set(getFnpdCacheKey(dir), data);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function getFnpdCacheKey(basedir) {
|
|
57
|
+
return `fnpd_${basedir}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Traverse between `longerDir` (inclusive) and `shorterDir` (exclusive) and call `cb` for each dir.
|
|
61
|
+
* @param longerDir Longer dir path, e.g. `/User/foo/bar/baz`
|
|
62
|
+
* @param shorterDir Shorter dir path, e.g. `/User/foo`
|
|
63
|
+
*/
|
|
64
|
+
function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
65
|
+
while (longerDir !== shorterDir) {
|
|
66
|
+
cb(longerDir);
|
|
67
|
+
longerDir = dirname(longerDir);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { findNearestPackageData, getCachedData, setCacheData };
|
|
@@ -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,124 +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
|
-
|
|
89
|
-
declare const LEAST_UPPER_BOUND = -1;
|
|
90
|
-
declare const GREATEST_LOWER_BOUND = 1;
|
|
91
|
-
|
|
92
|
-
declare class TraceMap implements SourceMap {
|
|
93
|
-
version: SourceMapV3['version'];
|
|
94
|
-
file: SourceMapV3['file'];
|
|
95
|
-
names: SourceMapV3['names'];
|
|
96
|
-
sourceRoot: SourceMapV3['sourceRoot'];
|
|
97
|
-
sources: SourceMapV3['sources'];
|
|
98
|
-
sourcesContent: SourceMapV3['sourcesContent'];
|
|
99
|
-
ignoreList: SourceMapV3['ignoreList'];
|
|
100
|
-
resolvedSources: string[];
|
|
101
|
-
private _encoded;
|
|
102
|
-
private _decoded;
|
|
103
|
-
private _decodedMemo;
|
|
104
|
-
private _bySources;
|
|
105
|
-
private _bySourceMemos;
|
|
106
|
-
constructor(map: SourceMapInput, mapUrl?: string | null);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
110
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
111
|
-
* `source-map` library.
|
|
112
|
-
*/
|
|
113
|
-
declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
|
|
114
|
-
/**
|
|
115
|
-
* Finds the generated line/column position of the provided source/line/column source position.
|
|
116
|
-
*/
|
|
117
|
-
declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
|
118
|
-
/**
|
|
119
|
-
* Iterates each mapping in generated position order.
|
|
120
|
-
*/
|
|
121
|
-
declare function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void;
|
|
122
9
|
|
|
123
10
|
interface StackTraceParserOptions {
|
|
124
11
|
ignoreStackEntries?: (RegExp | string)[];
|
|
@@ -126,14 +13,43 @@ interface StackTraceParserOptions {
|
|
|
126
13
|
getUrlId?: (id: string) => string;
|
|
127
14
|
frameFilter?: (error: TestError, frame: ParsedStack) => boolean | void;
|
|
128
15
|
}
|
|
16
|
+
declare const stackIgnorePatterns: (string | RegExp)[];
|
|
17
|
+
|
|
129
18
|
declare function parseSingleFFOrSafariStack(raw: string): ParsedStack | null;
|
|
130
19
|
declare function parseSingleStack(raw: string): ParsedStack | null;
|
|
131
|
-
// Based on https://github.com/stacktracejs/error-stack-parser
|
|
132
|
-
// Credit to stacktracejs
|
|
133
20
|
declare function parseSingleV8Stack(raw: string): ParsedStack | null;
|
|
134
21
|
declare function createStackString(stacks: ParsedStack[]): string;
|
|
135
22
|
declare function parseStacktrace(stack: string, options?: StackTraceParserOptions): ParsedStack[];
|
|
136
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;
|
|
137
53
|
|
|
138
|
-
export {
|
|
139
|
-
export type {
|
|
54
|
+
export { DecodedMap, createStackString, stackIgnorePatterns as defaultStackIgnorePatterns, getOriginalPosition, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|
|
55
|
+
export type { StackTraceParserOptions };
|