@vitest/utils 4.0.13 → 4.0.15

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/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.13",
4
+ "version": "4.0.15",
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.13"
85
+ "@vitest/pretty-format": "4.0.15"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@jridgewell/trace-mapping": "0.3.31",