-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(cli): support --related in vitest list #11015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joaovitoras
wants to merge
6
commits into
vitest-dev:main
Choose a base branch
from
joaovitoras:joaovitoras-list-related-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b8b4d7c
feat(cli): list related tests
joaovitoras 44abbcd
refactor(cli): reuse list option type
joaovitoras 13a352f
refactor(cli): rename --findRelatedTests to --related and update rela…
joaovitoras d420924
Merge branch 'main' into joaovitoras-list-related-tests
joaovitoras aa4d924
Merge branch 'main' into joaovitoras-list-related-tests
joaovitoras d64a8db
Merge branch 'main' into joaovitoras-list-related-tests
joaovitoras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { expect, test } from 'vitest' | ||
| import { replaceRoot, runInlineTests, runVitestCli } from '#test-utils' | ||
|
|
||
| const structure = { | ||
| 'src/shared.ts': 'export const shared = true', | ||
| 'src/intermediate.ts': ` | ||
| export { shared } from './shared' | ||
| `, | ||
| 'src/other.ts': 'export const other = true', | ||
| 'src/unrelated.ts': 'export const unrelated = true', | ||
| 'tests/direct.test.ts': ` | ||
| import { expect, test } from 'vitest' | ||
| import { shared } from '../src/shared' | ||
|
|
||
| test('direct dependency', () => { | ||
| expect(shared).toBe(true) | ||
| }) | ||
| `, | ||
| 'tests/transitive.test.ts': ` | ||
| import { expect, test } from 'vitest' | ||
| import { shared } from '../src/intermediate' | ||
|
|
||
| test('transitive dependency', () => { | ||
| expect(shared).toBe(true) | ||
| }) | ||
| `, | ||
| 'tests/other.test.ts': ` | ||
| import { expect, test } from 'vitest' | ||
| import { other } from '../src/other' | ||
|
|
||
| test('other dependency', () => { | ||
| expect(other).toBe(true) | ||
| }) | ||
| `, | ||
| 'tests/unrelated.test.ts': ` | ||
| import { expect, test } from 'vitest' | ||
| import { unrelated } from '../src/unrelated' | ||
|
|
||
| test('unrelated dependency', () => { | ||
| expect(unrelated).toBe(true) | ||
| }) | ||
| `, | ||
| } | ||
|
|
||
| async function setupRelatedTests() { | ||
| const result = await runInlineTests(structure) | ||
|
|
||
| expect(result.stderr).toBe('') | ||
| expect(result.testTree()).toMatchInlineSnapshot(` | ||
| { | ||
| "tests/direct.test.ts": { | ||
| "direct dependency": "passed", | ||
| }, | ||
| "tests/other.test.ts": { | ||
| "other dependency": "passed", | ||
| }, | ||
| "tests/transitive.test.ts": { | ||
| "transitive dependency": "passed", | ||
| }, | ||
| "tests/unrelated.test.ts": { | ||
| "unrelated dependency": "passed", | ||
| }, | ||
| } | ||
| `) | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| test('list --findRelatedTests includes direct and transitive dependents', async () => { | ||
| const { root } = await setupRelatedTests() | ||
| const { stdout, stderr, exitCode } = await runVitestCli( | ||
| 'list', | ||
| `--root=${root}`, | ||
| '--findRelatedTests', | ||
| 'src/shared.ts', | ||
| ) | ||
|
|
||
| expect(stderr).toBe('') | ||
| expect(stdout).toMatchInlineSnapshot(` | ||
| "tests/direct.test.ts > direct dependency | ||
| tests/transitive.test.ts > transitive dependency | ||
| " | ||
| `) | ||
| expect(exitCode).toBe(0) | ||
| }) | ||
|
|
||
| test('list --findRelatedTests combines multiple source files', async () => { | ||
| const { root } = await setupRelatedTests() | ||
| const { stdout, stderr, exitCode } = await runVitestCli( | ||
| 'list', | ||
| `--root=${root}`, | ||
| '--findRelatedTests', | ||
| 'src/shared.ts', | ||
| 'src/other.ts', | ||
| ) | ||
|
|
||
| expect(stderr).toBe('') | ||
| expect(stdout).toMatchInlineSnapshot(` | ||
| "tests/direct.test.ts > direct dependency | ||
| tests/other.test.ts > other dependency | ||
| tests/transitive.test.ts > transitive dependency | ||
| " | ||
| `) | ||
| expect(exitCode).toBe(0) | ||
| }) | ||
|
|
||
| test('list --findRelatedTests supports files-only and JSON output', async () => { | ||
| const { root } = await setupRelatedTests() | ||
| const filesResult = await runVitestCli( | ||
| 'list', | ||
| `--root=${root}`, | ||
| '--findRelatedTests', | ||
| '--filesOnly', | ||
| 'src/shared.ts', | ||
| ) | ||
| const jsonResult = await runVitestCli( | ||
| 'list', | ||
| `--root=${root}`, | ||
| '--findRelatedTests', | ||
| 'src/shared.ts', | ||
| '--json', | ||
| ) | ||
|
|
||
| expect(filesResult.stderr).toBe('') | ||
| expect(filesResult.stdout).toMatchInlineSnapshot(` | ||
| "tests/direct.test.ts | ||
| tests/transitive.test.ts | ||
| " | ||
| `) | ||
| expect(filesResult.exitCode).toBe(0) | ||
|
|
||
| expect(jsonResult.stderr).toBe('') | ||
| expect(replaceRoot(jsonResult.stdout, root)).toMatchInlineSnapshot(` | ||
| "[ | ||
| { | ||
| "name": "direct dependency", | ||
| "file": "<root>/tests/direct.test.ts" | ||
| }, | ||
| { | ||
| "name": "transitive dependency", | ||
| "file": "<root>/tests/transitive.test.ts" | ||
| } | ||
| ] | ||
| " | ||
| `) | ||
| expect(jsonResult.exitCode).toBe(0) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?