@vitest/utils 3.2.0-beta.3 → 3.2.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/error.js CHANGED
@@ -25,6 +25,24 @@ function serializeValue(val, seen = new WeakMap()) {
25
25
  if (!val || typeof val === "string") {
26
26
  return val;
27
27
  }
28
+ if (val instanceof Error && "toJSON" in val && typeof val.toJSON === "function") {
29
+ const jsonValue = val.toJSON();
30
+ if (jsonValue && jsonValue !== val && typeof jsonValue === "object") {
31
+ if (typeof val.message === "string") {
32
+ safe(() => jsonValue.message ?? (jsonValue.message = val.message));
33
+ }
34
+ if (typeof val.stack === "string") {
35
+ safe(() => jsonValue.stack ?? (jsonValue.stack = val.stack));
36
+ }
37
+ if (typeof val.name === "string") {
38
+ safe(() => jsonValue.name ?? (jsonValue.name = val.name));
39
+ }
40
+ if (val.cause != null) {
41
+ safe(() => jsonValue.cause ?? (jsonValue.cause = serializeValue(val.cause, seen)));
42
+ }
43
+ }
44
+ return serializeValue(jsonValue, seen);
45
+ }
28
46
  if (typeof val === "function") {
29
47
  return `Function<${val.name || "anonymous"}>`;
30
48
  }
@@ -89,6 +107,11 @@ function serializeValue(val, seen = new WeakMap()) {
89
107
  return clone;
90
108
  }
91
109
  }
110
+ function safe(fn) {
111
+ try {
112
+ return fn();
113
+ } catch {}
114
+ }
92
115
  function normalizeErrorMessage(message) {
93
116
  return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
94
117
  }
@@ -97,24 +120,16 @@ function processError(_err, diffOptions, seen = new WeakSet()) {
97
120
  return { message: String(_err) };
98
121
  }
99
122
  const err = _err;
100
- // stack is not serialized in worker communication
101
- // we stringify it first
102
- if (typeof err.stack === "string") {
103
- err.stackStr = String(err.stack);
104
- }
105
- if (typeof err.name === "string") {
106
- err.nameStr = String(err.name);
107
- }
108
123
  if (err.showDiff || err.showDiff === undefined && err.expected !== undefined && err.actual !== undefined) {
109
124
  err.diff = printDiffOrStringify(err.actual, err.expected, {
110
125
  ...diffOptions,
111
126
  ...err.diffOptions
112
127
  });
113
128
  }
114
- if (typeof err.expected !== "string") {
129
+ if ("expected" in err && typeof err.expected !== "string") {
115
130
  err.expected = stringify(err.expected, 10);
116
131
  }
117
- if (typeof err.actual !== "string") {
132
+ if ("actual" in err && typeof err.actual !== "string") {
118
133
  err.actual = stringify(err.actual, 10);
119
134
  }
120
135
  // some Error implementations don't allow rewriting message
@@ -973,7 +973,7 @@ function parseErrorStacktrace(e, options = {}) {
973
973
  if (e.stacks) {
974
974
  return e.stacks;
975
975
  }
976
- const stackStr = e.stack || e.stackStr || "";
976
+ const stackStr = e.stack || "";
977
977
  // if "stack" property was overwritten at runtime to be something else,
978
978
  // ignore the value because we don't know how to process it
979
979
  let stackFrames = typeof stackStr === "string" ? parseStacktrace(stackStr, options) : [];
package/dist/types.d.ts CHANGED
@@ -38,9 +38,7 @@ interface ErrorWithDiff {
38
38
  message: string;
39
39
  name?: string;
40
40
  cause?: unknown;
41
- nameStr?: string;
42
41
  stack?: string;
43
- stackStr?: string;
44
42
  stacks?: ParsedStack[];
45
43
  showDiff?: boolean;
46
44
  actual?: any;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "3.2.0-beta.3",
4
+ "version": "3.2.0",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -62,7 +62,7 @@
62
62
  "dependencies": {
63
63
  "loupe": "^3.1.3",
64
64
  "tinyrainbow": "^2.0.0",
65
- "@vitest/pretty-format": "3.2.0-beta.3"
65
+ "@vitest/pretty-format": "3.2.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@jridgewell/trace-mapping": "^0.3.25",