@vitest/utils 4.0.14 → 4.0.16

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/display.d.ts CHANGED
@@ -21,8 +21,9 @@ interface StringifyOptions extends PrettyFormatOptions {
21
21
  declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: StringifyOptions): string;
22
22
  declare const formatRegExp: RegExp;
23
23
  declare function format(...args: unknown[]): string;
24
+ declare function browserFormat(...args: unknown[]): string;
24
25
  declare function inspect(obj: unknown, options?: LoupeOptions): string;
25
26
  declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
26
27
 
27
- export { format, formatRegExp, inspect, objDisplay, stringify };
28
+ export { browserFormat, format, formatRegExp, inspect, objDisplay, stringify };
28
29
  export type { LoupeOptions, StringifyOptions };
package/dist/display.js CHANGED
@@ -609,11 +609,20 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
609
609
  }) : result;
610
610
  }
611
611
  const formatRegExp = /%[sdjifoOc%]/g;
612
- function format(...args) {
612
+ function baseFormat(args, options = {}) {
613
+ const formatArg = (item, inspecOptions) => {
614
+ if (options.prettifyObject) {
615
+ return stringify(item, undefined, {
616
+ printBasicPrototype: false,
617
+ escapeString: false
618
+ });
619
+ }
620
+ return inspect(item, inspecOptions);
621
+ };
613
622
  if (typeof args[0] !== "string") {
614
623
  const objects = [];
615
624
  for (let i = 0; i < args.length; i++) {
616
- objects.push(inspect(args[i], {
625
+ objects.push(formatArg(args[i], {
617
626
  depth: 0,
618
627
  colors: false
619
628
  }));
@@ -643,7 +652,7 @@ function format(...args) {
643
652
  if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
644
653
  return value.toString();
645
654
  }
646
- return inspect(value, {
655
+ return formatArg(value, {
647
656
  depth: 0,
648
657
  colors: false
649
658
  });
@@ -665,11 +674,11 @@ function format(...args) {
665
674
  return Number.parseInt(String(value)).toString();
666
675
  }
667
676
  case "%f": return Number.parseFloat(String(args[i++])).toString();
668
- case "%o": return inspect(args[i++], {
677
+ case "%o": return formatArg(args[i++], {
669
678
  showHidden: true,
670
679
  showProxy: true
671
680
  });
672
- case "%O": return inspect(args[i++]);
681
+ case "%O": return formatArg(args[i++]);
673
682
  case "%c": {
674
683
  i++;
675
684
  return "";
@@ -690,11 +699,17 @@ function format(...args) {
690
699
  if (x === null || typeof x !== "object") {
691
700
  str += ` ${x}`;
692
701
  } else {
693
- str += ` ${inspect(x)}`;
702
+ str += ` ${formatArg(x)}`;
694
703
  }
695
704
  }
696
705
  return str;
697
706
  }
707
+ function format(...args) {
708
+ return baseFormat(args);
709
+ }
710
+ function browserFormat(...args) {
711
+ return baseFormat(args, { prettifyObject: true });
712
+ }
698
713
  function inspect(obj, options = {}) {
699
714
  if (options.truncate === 0) {
700
715
  options.truncate = Number.POSITIVE_INFINITY;
@@ -724,4 +739,4 @@ function objDisplay(obj, options = {}) {
724
739
  return str;
725
740
  }
726
741
 
727
- export { format, formatRegExp, inspect, objDisplay, stringify };
742
+ export { browserFormat, format, formatRegExp, inspect, objDisplay, stringify };
package/dist/timers.d.ts CHANGED
@@ -13,6 +13,21 @@ interface SafeTimers {
13
13
  }
14
14
  declare function getSafeTimers(): SafeTimers;
15
15
  declare function setSafeTimers(): void;
16
+ /**
17
+ * Returns a promise that resolves after the specified duration.
18
+ *
19
+ * @param timeout - Delay in milliseconds
20
+ * @param scheduler - Timer function to use, defaults to `setTimeout`. Useful for mocked timers.
21
+ *
22
+ * @example
23
+ * await delay(100)
24
+ *
25
+ * @example
26
+ * // With mocked timers
27
+ * const { setTimeout } = getSafeTimers()
28
+ * await delay(100, setTimeout)
29
+ */
30
+ declare function delay(timeout: number, scheduler?: typeof setTimeout): Promise<void>;
16
31
 
17
- export { getSafeTimers, setSafeTimers };
32
+ export { delay, getSafeTimers, setSafeTimers };
18
33
  export type { SafeTimers };
package/dist/timers.js CHANGED
@@ -28,5 +28,22 @@ function setSafeTimers() {
28
28
  };
29
29
  globalThis[SAFE_TIMERS_SYMBOL] = timers;
30
30
  }
31
+ /**
32
+ * Returns a promise that resolves after the specified duration.
33
+ *
34
+ * @param timeout - Delay in milliseconds
35
+ * @param scheduler - Timer function to use, defaults to `setTimeout`. Useful for mocked timers.
36
+ *
37
+ * @example
38
+ * await delay(100)
39
+ *
40
+ * @example
41
+ * // With mocked timers
42
+ * const { setTimeout } = getSafeTimers()
43
+ * await delay(100, setTimeout)
44
+ */
45
+ function delay(timeout, scheduler = setTimeout) {
46
+ return new Promise((resolve) => scheduler(resolve, timeout));
47
+ }
31
48
 
32
- export { getSafeTimers, setSafeTimers };
49
+ export { delay, getSafeTimers, setSafeTimers };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "4.0.14",
4
+ "version": "4.0.16",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -82,7 +82,7 @@
82
82
  ],
83
83
  "dependencies": {
84
84
  "tinyrainbow": "^3.0.3",
85
- "@vitest/pretty-format": "4.0.14"
85
+ "@vitest/pretty-format": "4.0.16"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@jridgewell/trace-mapping": "0.3.31",