This part is the user's entry point. It reads the command typed in the terminal, interprets the options, and starts the main test controller.
Columns are parts of the code, grouped by process. Read top to bottom. Solid arrow: hands work over. Dashed: the reply. Purple: crosses between processes. Hook: work inside one part. Dashed boxes repeat. Hover a column name or a step for its full text.
packages/vitest/src/nodepackages/vitest/src/node/cli/cac.tspackages/vitest/src/node/cli/cli-config.tspackages/vitest/src/node/cli/cli-api.tspackages/vitest/src/node/cli/filter.tsThe command line entry point creates the interface for the test tool and immediately parses the arguments provided by the user. This happens once when the module loads, capturing everything typed after the command name. The parsed arguments are passed along for further processing.
<module> packages/vitest/src/node/cli.ts — Creates the Vitest CLI and immediately parses the process arguments.createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.The command definitions set up the available commands like run, watch, and bench, along with all their configurable options. It configures help text, version information, and how options appear to the user. The system prepares to register each enabled option.
createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.addCliOptions packages/vitest/src/node/cli/cac.ts — Registers enabled CLI options.addCommand packages/vitest/src/node/cli/cac.ts — Registers a CLI option and its nested options.addCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe option configuration processes a nested boolean value, converting it to the correct format for internal use. This handles options that have child settings or depend on other flags. The transformed value returns to continue registration.
transformNestedBoolean packages/vitest/src/node/cli/cli-config.ts — transformNestedBooleanThe option configuration transforms another option value, applying normalization rules to ensure consistency. This step handles format conversion and validation of the raw input. The processed value is handed back.
cliOptionsConfig.silent.transform packages/vitest/src/node/cli/cli-config.ts — transformaddCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe option configuration continues transforming option values, applying the same normalization rules. Each option goes through this transformation to ensure proper formatting. The result returns to the caller.
cliOptionsConfig.browser.transform packages/vitest/src/node/cli/cli-config.ts — transformaddCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe option configuration processes yet another option value through its transformation pipeline. This ensures all raw string inputs become proper configuration values. The transformed result passes back.
cliOptionsConfig.cache.transform packages/vitest/src/node/cli/cli-config.ts — transformaddCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe option configuration handles the final standard option transformation. This completes the bulk of option processing before special handling occurs. The value returns for registration.
cliOptionsConfig.mergeReports.transform packages/vitest/src/node/cli/cli-config.ts — transformaddCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe option configuration applies a special watermark transformation to handle specific marking or identification needs. This transformation ensures certain options are properly tagged or identified. The result goes back to the definitions.
watermarkTransform packages/vitest/src/node/cli/cli-config.ts — watermarkTransformaddCommand>transform packages/vitest/src/node/cli/cac.ts — transformThe command definitions resolve whether to run tests once or watch for changes, based on the provided options. It determines the mode and prepares the filters and options for the test runner. Everything needed to start testing is gathered.
run packages/vitest/src/node/cli/cac.ts — Starts test mode with run/watch behavior resolved.start packages/vitest/src/node/cli/cac.ts — Starts Vitest from CLI options and handles fatal startup errors.startVitest packages/vitest/src/node/cli/cli-api.ts — Prepares and starts Vitest, returning its context.normalizeCliOptions packages/vitest/src/node/cli/cac.ts — Normalizes CLI exclusions, location filters and typecheck settings.The API starter creates the main test context and ensures the required environment packages are available. It sets environment variables for test mode and resolves the root directory from options or the current working directory. The context is now ready for the server.
startVitest packages/vitest/src/node/cli/cli-api.ts — Prepares and starts Vitest, returning its context.prepareVitest packages/vitest/src/node/cli/cli-api.ts — Creates a Vitest context and ensures its environment package exists.The command line entry reinitializes the test tool around a development server, clearing any previous state and preparing for a fresh run. It resolves the configuration, creates the state tracking, and initializes reporters for output. The server setup completes with callbacks registered.
Vitest._setServer packages/vitest/src/node/core.ts — Reinitializes Vitest around a Vite development server.createCLI packages/vitest/src/node/cli/cac.ts — Returns a CAC CLI configured with Vitest commands, options, version, and filtered help.startVitest>ctx.onAfterSetServer[0] packages/vitest/src/node/cli/cli-api.ts — startVitest>ctx.onAfterSetServer[0]The API starter executes the callbacks that were registered after the server was set up, running in parallel with other initialization. This handles any additional setup needed now that the server is ready. The callbacks complete their work.
startVitest>ctx.onAfterSetServer[0] packages/vitest/src/node/cli/cli-api.ts — startVitest>ctx.onAfterSetServer[0]The command line entry discovers test specifications across all projects, searching for test files and validating any location filters provided. It prepares to parse filename filters that may include specific line numbers. Each filter needs individual parsing.
getEnvPackageName packages/vitest/src/node/cli/cli-api.ts — Maps an environment name to its installable package.VitestSpecifications.globTestSpecifications packages/vitest/src/node/specifications.ts — Discovers specifications across projects and validates location filters.parseFilter packages/vitest/src/node/cli/filter.ts — Parses a filename filter with an optional trailing numeric line location, rejecting numeric ranges.The filter parsing groups all parsed filters by their filename and collects any defined line numbers for each file. It keeps duplicates and maintains the order from the input, with file-only filters yielding empty line arrays. The grouped filters are ready for test execution.
parseFilter packages/vitest/src/node/cli/filter.ts — Parses a filename filter with an optional trailing numeric line location, rejecting numeric ranges.start packages/vitest/src/node/cli/cac.ts — Starts Vitest from CLI options and handles fatal startup errors.VitestSpecifications.globTestSpecifications packages/vitest/src/node/specifications.ts — Discovers specifications across projects and validates location filters.groupFilters packages/vitest/src/node/cli/filter.ts — Groups parsed filters by filename and collects their defined line numbers.