@vitest/utils 0.31.1 → 0.31.3

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/diff.js CHANGED
@@ -103,6 +103,8 @@ function unifiedDiff(actual, expected, options = {}) {
103
103
  else if (line.startsWith(minus))
104
104
  counts["-"]++;
105
105
  });
106
+ if (counts["+"] === 0 && counts["-"] === 0)
107
+ return "";
106
108
  let legend = "";
107
109
  if (showLegend) {
108
110
  legend = ` ${c.green(`- Expected - ${counts["-"]}`)}
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Nullable, Arrayable } from './types.js';
2
2
 
3
+ interface CloneOptions {
4
+ forceWritable?: boolean;
5
+ }
3
6
  declare function notNullish<T>(v: T | null | undefined): v is NonNullable<T>;
4
7
  declare function assertTypes(value: unknown, name: string, types: string[]): void;
5
8
  declare function isPrimitive(value: unknown): boolean;
@@ -9,8 +12,8 @@ declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
9
12
  declare function isObject(item: unknown): boolean;
10
13
  declare function getType(value: unknown): string;
11
14
  declare function getOwnProperties(obj: any): (string | symbol)[];
12
- declare function deepClone<T>(val: T): T;
13
- declare function clone<T>(val: T, seen: WeakMap<any, any>): T;
15
+ declare function deepClone<T>(val: T, options?: CloneOptions): T;
16
+ declare function clone<T>(val: T, seen: WeakMap<any, any>, options?: CloneOptions): T;
14
17
  declare function noop(): void;
15
18
  declare function objectAttr(source: any, path: string, defaultValue?: undefined): any;
16
19
  type DeferPromise<T> = Promise<T> & {
package/dist/helpers.js CHANGED
@@ -49,11 +49,12 @@ function getOwnProperties(obj) {
49
49
  collectOwnProperties(obj, ownProps);
50
50
  return Array.from(ownProps);
51
51
  }
52
- function deepClone(val) {
52
+ const defaultCloneOptions = { forceWritable: false };
53
+ function deepClone(val, options = defaultCloneOptions) {
53
54
  const seen = /* @__PURE__ */ new WeakMap();
54
- return clone(val, seen);
55
+ return clone(val, seen, options);
55
56
  }
56
- function clone(val, seen) {
57
+ function clone(val, seen, options = defaultCloneOptions) {
57
58
  let k, out;
58
59
  if (seen.has(val))
59
60
  return seen.get(val);
@@ -83,6 +84,7 @@ function clone(val, seen) {
83
84
  } else {
84
85
  Object.defineProperty(out, k2, {
85
86
  ...descriptor,
87
+ writable: options.forceWritable ? true : descriptor.writable,
86
88
  value: cloned
87
89
  });
88
90
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "0.31.1",
4
+ "version": "0.31.3",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",