vitest-git-trigger-patterns
v1.0.2
Published
Git VCS provider for Vitest to map broad changed files to focused tests during `--changed` runs
Readme
vitest-git-trigger-patterns
Git VCS provider for Vitest to map broad changed files to focused tests during --changed runs
Why?
- Vitest's
--changedoption is great for running tests related to changed files, but it can be too broad in some cases. For example, if you change a shared icon or style file, Vitest will run all tests that import that file, which can be a lot of tests.
Installation
npm install --save-dev vitest-git-trigger-patternsUsage
You can specify the VCS provider in your vitest.config.ts:
import type { UserConfig } from "vitest/config";
import { git } from "vitest-git-trigger-patterns";
export default {
test: {
experimental: {
vcsProvider: git({
triggerPatterns: [
{
pattern: /\/apps\/([^/]+)\/src\/(icons|i18n|styles)\//,
testsToRun: (_, match) => [`./apps/${match[1]}/tests/rendering.test.ts`, `./apps/${match[1]}/tests/smoke.test.ts`],
},
{
pattern: /\/apps\/([^/]+)\/package\.json$/,
testsToRun: (_, match) => `./apps/${match[1]}/tests/smoke.test.ts`,
},
],
}),
},
},
} satisfies UserConfig;Run Vitest with changed-file detection as usual:
vitest --changed
vitest --changed origin/mainPatterns receive the absolute changed-file path and the result of RegExp.exec. Returned test paths may be absolute or relative to the Vitest project root. Files that do not match a pattern are passed through for Vitest's normal module-graph handling.
Returning an empty array prevents module-graph fallback for that changed file. All matching patterns are evaluated, so another matching pattern can still return tests.
