-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(experimental): introduce experimental.vcsProvider
#9928
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
Merged
sheremet-va
merged 12 commits into
vitest-dev:main
from
sheremet-va:feat/add-vcs-provider
Mar 23, 2026
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
77b2767
feat: introduce `experimental.vcsProvider`
sheremet-va b82b8d4
docs: cleanup
sheremet-va 077050a
docs: don't allow vcsProvider in CLI
sheremet-va fe928e7
feat: support a string
sheremet-va 2aa6e34
Merge branch 'main' of github.com:vitest-dev/vitest into feat/add-vcs…
sheremet-va db7b1eb
chore: fix test
sheremet-va 41cf2cf
chore: normalize files from `findChangedFiles`
sheremet-va a0d31e4
chore: test
sheremet-va a45b8a9
chore: cleanup
sheremet-va 72b27e7
fix: always normalize
sheremet-va e5cd3d1
chore: remove test
sheremet-va 05a8a78
chorer: keep it
sheremet-va 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
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,9 @@ | ||
| export interface VCSProviderOptions { | ||
| root: string | ||
| changedSince?: string | boolean | ||
| } | ||
|
|
||
| export interface VCSProvider { | ||
| // eslint-disable-next-line ts/method-signature-style | ||
| findChangedFiles(options: VCSProviderOptions): Promise<string[]> | ||
| } |
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,130 @@ | ||
| import { runInlineTests } from '#test-utils' | ||
| import { expect, test } from 'vitest' | ||
|
|
||
| test('custom vcsProvider that returns specific files runs only matching tests', async () => { | ||
| const { testTree, stderr } = await runInlineTests({ | ||
| 'vitest.config.js': ` | ||
| import path from 'node:path' | ||
| export default { | ||
| test: { | ||
| experimental: { | ||
| vcsProvider: { | ||
| async findChangedFiles({ root }) { | ||
| return [path.resolve(root, 'src/changed.ts')] | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| `, | ||
| 'src/changed.ts': 'export const a = 1', | ||
| 'src/not-changed.ts': 'export const b = 2', | ||
| 'related.test.ts': ` | ||
| import { a } from './src/changed.ts' | ||
| import { test, expect } from 'vitest' | ||
| test('related test', () => { | ||
| expect(a).toBe(1) | ||
| }) | ||
| `, | ||
| 'not-related.test.ts': ` | ||
| import { b } from './src/not-changed.ts' | ||
| import { test, expect } from 'vitest' | ||
| test('not related test', () => { | ||
| expect(b).toBe(2) | ||
| }) | ||
| `, | ||
| }, { | ||
| changed: true, | ||
| }) | ||
|
|
||
| expect(stderr).toBe('') | ||
| expect(testTree()).toMatchInlineSnapshot(` | ||
| { | ||
| "related.test.ts": { | ||
| "related test": "passed", | ||
| }, | ||
| } | ||
| `) | ||
| }) | ||
|
|
||
| test('custom vcsProvider that returns no files runs no tests', async () => { | ||
| const { testTree, stdout } = await runInlineTests({ | ||
| 'vitest.config.js': ` | ||
| export default { | ||
| test: { | ||
| passWithNoTests: true, | ||
| experimental: { | ||
| vcsProvider: { | ||
| async findChangedFiles() { | ||
| return [] | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| `, | ||
| 'basic.test.ts': ` | ||
| import { test, expect } from 'vitest' | ||
| test('should not run', () => { | ||
| expect(1).toBe(1) | ||
| }) | ||
| `, | ||
| }, { | ||
| changed: true, | ||
| }) | ||
|
|
||
| expect(stdout).toContain(`No test files found, exiting with code 0`) | ||
| expect(testTree()).toMatchInlineSnapshot('{}') | ||
| }) | ||
|
|
||
| test('custom vcsProvider that returns all files runs all tests', async () => { | ||
| const { testTree, stderr } = await runInlineTests({ | ||
| 'vitest.config.js': ` | ||
| import path from 'node:path' | ||
| export default { | ||
| test: { | ||
| experimental: { | ||
| vcsProvider: { | ||
| async findChangedFiles({ root }) { | ||
| return [ | ||
| path.resolve(root, 'src/a.ts'), | ||
| path.resolve(root, 'src/b.ts'), | ||
| ] | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| `, | ||
| 'src/a.ts': 'export const a = 1', | ||
| 'src/b.ts': 'export const b = 2', | ||
| 'first.test.ts': ` | ||
| import { a } from './src/a.ts' | ||
| import { test, expect } from 'vitest' | ||
| test('first test', () => { | ||
| expect(a).toBe(1) | ||
| }) | ||
| `, | ||
| 'second.test.ts': ` | ||
| import { b } from './src/b.ts' | ||
| import { test, expect } from 'vitest' | ||
| test('second test', () => { | ||
| expect(b).toBe(2) | ||
| }) | ||
| `, | ||
| }, { | ||
| changed: true, | ||
| }) | ||
|
|
||
| expect(stderr).toBe('') | ||
| expect(testTree()).toMatchInlineSnapshot(` | ||
| { | ||
| "first.test.ts": { | ||
| "first test": "passed", | ||
| }, | ||
| "second.test.ts": { | ||
| "second test": "passed", | ||
| }, | ||
| } | ||
| `) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.