@vitest/runner 3.1.0-beta.2 → 3.1.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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, e as TaskHook, O as OnTestFailedHandler, f as OnTestFinishedHandler, a as Test, g as Custom, S as Suite, h as SuiteHooks, F as File, i as TaskUpdateEvent, T as Task, j as TestAPI, k as SuiteAPI, l as SuiteCollector } from './tasks.d-CnuPOyeL.js';
2
- export { D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, R as RunMode, r as RuntimeContext, s as SequenceHooks, t as SequenceSetupFiles, u as SuiteFactory, v as TaskBase, w as TaskContext, x as TaskCustomOptions, y as TaskEventPack, z as TaskMeta, G as TaskPopulated, J as TaskResult, K as TaskResultPack, L as TaskState, M as TestContext, N as TestFunction, P as TestOptions, U as Use } from './tasks.d-CnuPOyeL.js';
1
+ import { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, e as TaskHook, O as OnTestFailedHandler, f as OnTestFinishedHandler, a as Test, g as Custom, S as Suite, h as SuiteHooks, F as File, i as TaskUpdateEvent, T as Task, j as TestAPI, k as SuiteAPI, l as SuiteCollector } from './tasks.d-hsdzc98-.js';
2
+ export { D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, R as RunMode, r as RuntimeContext, s as SequenceHooks, t as SequenceSetupFiles, u as SuiteFactory, v as TaskBase, w as TaskContext, x as TaskCustomOptions, y as TaskEventPack, z as TaskMeta, G as TaskPopulated, J as TaskResult, K as TaskResultPack, L as TaskState, M as TestContext, N as TestFunction, P as TestOptions, U as Use } from './tasks.d-hsdzc98-.js';
3
3
  import { Awaitable } from '@vitest/utils';
4
4
  import { FileSpecification, VitestRunner } from './types.js';
5
5
  export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getSafeTimers, isObject, createDefer, toArray, isNegativeNaN, format, objectAttr, objDisplay, assertTypes, shuffle } from '@vitest/utils';
1
+ import { isObject, createDefer, toArray, isNegativeNaN, format, objectAttr, objDisplay, getSafeTimers, assertTypes, shuffle } from '@vitest/utils';
2
2
  import { parseSingleStack } from '@vitest/utils/source-map';
3
3
  import { c as createChainable, b as createFileTask, a as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, l as limitConcurrency, p as partitionSuiteChildren, o as hasTests, n as hasFailed } from './chunk-tasks.js';
4
4
  import { processError } from '@vitest/utils/error';
@@ -16,96 +16,6 @@ class PendingError extends Error {
16
16
  }
17
17
  }
18
18
 
