@vitest/runner 3.0.0 → 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.
@@ -49,8 +49,8 @@ function interpretTaskModes(file, namePattern, testLocations, onlyMode, parentIs
49
49
  }
50
50
  }
51
51
  let hasLocationMatch = parentMatchedWithLocation;
52
- if (testLocations !== void 0 && testLocations.length !== 0) {
53
- if (t.location && (testLocations == null ? void 0 : testLocations.includes(t.location.line))) {
52
+ if (testLocations !== undefined && testLocations.length !== 0) {
53
+ if (t.location && (testLocations == null ? undefined : testLocations.includes(t.location.line))) {
54
54
  t.mode = "run";
55
55
  matchedLocations.push(t.location.line);
56
56
  hasLocationMatch = true;
@@ -81,16 +81,16 @@ function interpretTaskModes(file, namePattern, testLocations, onlyMode, parentIs
81
81
  }
82
82
  };
83
83
  traverseSuite(file, parentIsOnly, false);
84
- const nonMatching = testLocations == null ? void 0 : testLocations.filter((loc) => !matchedLocations.includes(loc));
84
+ const nonMatching = testLocations == null ? undefined : testLocations.filter((loc) => !matchedLocations.includes(loc));
85
85
  if (nonMatching && nonMatching.length !== 0) {
86
86
  const message = nonMatching.length === 1 ? `line ${nonMatching[0]}` : `lines ${nonMatching.join(", ")}`;
87
- if (file.result === void 0) {
87
+ if (file.result === undefined) {
88
88
  file.result = {
89
89
  state: "fail",
90
90
  errors: []
91
91
  };
92
92
  }
93
- if (file.result.errors === void 0) {
93
+ if (file.result.errors === undefined) {
94
94
  file.result.errors = [];
95
95
  }
96
96
  file.result.errors.push(
@@ -171,7 +171,7 @@ function createFileTask(filepath, root, projectName, pool) {
171
171
  tasks: [],
172
172
  meta: /* @__PURE__ */ Object.create(null),
173
173
  projectName,
174
- file: void 0,
174
+ file: undefined,
175
175
  pool
176
176
  };
177
177
  file.file = file;
@@ -271,16 +271,16 @@ function hasFailed(suite) {
271
271
  return toArray(suite).some(
272
272
  (s) => {
273
273
  var _a;
274
- return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
274
+ return ((_a = s.result) == null ? undefined : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks);
275
275
  }
276
276
  );
277
277
  }
278
278
  function getNames(task) {
279
279
  const names = [task.name];
280
280
  let current = task;
281
- while (current == null ? void 0 : current.suite) {
281
+ while (current == null ? undefined : current.suite) {
282
282
  current = current.suite;
283
- if (current == null ? void 0 : current.name) {
283
+ if (current == null ? undefined : current.name) {
284
284
  names.unshift(current.name);
285
285
  }
286
286
  }
package/dist/index.js CHANGED
@@ -16,13 +16,14 @@ 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
22
23
  };
23
24
  function collectTask(task) {
24
25
  var _a;
25
- (_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
26
+ (_a = collectorContext.currentSuite) == null ? undefined : _a.tasks.push(task);
26
27
  }
27
28
  async function runWithSuite(suite, fn) {
28
29
  const prev = collectorContext.currentSuite;
@@ -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 ? void 0 : _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) {
@@ -74,7 +98,7 @@ function createTestContext(test, runner) {
74
98
  withTimeout(handler, timeout ?? runner.config.hookTimeout, true)
75
99
  );
76
100
  };
77
- return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
101
+ return ((_a = runner.extendTaskContext) == null ? undefined : _a.call(runner, context)) || context;
78
102
  }
79
103
  function makeTimeoutMsg(isHook, timeout) {
80
104
  return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
@@ -151,7 +175,7 @@ function withFixtures(fn, testContext) {
151
175
  return fn({});
152
176
  }
153
177
  const fixtures = getFixture(context);
154
- if (!(fixtures == null ? void 0 : fixtures.length)) {
178
+ if (!(fixtures == null ? undefined : fixtures.length)) {
155
179
  return fn(context);
156
180
  }
157
181
  const usedProps = getUsedProps(fn);
@@ -408,12 +432,12 @@ function createSuiteCollector(name, factory = () => {
408
432
  const task2 = {
409
433
  id: "",
410
434
  name: name2,
411
- suite: void 0,
435
+ suite: undefined,
412
436
  each: options.each,
413
437
  fails: options.fails,
414
- context: void 0,
438
+ context: undefined,
415
439
  type: "test",
416
- file: void 0,
440
+ file: undefined,
417
441
  retry: options.retry ?? runner.config.retry,
418
442
  repeats: options.repeats,
419
443
  mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
@@ -423,7 +447,7 @@ function createSuiteCollector(name, factory = () => {
423
447
  if (options.concurrent || !options.sequential && runner.config.sequence.concurrent) {
424
448
  task2.concurrent = true;
425
449
  }
426
- task2.shuffle = suiteOptions == null ? void 0 : suiteOptions.shuffle;
450
+ task2.shuffle = suiteOptions == null ? undefined : suiteOptions.shuffle;
427
451
  const context = createTestContext(task2, runner);
428
452
  Object.defineProperty(task2, "context", {
429
453
  value: context,
@@ -435,7 +459,7 @@ function createSuiteCollector(name, factory = () => {
435
459
  task2,
436
460
  withTimeout(
437
461
  withAwaitAsyncAssertions(withFixtures(handler, context), task2),
438
- (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
462
+ (options == null ? undefined : options.timeout) ?? runner.config.testTimeout
439
463
  )
440
464
  );
441
465
  }
@@ -457,8 +481,8 @@ function createSuiteCollector(name, factory = () => {
457
481
  if (typeof suiteOptions === "object") {
458
482
  options = Object.assign({}, suiteOptions, options);
459
483
  }
460
- options.concurrent = this.concurrent || !this.sequential && (options == null ? void 0 : options.concurrent);
461
- options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential);
484
+ options.concurrent = this.concurrent || !this.sequential && (options == null ? undefined : options.concurrent);
485
+ options.sequential = this.sequential || !this.concurrent && (options == null ? undefined : options.sequential);
462
486
  const test3 = task(formatName(name2), {
463
487
  ...this,
464
488
  ...options,
@@ -491,11 +515,11 @@ function createSuiteCollector(name, factory = () => {
491
515
  name,
492
516
  mode,
493
517
  each,
494
- file: void 0,
495
- shuffle: suiteOptions == null ? void 0 : suiteOptions.shuffle,
518
+ file: undefined,
519
+ shuffle: suiteOptions == null ? undefined : suiteOptions.shuffle,
496
520
  tasks: [],
497
521
  meta: /* @__PURE__ */ Object.create(null),
498
- concurrent: suiteOptions == null ? void 0 : suiteOptions.concurrent
522
+ concurrent: suiteOptions == null ? undefined : suiteOptions.concurrent
499
523
  };
500
524
  if (runner && includeLocation && runner.config.includeTaskLocation) {
501
525
  const limit = Error.stackTraceLimit;
@@ -542,7 +566,7 @@ function withAwaitAsyncAssertions(fn, task) {
542
566
  const fnResult = await fn(...args);
543
567
  if (task.promises) {
544
568
  const result = await Promise.allSettled(task.promises);
545
- const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
569
+ const errors = result.map((r) => r.status === "rejected" ? r.reason : undefined).filter(Boolean);
546
570
  if (errors.length) {
547
571
  throw errors;
548
572
  }
@@ -562,9 +586,9 @@ function createSuite() {
562
586
  const isConcurrentSpecified = options.concurrent || this.concurrent || options.sequential === false;
563
587
  const isSequentialSpecified = options.sequential || this.sequential || options.concurrent === false;
564
588
  options = {
565
- ...currentSuite == null ? void 0 : currentSuite.options,
589
+ ...currentSuite == null ? undefined : currentSuite.options,
566
590
  ...options,
567
- shuffle: this.shuffle ?? options.shuffle ?? ((_a = currentSuite == null ? void 0 : currentSuite.options) == null ? void 0 : _a.shuffle) ?? (runner == null ? void 0 : runner.config.sequence.shuffle)
591
+ shuffle: this.shuffle ?? options.shuffle ?? ((_a = currentSuite == null ? undefined : currentSuite.options) == null ? undefined : _a.shuffle) ?? (runner == null ? undefined : runner.config.sequence.shuffle)
568
592
  };
569
593
  const isConcurrent = isConcurrentSpecified || options.concurrent && !isSequentialSpecified;
570
594
  const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
@@ -609,7 +633,7 @@ function createSuite() {
609
633
  }
610
634
  }
611
635
  });
612
- this.setContext("each", void 0);
636
+ this.setContext("each", undefined);
613
637
  };
614
638
  };
615
639
  suiteFn.for = function(cases, ...args) {
@@ -664,7 +688,7 @@ function createTaskCollector(fn, context) {
664
688
  }
665
689
  }
666
690
  });
667
- this.setContext("each", void 0);
691
+ this.setContext("each", undefined);
668
692
  };
669
693
  };
670
694
  taskFn.for = function(cases, ...args) {
@@ -695,7 +719,7 @@ function createTaskCollector(fn, context) {
695
719
  context || {},
696
720
  (key) => {
697
721
  var _a, _b;
698
- return (_b = (_a = getRunner()).injectValue) == null ? void 0 : _b.call(_a, key);
722
+ return (_b = (_a = getRunner()).injectValue) == null ? undefined : _b.call(_a, key);
699
723
  }
700
724
  );
701
725
  return createTest(function fn2(name, optionsOrFn, optionsOrTest) {
@@ -747,7 +771,7 @@ function formatTitle(template, items, idx) {
747
771
  (_, key) => {
748
772
  var _a, _b;
749
773
  return objDisplay(objectAttr(items[0], key), {
750
- truncate: (_b = (_a = runner == null ? void 0 : runner.config) == null ? void 0 : _a.chaiConfig) == null ? void 0 : _b.truncateThreshold
774
+ truncate: (_b = (_a = runner == null ? undefined : runner.config) == null ? undefined : _a.chaiConfig) == null ? undefined : _b.truncateThreshold
751
775
  });
752
776
  }
753
777
  );
@@ -866,10 +890,10 @@ async function collectTests(specs, runner) {
866
890
  const config = runner.config;
867
891
  for (const spec of specs) {
868
892
  const filepath = typeof spec === "string" ? spec : spec.filepath;
869
- const testLocations = typeof spec === "string" ? void 0 : spec.testLocations;
893
+ const testLocations = typeof spec === "string" ? undefined : spec.testLocations;
870
894
  const file = createFileTask(filepath, config.root, config.name, runner.pool);
871
895
  file.shuffle = config.sequence.shuffle;
872
- (_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
896
+ (_a = runner.onCollectStart) == null ? undefined : _a.call(runner, file);
873
897
  clearCollectorContext(filepath, runner);
874
898
  try {
875
899
  const setupFiles = toArray(config.setupFiles);
@@ -911,7 +935,7 @@ async function collectTests(specs, runner) {
911
935
  calculateSuiteHash(file);
912
936
  file.tasks.forEach((task) => {
913
937
  var _a2;
914
- if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
938
+ if (((_a2 = task.suite) == null ? undefined : _a2.id) === "") {
915
939
  delete task.suite;
916
940
  }
917
941
  });
@@ -1056,7 +1080,7 @@ async function sendTasksUpdate(runner) {
1056
1080
  const taskPacks = Array.from(packs).map(([id, task]) => {
1057
1081
  return [id, task[0], task[1]];
1058
1082
  });
1059
- const p = (_a = runner.onTaskUpdate) == null ? void 0 : _a.call(runner, taskPacks, eventsPacks);
1083
+ const p = (_a = runner.onTaskUpdate) == null ? undefined : _a.call(runner, taskPacks, eventsPacks);
1060
1084
  eventsPacks.length = 0;
1061
1085
  packs.clear();
1062
1086
  return p;
@@ -1074,11 +1098,11 @@ async function callCleanupHooks(cleanups) {
1074
1098
  }
1075
1099
  async function runTest(test, runner) {
1076
1100
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1077
- await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
1101
+ await ((_a = runner.onBeforeRunTask) == null ? undefined : _a.call(runner, test));
1078
1102
  if (test.mode !== "run" && test.mode !== "queued") {
1079
1103
  return;
1080
1104
  }
1081
- if (((_b = test.result) == null ? void 0 : _b.state) === "fail") {
1105
+ if (((_b = test.result) == null ? undefined : _b.state) === "fail") {
1082
1106
  updateTask("test-failed-early", test, runner);
1083
1107
  return;
1084
1108
  }
@@ -1134,11 +1158,11 @@ async function runTest(test, runner) {
1134
1158
  } catch (e) {
1135
1159
  failTask(test.result, e, runner.config.diffOptions);
1136
1160
  }
1137
- if (((_e = test.result) == null ? void 0 : _e.pending) || ((_f = test.result) == null ? void 0 : _f.state) === "skip") {
1161
+ if (((_e = test.result) == null ? undefined : _e.pending) || ((_f = test.result) == null ? undefined : _f.state) === "skip") {
1138
1162
  test.mode = "skip";
1139
- test.result = { state: "skip", note: (_g = test.result) == null ? void 0 : _g.note, pending: true };
1163
+ test.result = { state: "skip", note: (_g = test.result) == null ? undefined : _g.note, pending: true };
1140
1164
  updateTask("test-finished", test, runner);
1141
- setCurrentTest(void 0);
1165
+ setCurrentTest(undefined);
1142
1166
  return;
1143
1167
  }
1144
1168
  try {
@@ -1165,8 +1189,8 @@ async function runTest(test, runner) {
1165
1189
  runner.config.sequence.hooks
1166
1190
  );
1167
1191
  }
1168
- test.onFailed = void 0;
1169
- test.onFinished = void 0;
1192
+ test.onFailed = undefined;
1193
+ test.onFinished = undefined;
1170
1194
  if (test.result.state === "pass") {
1171
1195
  break;
1172
1196
  }
@@ -1184,12 +1208,12 @@ async function runTest(test, runner) {
1184
1208
  test.result.errors = [error];
1185
1209
  } else {
1186
1210
  test.result.state = "pass";
1187
- test.result.errors = void 0;
1211
+ test.result.errors = undefined;
1188
1212
  }
1189
1213
  }
1190
- setCurrentTest(void 0);
1214
+ setCurrentTest(undefined);
1191
1215
  test.result.duration = now() - start;
1192
- await ((_i = runner.onAfterRunTask) == null ? void 0 : _i.call(runner, test));
1216
+ await ((_i = runner.onAfterRunTask) == null ? undefined : _i.call(runner, test));
1193
1217
  updateTask("test-finished", test, runner);
1194
1218
  }
1195
1219
  function failTask(result, err, diffOptions) {
@@ -1219,8 +1243,8 @@ function markTasksAsSkipped(suite, runner) {
1219
1243
  }
1220
1244
  async function runSuite(suite, runner) {
1221
1245
  var _a, _b, _c, _d;
1222
- await ((_a = runner.onBeforeRunSuite) == null ? void 0 : _a.call(runner, suite));
1223
- if (((_b = suite.result) == null ? void 0 : _b.state) === "fail") {
1246
+ await ((_a = runner.onBeforeRunSuite) == null ? undefined : _a.call(runner, suite));
1247
+ if (((_b = suite.result) == null ? undefined : _b.state) === "fail") {
1224
1248
  markTasksAsSkipped(suite, runner);
1225
1249
  updateTask("suite-failed-early", suite, runner);
1226
1250
  return;
@@ -1289,7 +1313,7 @@ async function runSuite(suite, runner) {
1289
1313
  if (suite.mode === "run" || suite.mode === "queued") {
1290
1314
  if (!runner.config.passWithNoTests && !hasTests(suite)) {
1291
1315
  suite.result.state = "fail";
1292
- if (!((_c = suite.result.errors) == null ? void 0 : _c.length)) {
1316
+ if (!((_c = suite.result.errors) == null ? undefined : _c.length)) {
1293
1317
  const error = processError(
1294
1318
  new Error(`No test found in suite ${suite.name}`)
1295
1319
  );
@@ -1303,7 +1327,7 @@ async function runSuite(suite, runner) {
1303
1327
  }
1304
1328
  suite.result.duration = now() - start;
1305
1329
  updateTask("suite-finished", suite, runner);
1306
- await ((_d = runner.onAfterRunSuite) == null ? void 0 : _d.call(runner, suite));
1330
+ await ((_d = runner.onAfterRunSuite) == null ? undefined : _d.call(runner, suite));
1307
1331
  }
1308
1332
  }
1309
1333
  let limitMaxConcurrency;
@@ -1319,7 +1343,7 @@ async function runFiles(files, runner) {
1319
1343
  limitMaxConcurrency ?? (limitMaxConcurrency = limitConcurrency(runner.config.maxConcurrency));
1320
1344
  for (const file of files) {
1321
1345
  if (!file.tasks.length && !runner.config.passWithNoTests) {
1322
- if (!((_b = (_a = file.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.length)) {
1346
+ if (!((_b = (_a = file.result) == null ? undefined : _a.errors) == null ? undefined : _b.length)) {
1323
1347
  const error = processError(
1324
1348
  new Error(`No test suite found in file ${file.filepath}`)
1325
1349
  );
@@ -1335,21 +1359,21 @@ async function runFiles(files, runner) {
1335
1359
  async function startTests(specs, runner) {
1336
1360
  var _a, _b, _c, _d;
1337
1361
  const paths = specs.map((f) => typeof f === "string" ? f : f.filepath);
1338
- await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
1362
+ await ((_a = runner.onBeforeCollect) == null ? undefined : _a.call(runner, paths));
1339
1363
  const files = await collectTests(specs, runner);
1340
- await ((_b = runner.onCollected) == null ? void 0 : _b.call(runner, files));
1341
- await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
1364
+ await ((_b = runner.onCollected) == null ? undefined : _b.call(runner, files));
1365
+ await ((_c = runner.onBeforeRunFiles) == null ? undefined : _c.call(runner, files));
1342
1366
  await runFiles(files, runner);
1343
- await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
1367
+ await ((_d = runner.onAfterRunFiles) == null ? undefined : _d.call(runner, files));
1344
1368
  await sendTasksUpdate(runner);
1345
1369
  return files;
1346
1370
  }
1347
1371
  async function publicCollect(specs, runner) {
1348
1372
  var _a, _b;
1349
1373
  const paths = specs.map((f) => typeof f === "string" ? f : f.filepath);
1350
- await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
1374
+ await ((_a = runner.onBeforeCollect) == null ? undefined : _a.call(runner, paths));
1351
1375
  const files = await collectTests(specs, runner);
1352
- await ((_b = runner.onCollected) == null ? void 0 : _b.call(runner, files));
1376
+ await ((_b = runner.onCollected) == null ? undefined : _b.call(runner, files));
1353
1377
  return files;
1354
1378
  }
1355
1379
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -38,8 +38,8 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "pathe": "^2.0.0",
42
- "@vitest/utils": "3.0.0"
41
+ "pathe": "^2.0.1",
42
+ "@vitest/utils": "3.0.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",