@vitest/runner 3.1.1 → 3.1.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 +46 -30
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -443,7 +443,7 @@ function parseArguments(optionsOrFn, optionsOrTest) {
443
443
  handler: fn
444
444
  };
445
445
  }
446
- function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions) {
446
+ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions, parentCollectorFixtures) {
447
447
  const tasks = [];
448
448
  let suite;
449
449
  initSuite(true);
@@ -476,14 +476,15 @@ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions
476
476
  enumerable: false
477
477
  });
478
478
  setTestFixture(context, options.fixtures);
479
+ const limit = Error.stackTraceLimit;
480
+ Error.stackTraceLimit = 15;
481
+ const stackTraceError = new Error("STACK_TRACE_ERROR");
482
+ Error.stackTraceLimit = limit;
479
483
  if (handler) {
480
- setFn(task, withTimeout(withAwaitAsyncAssertions(withFixtures(handler, context), task), timeout));
484
+ setFn(task, withTimeout(withAwaitAsyncAssertions(withFixtures(handler, context), task), timeout, false, stackTraceError));
481
485
  }
482
486
  if (runner.config.includeTaskLocation) {
483
- const limit = Error.stackTraceLimit;
484
- Error.stackTraceLimit = 15;
485
- const error = new Error("stacktrace").stack;
486
- Error.stackTraceLimit = limit;
487
+ const error = stackTraceError.stack;
487
488
  const stack = findTestFileStackTrace(error, task.each ?? false);
488
489
  if (stack) {
489
490
  task.location = stack;
@@ -506,7 +507,7 @@ function createSuiteCollector(name, factory = () => {}, mode, each, suiteOptions
506
507
  });
507
508
  test.type = "test";
508
509
  });