19
- const now$2 = Date.now;
20
- const collectorContext = {
21
- tasks: [],
22
- currentSuite: null
23
- };
24
- function collectTask(task) {
25
- var _collectorContext$cur;
26
- (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.tasks.push(task);
27
- }
28
- async function runWithSuite(suite, fn) {
29
- const prev = collectorContext.currentSuite;
30
- collectorContext.currentSuite = suite;
31
- await fn();
32
- collectorContext.currentSuite = prev;
33
- }
34
- function withTimeout(fn, timeout, isHook = false, stackTraceError) {
35
- if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
36
- return fn;
37
- }
38
- const { setTimeout, clearTimeout } = getSafeTimers();
39
- return function runWithTimeout(...args) {
40
- const startTime = now$2();
41
- return new Promise((resolve_, reject_) => {
42
- var _timer$unref;
43
- const timer = setTimeout(() => {
44
- clearTimeout(timer);
45
- rejectTimeoutError();
46
- }, timeout);
47
- (_timer$unref = timer.unref) === null || _timer$unref === void 0 ? void 0 : _timer$unref.call(timer);
48
- function rejectTimeoutError() {
49
- reject_(makeTimeoutError(isHook, timeout, stackTraceError));
50
- }
51
- function resolve(result) {
52
- clearTimeout(timer);
53
- if (now$2() - startTime >= timeout) {
54
- rejectTimeoutError();
55
- return;
56
- }
57
- resolve_(result);
58
- }
59
- function reject(error) {
60
- clearTimeout(timer);
61
- reject_(error);
62
- }
63
- try {
64
- const result = fn(...args);
65
- if (typeof result === "object" && result != null && typeof result.then === "function") {
66
- result.then(resolve, reject);
67
- } else {
68
- resolve(result);
69
- }
70
- } catch (error) {
71
- reject(error);
72
- }
73
- });
74
- };
75
- }
76
- function createTestContext(test, runner) {
77
- var _runner$extendTaskCon;
78
- const context = function() {
79
- throw new Error("done() callback is deprecated, use promise instead");
80
- };
81
- context.task = test;
82
- context.skip = (condition, note) => {
83
- if (condition === false) {
84
- return undefined;
85
- }
86
- test.result ?? (test.result = { state: "skip" });
87
- test.result.pending = true;
88
- throw new PendingError("test is skipped; abort execution", test, typeof condition === "string" ? condition : note);
89
- };
90
- context.onTestFailed = (handler, timeout) => {
91
- test.onFailed || (test.onFailed = []);
92
- test.onFailed.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR")));
93
- };
94
- context.onTestFinished = (handler, timeout) => {
95
- test.onFinished || (test.onFinished = []);
96
- test.onFinished.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR")));
97
- };
98
- return ((_runner$extendTaskCon = runner.extendTaskContext) === null || _runner$extendTaskCon === void 0 ? void 0 : _runner$extendTaskCon.call(runner, context)) || context;
99
- }
100
- function makeTimeoutError(isHook, timeout, stackTraceError) {
101
- const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.\nIf this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
102
- const error = new Error(message);
103
- if (stackTraceError === null || stackTraceError === void 0 ? void 0 : stackTraceError.stack) {
104
- error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
105
- }
106
- return error;
107
- }
108
-
109
19
  const fnMap = new WeakMap();
110
20
  const testFixtureMap = new WeakMap();
111
21
  const hooksMap = new WeakMap();
@@ -912,6 +822,103 @@ function findTestFileStackTrace(error, each) {
912
822
  }
913
823
  }
914
824
 
