new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vitest · Config reference · all subjects

test options

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Scoped fixtures in test.extend with scope option

The test.extend fixtures can now specify a scope option with two possible values: 'file' or 'worker'. File scope is similar to using beforeAll and afterAll at the top level of the file but won't be called if the fixture is not used in any test. Worker scope means the fixture is initiated once per worker. By default Vitest creates one worker for every test, so isolation must be disabled to benefit from worker scope.

Explicit Resource Management in vi.spyOn and vi.fn

In environments supporting Explicit Resource Management, you can use the using keyword instead of const with vi.spyOn and vi.fn to automatically call mockRestore on mocked functions when the containing block is exited. This is especially useful for spied methods.

Test signal API with AbortSignal

Vitest provides an AbortSignal object to the test body via a signal parameter. The signal is aborted when the test times out, another test fails with --bail flag set to non-zero, or the user presses Ctrl+C in the terminal. This can be used to stop resources that support the AbortSignal Web API, such as fetch requests.

tags configuration in test section

The tags configuration option allows defining test tags in the test section of vitest.config. Each tag requires a name property and can optionally include test options like timeout and retry that apply to every test marked with that tag. Tags are defined as an array of objects where each object has at least a name property.

test.extend supports type inference with builder pattern

Vitest 4.1 introduces a new test.extend pattern that supports type inference. You can return a value from the factory instead of calling the use function, and TypeScript infers the type from the return value. Function fixtures receive an onCleanup callback to register teardown logic.

aroundEach and aroundAll hooks for test context wrapping

The aroundEach hook registers a callback that wraps around each test within a suite. The aroundAll hook works similarly but is called for every suite. Both hooks receive a runTest function that must be called to execute the test. These are useful for wrapping tests in contexts like AsyncLocalStorage, tracing spans, or database transactions.

Tags filter command-line syntax with logical operators

Vitest supports a custom syntax for filtering tags via --tags-filter with logical operators: 'and' or '&&' to include both expressions, 'or' or '||' to include at least one expression, 'not' or '!' to exclude the expression, '*' wildcard to match any number of characters, and '()' to group expressions and override precedence.

Test context passed to beforeAll, afterAll, and aroundAll hooks

Vitest 4.1 passes down file and worker contexts to beforeAll, afterAll, and aroundAll hooks. These hooks can now access fixtures defined with file or worker scope, allowing setup and teardown operations that use those fixtures.

Type-aware hooks with test.extend

Vitest 4 allows type-aware lifecycle hooks when using test.extend. Hooks like beforeEach and afterEach can now be referenced directly on the returned test object and are aware of the extended context.

Give your agent this brain