Skip to content

feat(cli): support --related in vitest list - #11015

Open
joaovitoras wants to merge 3 commits into
vitest-dev:mainfrom
joaovitoras:joaovitoras-list-related-tests
Open

feat(cli): support --related in vitest list#11015
joaovitoras wants to merge 3 commits into
vitest-dev:mainfrom
joaovitoras:joaovitoras-list-related-tests

Conversation

@joaovitoras

@joaovitoras joaovitoras commented Aug 19, 2026

Copy link
Copy Markdown

Description

vitest related runs tests affected by source files, but tooling that only needs to inspect the affected test set had no equivalent list workflow.

This is useful for CI orchestration that needs to determine the affected test files without executing the tests. Coverage includes direct and transitive dependencies, multiple related source files, file-only output, JSON output, and CLI parsing.

Use case - Sharding related tests

In CI, a pipeline can identify the test files affected by a change and distribute only those files across available workers. For example, vitest list --related --filesOnly <changed-files> produces the related test-file list. The pipeline can split it into balanced groups and run each group in a separate shard.

Usage

# List affected test cases
vitest list --related src/index.ts src/utils.ts

# List only affected test files
vitest list --related --filesOnly src/index.ts src/utils.ts

# Produce json output
vitest list --related --json src/index.ts src/utils.ts

Resolves #11016

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@github-actions github-actions Bot added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 19, 2026
@joaovitoras
joaovitoras force-pushed the joaovitoras-list-related-tests branch from c17c296 to 75459d9 Compare August 19, 2026 17:21
@github-actions

Copy link
Copy Markdown

Hello @joaovitoras. Your PR has been labeled maybe automated because it appears to have been fully generated by AI with no human involvement.

To keep your PR open, please follow these steps:

  • Confirm that you are a real human. If you are an automated agent, disclose that
  • Make sure you've read, reviewed and stand behind its content
  • Make sure you've read the full issue along with all of its comments, as well as any linked issues and their comments
  • Make sure it follows our contribution guidelines and uses the correct GitHub template
  • Disclose any AI tools you used (e.g. Claude, Copilot, Codex)

Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically.

These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context.

@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c17c296
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a85e609c003c20009fa8411
😎 Deploy Preview https://deploy-preview-11015--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@joaovitoras
joaovitoras marked this pull request as draft August 19, 2026 17:22
@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 13a352f
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a870e2d2e242200087631bd
😎 Deploy Preview https://deploy-preview-11015--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@joaovitoras joaovitoras changed the title feat(cli): support --related in vitest list feat(cli): support --findRelatedTests in vitest list Aug 19, 2026
@joaovitoras
joaovitoras force-pushed the joaovitoras-list-related-tests branch from 7053f9c to b8b4d7c Compare August 19, 2026 18:07
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@joaovitoras
joaovitoras marked this pull request as ready for review August 19, 2026 18:48
@joaovitoras joaovitoras reopened this Aug 19, 2026
@joaovitoras

Copy link
Copy Markdown
Author

This PR was authored and reviewed by me. Copilot was used only as an assistant, not as an autonomous agent. The change was manually designed and tested by me

Comment thread packages/vitest/src/node/cli/cac.ts Outdated
options.passWithNoTests ??= true
args = []
}
if (arrayArgs[2] === 'list' && options.findRelatedTests) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half the changes in this PR would be removed if you just named it related. Why do we need to follow jest naming?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to go this way, it was just a strong inspiration
Working on it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right. Renaming it to related removed the separate Jest-inspired option and its API/config plumbing. The remaining handling is needed because, for list, --related is a boolean flag while its positional arguments must be converted into the existing related: string[] runtime option, rather than treated as test filters

What do you think about this? Do you recommend I follow a different approach?

@sheremet-va sheremet-va removed the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Aug 20, 2026
@joaovitoras joaovitoras changed the title feat(cli): support --findRelatedTests in vitest list feat(cli): support --related in vitest list Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support listing tests related to source files

2 participants