825
+ const now$2 = Date.now;
826
+ const collectorContext = {
827
+ tasks: [],
828
+ currentSuite: null
829
+ };
830
+ function collectTask(task) {
831
+ var _collectorContext$cur;
832
+ (_collectorContext$cur = collectorContext.currentSuite) === null || _collectorContext$cur === void 0 ? void 0 : _collectorContext$cur.tasks.push(task);
833
+ }
834
+ async function runWithSuite(suite, fn) {
835
+ const prev = collectorContext.currentSuite;
836
+ collectorContext.currentSuite = suite;
837
+ await fn();
838
+ collectorContext.currentSuite = prev;
839
+ }
840
+ function withTimeout(fn, timeout, isHook = false, stackTraceError) {
841
+ if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
842
+ return fn;
843
+ }
844
+ const { setTimeout, clearTimeout } = getSafeTimers();
845
+ return function runWithTimeout(...args) {
846
+ const startTime = now$2();
847
+ const runner = getRunner();
848
+ runner._currentTaskStartTime = startTime;
849
+ runner._currentTaskTimeout = timeout;
850
+ return new Promise((resolve_, reject_) => {
851
+ var _timer$unref;
852
+ const timer = setTimeout(() => {
853
+ clearTimeout(timer);
854
+ rejectTimeoutError();
855
+ }, timeout);
856
+ (_timer$unref = timer.unref) === null || _timer$unref === void 0 ? void 0 : _timer$unref.call(timer);
857
+ function rejectTimeoutError() {
858
+ reject_(makeTimeoutError(isHook, timeout, stackTraceError));
859
+ }
860
+ function resolve(result) {
861
+ runner._currentTaskStartTime = undefined;
862
+ runner._currentTaskTimeout = undefined;
863
+ clearTimeout(timer);
864
+ if (now$2() - startTime >= timeout) {
865
+ rejectTimeoutError();
866
+ return;
867
+ }
868
+ resolve_(result);
869
+ }
870
+ function reject(error) {
871
+ runner._currentTaskStartTime = undefined;
872
+ runner._currentTaskTimeout = undefined;
873
+ clearTimeout(timer);
874
+ reject_(error);
875
+ }
876
+ try {
877
+ const result = fn(...args);
878
+ if (typeof result === "object" && result != null && typeof result.then === "function") {
879
+ result.then(resolve, reject);
880
+ } else {
881
+ resolve(result);
882
+ }
883
+ } catch (error) {
884
+ reject(error);
885
+ }
886
+ });
887
+ };
888
+ }
889
+ function createTestContext(test, runner) {
890
+ var _runner$extendTaskCon;
891
+ const context = function() {
892
+ throw new Error("done() callback is deprecated, use promise instead");
893
+ };
894
+ context.task = test;
895
+ context.skip = (condition, note) => {
896
+ if (condition === false) {
897
+ return undefined;
898
+ }
899
+ test.result ?? (test.result = { state: "skip" });
900
+ test.result.pending = true;
901
+ throw new PendingError("test is skipped; abort execution", test, typeof condition === "string" ? condition : note);
902
+ };
903
+ context.onTestFailed = (handler, timeout) => {
904
+ test.onFailed || (test.onFailed = []);
905
+ test.onFailed.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR")));
906
+ };
907
+ context.onTestFinished = (handler, timeout) => {
908
+ test.onFinished || (test.onFinished = []);
909
+ test.onFinished.push(withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR")));
910
+ };
911
+ return ((_runner$extendTaskCon = runner.extendTaskContext) === null || _runner$extendTaskCon === void 0 ? void 0 : _runner$extendTaskCon.call(runner, context)) || context;
912
+ }
913
+ function makeTimeoutError(isHook, timeout, stackTraceError) {
914
+ const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.\nIf this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
915
+ const error = new Error(message);
916
+ if (stackTraceError === null || stackTraceError === void 0 ? void 0 : stackTraceError.stack) {
917
+ error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
918
+ }
919
+ return error;
920
+ }
921
+
915
922
  function getDefaultHookTimeout() {
916
923
  return getRunner().config.hookTimeout;
917
924
  }
@@ -1245,21 +1252,8 @@ async function callSuiteHook(suite, currentTask, name, runner, args) {
1245
1252
  }
1246
1253
  const packs = new Map();
1247
1254
  const eventsPacks = [];
1248
- let updateTimer;
1249
- let previousUpdate;
1250
- function updateTask(event, task, runner) {
1251
- eventsPacks.push([task.id, event]);
1252
- packs.set(task.id, [task.result, task.meta]);
1253
- const { clearTimeout, setTimeout } = getSafeTimers();
1254
- clearTimeout(updateTimer);
1255
- updateTimer = setTimeout(() => {
1256
- previousUpdate = sendTasksUpdate(runner);
1257
- }, 10);
1258
- }
1259
- async function sendTasksUpdate(runner) {
1260
- const { clearTimeout } = getSafeTimers();
1261
- clearTimeout(updateTimer);
1262
- await previousUpdate;
1255
+ const pendingTasksUpdates = [];
1256
+ function sendTasksUpdate(runner) {
1263
1257
  if (packs.size) {
1264
1258
  var _runner$onTaskUpdate;
1265
1259
  const taskPacks = Array.from(packs).map(([id, task]) => {
@@ -1270,11 +1264,34 @@ async function sendTasksUpdate(runner) {
1270
1264
  ];
1271
1265
  });
1272
1266
  const p = (_runner$onTaskUpdate = runner.onTaskUpdate) === null || _runner$onTaskUpdate === void 0 ? void 0 : _runner$onTaskUpdate.call(runner, taskPacks, eventsPacks);
1267
+ if (p) {
1268
+ pendingTasksUpdates.push(p);
1269
+ p.then(() => pendingTasksUpdates.splice(pendingTasksUpdates.indexOf(p), 1), () => {});
1270
+ }
1273
1271
  eventsPacks.length = 0;
1274
1272
  packs.clear();
1275
- return p;
1276
1273
  }
1277
1274
  }
1275
+ async function finishSendTasksUpdate(runner) {
1276
+ sendTasksUpdate(runner);
1277
+ await Promise.all(pendingTasksUpdates);
1278
+ }
1279
+ function throttle(fn, ms) {
1280
+ let last = 0;
1281
+ return function(...args) {
1282
+ const now = unixNow();
1283
+ if (now - last > ms) {
1284
+ last = now;
1285
+ return fn.apply(this, args);
1286
+ }
1287
+ };
1288
+ }
1289
+ const sendTasksUpdateThrottled = throttle(sendTasksUpdate, 100);
1290
+ function updateTask(event, task, runner) {
1291
+ eventsPacks.push([task.id, event]);
1292
+ packs.set(task.id, [task.result, task.meta]);
1293
+ sendTasksUpdateThrottled(runner);
1294
+ }
1278
1295
  async function callCleanupHooks(cleanups) {
1279
1296
  await Promise.all(cleanups.map(async (fn) => {
1280
1297
  if (typeof fn !== "function") {
@@ -1287,6 +1304,8 @@ async function runTest(test, runner) {
1287
1304
  var _runner$onBeforeRunTa, _test$result, _runner$onAfterRunTas;
1288
1305
  await ((_runner$onBeforeRunTa = runner.onBeforeRunTask) === null || _runner$onBeforeRunTa === void 0 ? void 0 : _runner$onBeforeRunTa.call(runner, test));
1289
1306
  if (test.mode !== "run" && test.mode !== "queued") {
1307
+ updateTask("test-prepare", test, runner);
1308
+ updateTask("test-finished", test, runner);
1290
1309
  return;
1291
1310
  }
1292
1311
  if (((_test$result = test.result) === null || _test$result === void 0 ? void 0 : _test$result.state) === "fail") {
@@ -1535,7 +1554,7 @@ async function startTests(specs, runner) {
1535
1554
  await ((_runner$onBeforeRunFi = runner.onBeforeRunFiles) === null || _runner$onBeforeRunFi === void 0 ? void 0 : _runner$onBeforeRunFi.call(runner, files));
1536
1555
  await runFiles(files, runner);
1537
1556
  await ((_runner$onAfterRunFil = runner.onAfterRunFiles) === null || _runner$onAfterRunFil === void 0 ? void 0 : _runner$onAfterRunFil.call(runner, files));
1538
- await sendTasksUpdate(runner);
1557
+ await finishSendTasksUpdate(runner);
1539
1558
  return files;
1540
1559
  }
1541
1560
  async function publicCollect(specs, runner) {
@@ -454,7 +454,7 @@ interface TestContext {
454
454
  /**
455
455
  * Metadata of the current test
456
456
  */
457
- task: Readonly<Task>;
457
+ task: Readonly<Test<TestContext>>;
458
458
  /**
459
459
  * Extract hooks on test failed
460
460
  */
@@ -487,4 +487,5 @@ interface TaskHook<HookListener> {
487
487
  type SequenceHooks = "stack" | "list" | "parallel";
488
488
  type SequenceSetupFiles = "list" | "parallel";
489
489
 
490
- export { type AfterAllListener as A, type BeforeAllListener as B, type ChainableFunction as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type TaskPopulated as G, type HookCleanupCallback as H, type InferFixturesTypes as I, type TaskResult as J, type TaskResultPack as K, type TaskState as L, type TestContext as M, type TestFunction as N, type OnTestFailedHandler as O, type TestOptions as P, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type AfterEachListener as b, createChainable as c, type BeforeEachListener as d, type TaskHook as e, type OnTestFinishedHandler as f, type Custom as g, type SuiteHooks as h, type TaskUpdateEvent as i, type TestAPI as j, type SuiteAPI as k, type SuiteCollector as l, type Fixture as m, type FixtureFn as n, type FixtureOptions as o, type Fixtures as p, type HookListener as q, type RuntimeContext as r, type SequenceHooks as s, type SequenceSetupFiles as t, type SuiteFactory as u, type TaskBase as v, type TaskContext as w, type TaskCustomOptions as x, type TaskEventPack as y, type TaskMeta as z };
490
+ export { createChainable as c };
491
+ export type { AfterAllListener as A, BeforeAllListener as B, ChainableFunction as C, DoneCallback as D, ExtendedContext as E, File as F, TaskPopulated as G, HookCleanupCallback as H, InferFixturesTypes as I, TaskResult as J, TaskResultPack as K, TaskState as L, TestContext as M, TestFunction as N, OnTestFailedHandler as O, TestOptions as P, RunMode as R, Suite as S, Task as T, Use as U, Test as a, AfterEachListener as b, BeforeEachListener as d, TaskHook as e, OnTestFinishedHandler as f, Custom as g, SuiteHooks as h, TaskUpdateEvent as i, TestAPI as j, SuiteAPI as k, SuiteCollector as l, Fixture as m, FixtureFn as n, FixtureOptions as o, Fixtures as p, HookListener as q, RuntimeContext as r, SequenceHooks as s, SequenceSetupFiles as t, SuiteFactory as u, TaskBase as v, TaskContext as w, TaskCustomOptions as x, TaskEventPack as y, TaskMeta as z };
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DiffOptions } from '@vitest/utils/diff';
2
- import { F as File, T as Task, a as Test, S as Suite, K as TaskResultPack, y as TaskEventPack, M as TestContext, s as SequenceHooks, t as SequenceSetupFiles } from './tasks.d-CnuPOyeL.js';
3
- export { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, g as Custom, j as CustomAPI, D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, f as OnTestFinishedHandler, R as RunMode, r as RuntimeContext, k as SuiteAPI, l as SuiteCollector, u as SuiteFactory, h as SuiteHooks, v as TaskBase, w as TaskContext, x as TaskCustomOptions, e as TaskHook, z as TaskMeta, G as TaskPopulated, J as TaskResult, L as TaskState, i as TaskUpdateEvent, j as TestAPI, N as TestFunction, P as TestOptions, U as Use } from './tasks.d-CnuPOyeL.js';
2
+ import { F as File, T as Task, a as Test, S as Suite, K as TaskResultPack, y as TaskEventPack, M as TestContext, s as SequenceHooks, t as SequenceSetupFiles } from './tasks.d-hsdzc98-.js';
3
+ export { A as AfterAllListener, b as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, g as Custom, j as CustomAPI, D as DoneCallback, E as ExtendedContext, m as Fixture, n as FixtureFn, o as FixtureOptions, p as Fixtures, H as HookCleanupCallback, q as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, f as OnTestFinishedHandler, R as RunMode, r as RuntimeContext, k as SuiteAPI, l as SuiteCollector, u as SuiteFactory, h as SuiteHooks, v as TaskBase, w as TaskContext, x as TaskCustomOptions, e as TaskHook, z as TaskMeta, G as TaskPopulated, J as TaskResult, L as TaskState, i as TaskUpdateEvent, j as TestAPI, N as TestFunction, P as TestOptions, U as Use } from './tasks.d-hsdzc98-.js';
4
4
  import '@vitest/utils';
5
5
 
6
6
  /**
@@ -140,6 +140,11 @@ interface VitestRunner {
140
140
  * The name of the current pool. Can affect how stack trace is inferred on the server side.
141
141
  */
142
142
  pool?: string;
143
+ /** @private */
144
+ _currentTaskStartTime?: number;
145
+ /** @private */
146
+ _currentTaskTimeout?: number;
143
147
  }
144
148
 
145
- export { type CancelReason, File, type FileSpecification, SequenceHooks, SequenceSetupFiles, Suite, Task, TaskEventPack, TaskResultPack, Test, TestContext, type VitestRunner, type VitestRunnerConfig, type VitestRunnerConstructor, type VitestRunnerImportSource };
149
+ export { File, SequenceHooks, SequenceSetupFiles, Suite, Task, TaskEventPack, TaskResultPack, Test, TestContext };
150
+ export type { CancelReason, FileSpecification, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, F as File, T as Task, a as Test } from './tasks.d-CnuPOyeL.js';
2
- export { C as ChainableFunction, c as createChainable } from './tasks.d-CnuPOyeL.js';
1
+ import { S as Suite, F as File, T as Task, a as Test } from './tasks.d-hsdzc98-.js';
2
+ export { C as ChainableFunction, c as createChainable } from './tasks.d-hsdzc98-.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "3.1.0-beta.2",
4
+ "version": "3.1.0",
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.3",
42
- "@vitest/utils": "3.1.0-beta.2"
42
+ "@vitest/utils": "3.1.0"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",