@vitest/runner 4.1.0-beta.5 → 4.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/README.md +4 -2
- package/dist/index.js +53 -20
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @vitest/runner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://npmx.dev/package/@vitest/runner)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Vitest mechanism to collect and run tests.
|
|
6
|
+
|
|
7
|
+
[GitHub](https://github.com/vitest-dev/vitest/tree/main/packages/runner) | [Documentation](https://vitest.dev/api/advanced/runner)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { processError } from '@vitest/utils/error';
|
|
2
|
-
import { isObject, filterOutComments, createDefer, assertTypes, toArray, isNegativeNaN, unique, objectAttr, shuffle } from '@vitest/utils/helpers';
|
|
2
|
+
import { isObject, filterOutComments, ordinal, createDefer, assertTypes, toArray, isNegativeNaN, unique, objectAttr, shuffle } from '@vitest/utils/helpers';
|
|
3
3
|
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
4
|
import { format, formatRegExp, objDisplay } from '@vitest/utils/display';
|
|
5
5
|
import { w as getChainableContext, a as createChainable, v as validateTags, e as createTaskName, x as createNoTagsError, f as findTestFileStackTrace, d as createTagsFilter, b as createFileTask, c as calculateSuiteHash, u as someTasksAreOnly, q as interpretTaskModes, s as limitConcurrency, t as partitionSuiteChildren, p as hasTests, o as hasFailed } from './chunk-tasks.js';
|
|
@@ -27,6 +27,12 @@ class TestRunAbortError extends Error {
|
|
|
27
27
|
class FixtureDependencyError extends Error {
|
|
28
28
|
name = "FixtureDependencyError";
|
|
29
29
|
}
|
|
30
|
+
class FixtureAccessError extends Error {
|
|
31
|
+
name = "FixtureAccessError";
|
|
32
|
+
}
|
|
33
|
+
class FixtureParseError extends Error {
|
|
34
|
+
name = "FixtureParseError";
|
|
35
|
+
}
|
|
30
36
|
class AroundHookSetupError extends Error {
|
|
31
37
|
name = "AroundHookSetupError";
|
|
32
38
|
}
|
|
@@ -272,7 +278,7 @@ async function callFixtureCleanupFrom(context, fromIndex) {
|
|
|
272
278
|
const contextHasFixturesCache = new WeakMap();
|
|
273
279
|
function withFixtures(fn, options) {
|
|
274
280
|
const collector = getCurrentSuite();
|
|
275
|
-
const suite = collector.suite || collector.file;
|
|
281
|
+
const suite = options?.suite || collector.suite || collector.file;
|
|
276
282
|
return async (hookContext) => {
|
|
277
283
|
const context = hookContext || options?.context;
|
|
278
284
|
if (!context) {
|
|
@@ -442,25 +448,35 @@ function resolveDeps(usedFixtures, registrations, depSet = new Set(), pendingFix
|
|
|
442
448
|
});
|
|
443
449
|
return pendingFixtures;
|
|
444
450
|
}
|
|
445
|
-
function validateSuiteHook(fn, hook,
|
|
446
|
-
const usedProps = getUsedProps(fn
|
|
451
|
+
function validateSuiteHook(fn, hook, suiteError) {
|
|
452
|
+
const usedProps = getUsedProps(fn, {
|
|
453
|
+
sourceError: suiteError,
|
|
454
|
+
suiteHook: hook
|
|
455
|
+
});
|
|
447
456
|
if (usedProps.size) {
|
|
448
|
-
|
|
449
|
-
if (
|
|
450
|
-
|
|
451
|
-
const stack = processor(error.stack || "");
|
|
452
|
-
console.warn(stack);
|
|
457
|
+
const error = new FixtureAccessError(`The ${hook} hook uses fixtures "${[...usedProps].join("\", \"")}", but has no access to context. ` + `Did you forget to call it as "test.${hook}()" instead of "${hook}()"?\n` + `If you used internal "suite" task as the first argument previously, access it in the second argument instead. ` + `See https://vitest.dev/guide/test-context#suite-level-hooks`);
|
|
458
|
+
if (suiteError) {
|
|
459
|
+
error.stack = suiteError.stack?.replace(suiteError.message, error.message);
|
|
453
460
|
}
|
|
461
|
+
throw error;
|
|
454
462
|
}
|
|
455
463
|
}
|
|
456
464
|
const kPropsSymbol = Symbol("$vitest:fixture-props");
|
|
465
|
+
const kPropNamesSymbol = Symbol("$vitest:fixture-prop-names");
|
|
457
466
|
function configureProps(fn, options) {
|
|
458
467
|
Object.defineProperty(fn, kPropsSymbol, {
|
|
459
468
|
value: options,
|
|
460
469
|
enumerable: false
|
|
461
470
|
});
|
|
462
471
|
}
|
|
463
|
-
function
|
|
472
|
+
function memoProps(fn, props) {
|
|
473
|
+
fn[kPropNamesSymbol] = props;
|
|
474
|
+
return props;
|
|
475
|
+
}
|
|
476
|
+
function getUsedProps(fn, { sourceError, suiteHook } = {}) {
|
|
477
|
+
if (kPropNamesSymbol in fn) {
|
|
478
|
+
return fn[kPropNamesSymbol];
|
|
479
|
+
}
|
|
464
480
|
const { index: fixturesIndex = 0, original: implementation = fn } = kPropsSymbol in fn ? fn[kPropsSymbol] : {};
|
|
465
481
|
let fnString = filterOutComments(implementation.toString());
|
|
466
482
|
// match lowered async function and strip it off
|
|
@@ -473,18 +489,23 @@ function getUsedProps(fn) {
|
|
|
473
489
|
}
|
|
474
490
|
const match = fnString.match(/[^(]*\(([^)]*)/);
|
|
475
491
|
if (!match) {
|
|
476
|
-
return new Set();
|
|
492
|
+
return memoProps(fn, new Set());
|
|
477
493
|
}
|
|
478
494
|
const args = splitByComma(match[1]);
|
|
479
495
|
if (!args.length) {
|
|
480
|
-
return new Set();
|
|
496
|
+
return memoProps(fn, new Set());
|
|
481
497
|
}
|
|
482
498
|
const fixturesArgument = args[fixturesIndex];
|
|
483
499
|
if (!fixturesArgument) {
|
|
484
|
-
return new Set();
|
|
500
|
+
return memoProps(fn, new Set());
|
|
485
501
|
}
|
|
486
502
|
if (!(fixturesArgument[0] === "{" && fixturesArgument.endsWith("}"))) {
|
|
487
|
-
|
|
503
|
+
const ordinalArgument = ordinal(fixturesIndex + 1);
|
|
504
|
+
const error = new FixtureParseError(`The ${ordinalArgument} argument inside a fixture must use object destructuring pattern, e.g. ({ task } => {}). ` + `Instead, received "${fixturesArgument}".` + `${suiteHook ? ` If you used internal "suite" task as the ${ordinalArgument} argument previously, access it in the ${ordinal(fixturesIndex + 2)} argument instead.` : ""}`);
|
|
505
|
+
if (sourceError) {
|
|
506
|
+
error.stack = sourceError.stack?.replace(sourceError.message, error.message);
|
|
507
|
+
}
|
|
508
|
+
throw error;
|
|
488
509
|
}
|
|
489
510
|
const _first = fixturesArgument.slice(1, -1).replace(/\s/g, "");
|
|
490
511
|
const props = splitByComma(_first).map((prop) => {
|
|
@@ -492,9 +513,13 @@ function getUsedProps(fn) {
|
|
|
492
513
|
});
|
|
493
514
|
const last = props.at(-1);
|
|
494
515
|
if (last && last.startsWith("...")) {
|
|
495
|
-
|
|
516
|
+
const error = new FixtureParseError(`Rest parameters are not supported in fixtures, received "${last}".`);
|
|
517
|
+
if (sourceError) {
|
|
518
|
+
error.stack = sourceError.stack?.replace(sourceError.message, error.message);
|
|
519
|
+
}
|
|
520
|
+
throw error;
|
|
496
521
|
}
|
|
497
|
-
return new Set(props);
|
|
522
|
+
return memoProps(fn, new Set(props));
|
|
498
523
|
}
|
|
499
524
|
function splitByComma(s) {
|
|
500
525
|
const result = [];
|
|
@@ -625,7 +650,11 @@ function afterAll(fn, timeout) {
|
|
|
625
650
|
function beforeEach(fn, timeout = getDefaultHookTimeout()) {
|
|
626
651
|
assertTypes(fn, "\"beforeEach\" callback", ["function"]);
|
|
627
652
|
const stackTraceError = new Error("STACK_TRACE_ERROR");
|
|
628
|
-
|
|
653
|
+
const wrapper = (context, suite) => {
|
|
654
|
+
const fixtureResolver = withFixtures(fn, { suite });
|
|
655
|
+
return fixtureResolver(context);
|
|
656
|
+
};
|
|
657
|
+
return getCurrentSuite().on("beforeEach", Object.assign(withTimeout(wrapper, timeout ?? getDefaultHookTimeout(), true, stackTraceError, abortIfTimeout), {
|
|
629
658
|
[CLEANUP_TIMEOUT_KEY]: timeout,
|
|
630
659
|
[CLEANUP_STACK_TRACE_KEY]: stackTraceError
|
|
631
660
|
}));
|
|
@@ -649,7 +678,11 @@ function beforeEach(fn, timeout = getDefaultHookTimeout()) {
|
|
|
649
678
|
*/
|
|
650
679
|
function afterEach(fn, timeout) {
|
|
651
680
|
assertTypes(fn, "\"afterEach\" callback", ["function"]);
|
|
652
|
-
|
|
681
|
+
const wrapper = (context, suite) => {
|
|
682
|
+
const fixtureResolver = withFixtures(fn, { suite });
|
|
683
|
+
return fixtureResolver(context);
|
|
684
|
+
};
|
|
685
|
+
return getCurrentSuite().on("afterEach", withTimeout(wrapper, timeout ?? getDefaultHookTimeout(), true, new Error("STACK_TRACE_ERROR"), abortIfTimeout));
|
|
653
686
|
}
|
|
654
687
|
/**
|
|
655
688
|
* Registers a callback function to be executed when a test fails within the current suite.
|
|
@@ -773,7 +806,7 @@ function aroundEach(fn, timeout) {
|
|
|
773
806
|
index: 1,
|
|
774
807
|
original: fn
|
|
775
808
|
});
|
|
776
|
-
const fixtureResolver = withFixtures(innerFn);
|
|
809
|
+
const fixtureResolver = withFixtures(innerFn, { suite });
|
|
777
810
|
return fixtureResolver(context);
|
|
778
811
|
};
|
|
779
812
|
return getCurrentSuite().on("aroundEach", Object.assign(wrapper, {
|
|
@@ -1566,7 +1599,7 @@ function formatTemplateString(cases, args) {
|
|
|
1566
1599
|
return res;
|
|
1567
1600
|
}
|
|
1568
1601
|
|
|
1569
|
-
const now$2 = Date.now;
|
|
1602
|
+
const now$2 = globalThis.performance ? globalThis.performance.now.bind(globalThis.performance) : Date.now;
|
|
1570
1603
|
const collectorContext = {
|
|
1571
1604
|
tasks: [],
|
|
1572
1605
|
currentSuite: null
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/runner",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.0
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"description": "Vitest test runner",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://vitest.dev/api/advanced/runner",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/vitest-dev/vitest.git",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/vitest-dev/vitest/issues"
|
|
16
16
|
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"vitest",
|
|
19
|
+
"test",
|
|
20
|
+
"test-runner"
|
|
21
|
+
],
|
|
17
22
|
"sideEffects": true,
|
|
18
23
|
"exports": {
|
|
19
24
|
".": {
|
|
@@ -39,7 +44,7 @@
|
|
|
39
44
|
],
|
|
40
45
|
"dependencies": {
|
|
41
46
|
"pathe": "^2.0.3",
|
|
42
|
-
"@vitest/utils": "4.1.0
|
|
47
|
+
"@vitest/utils": "4.1.0"
|
|
43
48
|
},
|
|
44
49
|
"scripts": {
|
|
45
50
|
"build": "premove dist && rollup -c",
|