@vitest/runner 3.0.1 → 3.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +37 -13
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ class PendingError extends Error {
16
16
  taskId;
17
17
  }
18
18
 
19
+ const now$2 = Date.now;
19
20
  const collectorContext = {
20
21
  tasks: [],
21
22
  currentSuite: null
@@ -36,19 +37,42 @@ function withTimeout(fn, timeout, isHook = false) {
36
37
  }
37
38
  const { setTimeout, clearTimeout } = getSafeTimers();
38
39
  return function runWithTimeout(...args) {
39
- return Promise.race([
40
- new Promise((resolve, reject) => {
41
- var _a;
42
- const timer = setTimeout(() => {
43
- clearTimeout(timer);
44
- reject(new Error(makeTimeoutMsg(isHook, timeout)));
45
- }, timeout);
46
- (_a = timer.unref) == null ? undefined : _a.call(timer);
47
- }),
48
- Promise.resolve(fn(...args)).then((result) => {
49
- return new Promise((resolve) => setTimeout(resolve, 0, result));
50
- })
51
- ]);
40
+ const startTime = now$2();
41
+ return new Promise((resolve_, reject_) => {
42
+ var _a;
43
+ const timer = setTimeout(() => {
44
+ clearTimeout(timer);
45
+ reject(new Error(makeTimeoutMsg(isHook, timeout)));
46
+ }, timeout);
47
+ (_a = timer.unref) == null ? undefined : _a.call(timer);
48
+ function resolve(result) {
49
+ clearTimeout(timer);
50
+ resolve_(result);
51
+ }
52
+ function reject(error) {
53
+ clearTimeout(timer);
54
+ reject_(error);
55
+ }
56
+ try {
57
+ const result = fn(...args);
58
+ if (typeof result === "object" && result != null && typeof result.then === "function") {
59
+ result.then(
60
+ (result2) => {
61
+ if (now$2() - startTime >= timeout) {
62
+ reject(new Error(makeTimeoutMsg(isHook, timeout)));
63
+ } else {
64
+ resolve(result2);
65
+ }
66
+ },
67
+ reject
68
+ );
69
+ } else {
70
+ resolve(result);
71
+ }
72
+ } catch (error) {
73
+ reject(error);
74
+ }
75
+ });
52
76
  };
53
77
  }
54
78
  function createTestContext(test, runner) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "3.0.1",
4
+ "version": "3.0.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "pathe": "^2.0.1",
42
- "@vitest/utils": "3.0.1"
42
+ "@vitest/utils": "3.0.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",