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 · Guide · all subjects

pool/custom

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

Custom pool runner function signature

A custom pool runner is provided as a function that returns a PoolRunnerInitializer object with two properties: name (string indicating the custom pool runner name, must match the worker's name property) and createPoolWorker (function that takes options parameter and returns a CustomPoolWorker instance).

PoolWorker interface required methods

A CustomPoolWorker class must implement the PoolWorker interface with these required methods: name (property set to the pool name string), send(message: WorkerRequest) (sends a message to the worker), on(event: string, callback: (arg: any) => void) (listens to worker events like message, error, exit), off(event: string, callback: (arg: any) => void) (unsubscribes from on listeners), async start() (called when worker starts), async stop() (cleanup state), and deserialize(data) (deserializes data from worker).

Custom pool configuration in vitest.config.ts

To use a custom pool runner, provide it to the pool option in the test configuration: test: { pool: customPool({ customProperty: true }) }. This runs every test file with the custom pool by default.

Using multiple pools with projects

To run tests in different pools, use the projects feature in vitest.config.ts. Each project can specify its own pool option, allowing some tests to run with threads pool and others with a custom pool.

Worker initialization with vitest/worker utilities

In a worker file, import init, runBaseTests, and setupEnvironment from 'vitest/worker'. The init function accepts a configuration object with properties: post (sends message to CustomPoolRunner's onWorker message event), on (listens to CustomPoolRunner's postMessage calls), off (optional, removes on listeners), teardown (optional, teardowns worker and unsubscribes listeners), serialize (optional, custom serializer for post calls), deserialize (optional, custom deserializer for on callbacks), runTests (calls runBaseTests('run', state, traces)), collectTests (calls runBaseTests('collect', state, traces)), and setup (calls setupEnvironment).

Custom pool runner example structure

A custom pool implementation consists of two main parts: a PoolRunnerInitializer that creates CustomPoolWorker instances, and a worker file that uses init from vitest/worker. The CustomPoolRunner controls worker lifecycle and communication channels, such as using node:worker_threads Worker with postMessage and parentPort for communication.

Custom pool is advanced low-level API

Custom pool is an advanced, experimental, and very low-level API primarily used by library authors. Regular test users who just want to run tests do not need this feature.

Give your agent this brain