509
- let collectorFixtures;
510
+ let collectorFixtures = parentCollectorFixtures;
510
511
  const collector = {
511
512
  type: "collector",
512
513
  name,
@@ -620,7 +621,7 @@ function createSuite() {
620
621
  const isSequential = isSequentialSpecified || options.sequential && !isConcurrentSpecified;
621
622
  options.concurrent = isConcurrent && !isSequential;
622
623
  options.sequential = isSequential && !isConcurrent;
623
- return createSuiteCollector(formatName(name), factory, mode, this.each, options);
624
+ return createSuiteCollector(formatName(name), factory, mode, this.each, options, currentSuite === null || currentSuite === void 0 ? void 0 : currentSuite.fixtures());
624
625
  }
625
626
  suiteFn.each = function(cases, ...args) {
626
627
  const suite = this.withContext();
@@ -741,10 +742,11 @@ function createTaskCollector(fn, context) {
741
742
  return createTest(function fn(name, optionsOrFn, optionsOrTest) {
742
743
  const collector = getCurrentSuite();
743
744
  const scopedFixtures = collector.fixtures();
745
+ const context = { ...this };
744
746
  if (scopedFixtures) {
745
- this.fixtures = mergeScopedFixtures(this.fixtures || [], scopedFixtures);
747
+ context.fixtures = mergeScopedFixtures(context.fixtures || [], scopedFixtures);
746
748
  }
747
- collector.test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest);
749
+ collector.test.fn.call(context, formatName(name), optionsOrFn, optionsOrTest);
748
750
  }, _context);
749
751
  };
750
752
  const _test = createChainable([
@@ -1292,13 +1294,26 @@ function updateTask(event, task, runner) {
1292
1294
  packs.set(task.id, [task.result, task.meta]);
1293
1295
  sendTasksUpdateThrottled(runner);
1294
1296
  }
1295
- async function callCleanupHooks(cleanups) {
1296
- await Promise.all(cleanups.map(async (fn) => {
1297
- if (typeof fn !== "function") {
1298
- return;
1297
+ async function callCleanupHooks(runner, cleanups) {
1298
+ const sequence = runner.config.sequence.hooks;
1299
+ if (sequence === "stack") {
1300
+ cleanups = cleanups.slice().reverse();
1301
+ }
1302
+ if (sequence === "parallel") {
1303
+ await Promise.all(cleanups.map(async (fn) => {
1304
+ if (typeof fn !== "function") {
1305
+ return;
1306
+ }
1307
+ await fn();
1308
+ }));
1309
+ } else {
1310
+ for (const fn of cleanups) {
1311
+ if (typeof fn !== "function") {
1312
+ continue;
1313
+ }
1314
+ await fn();
1299
1315
  }
1300
- await fn();
1301
- }));
1316
+ }
1302
1317
  }
1303
1318
  async function runTest(test, runner) {
1304
1319
  var _runner$onBeforeRunTa, _test$result, _runner$onAfterRunTas;
@@ -1358,18 +1373,6 @@ async function runTest(test, runner) {
1358
1373
  } catch (e) {
1359
1374
  failTask(test.result, e, runner.config.diffOptions);
1360
1375
  }
1361
- if (((_test$result2 = test.result) === null || _test$result2 === void 0 ? void 0 : _test$result2.pending) || ((_test$result3 = test.result) === null || _test$result3 === void 0 ? void 0 : _test$result3.state) === "skip") {
1362
- var _test$result4;
1363
- test.mode = "skip";
1364
- test.result = {
1365
- state: "skip",
1366
- note: (_test$result4 = test.result) === null || _test$result4 === void 0 ? void 0 : _test$result4.note,
1367
- pending: true
1368
- };
1369
- updateTask("test-finished", test, runner);
1370
- setCurrentTest(undefined);
1371
- return;
1372
- }
1373
1376
  try {
1374
1377
  var _runner$onTaskFinishe;
1375
1378
  await ((_runner$onTaskFinishe = runner.onTaskFinished) === null || _runner$onTaskFinishe === void 0 ? void 0 : _runner$onTaskFinishe.call(runner, test));
@@ -1378,7 +1381,7 @@ async function runTest(test, runner) {
1378
1381
  }
1379
1382
  try {
1380
1383
  await callSuiteHook(suite, test, "afterEach", runner, [test.context, suite]);
1381
- await callCleanupHooks(beforeEachCleanups);
1384
+ await callCleanupHooks(runner, beforeEachCleanups);
1382
1385
  await callFixtureCleanup(test.context);
1383
1386
  } catch (e) {
1384
1387
  failTask(test.result, e, runner.config.diffOptions);
@@ -1389,6 +1392,19 @@ async function runTest(test, runner) {
1389
1392
  }
1390
1393
  test.onFailed = undefined;
1391
1394
  test.onFinished = undefined;
1395
+ if (((_test$result2 = test.result) === null || _test$result2 === void 0 ? void 0 : _test$result2.pending) || ((_test$result3 = test.result) === null || _test$result3 === void 0 ? void 0 : _test$result3.state) === "skip") {
1396
+ var _test$result4;
1397
+ test.mode = "skip";
1398
+ test.result = {
1399
+ state: "skip",
1400
+ note: (_test$result4 = test.result) === null || _test$result4 === void 0 ? void 0 : _test$result4.note,
1401
+ pending: true,
1402
+ duration: now() - start
1403
+ };
1404
+ updateTask("test-finished", test, runner);
1405
+ setCurrentTest(undefined);
1406
+ return;
1407
+ }
1392
1408
  if (test.result.state === "pass") {
1393
1409
  break;
1394
1410
  }
@@ -1498,7 +1514,7 @@ async function runSuite(suite, runner) {
1498
1514
  }
1499
1515
  try {
1500
1516
  await callSuiteHook(suite, suite, "afterAll", runner, [suite]);
1501
- await callCleanupHooks(beforeAllCleanups);
1517
+ await callCleanupHooks(runner, beforeAllCleanups);
1502
1518
  } catch (e) {
1503
1519
  failTask(suite.result, e, runner.config.diffOptions);
1504
1520
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "3.1.1",
4
+ "version": "3.1.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.3",
42
- "@vitest/utils": "3.1.1"
42
+ "@vitest/utils": "3.1.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",