@vitest/runner 4.1.0-beta.5 → 4.1.0-beta.6
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 +40 -15
- 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
|
}
|
|
@@ -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 = [];
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/runner",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.0-beta.
|
|
4
|
+
"version": "4.1.0-beta.6",
|
|
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-beta.
|
|
47
|
+
"@vitest/utils": "4.1.0-beta.6"
|
|
43
48
|
},
|
|
44
49
|
"scripts": {
|
|
45
50
|
"build": "premove dist && rollup -c",
|