[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

refactor: rename `matchesTagsFilter` to `matchesTags` (#9956)

authored by

Vladimir and committed by
GitHub
(Mar 23, 2026, 3:56 PM +0100) ebfde798 56115003

+27 -27
+2 -2
docs/guide/test-tags.md
··· 303 303 304 304 ### Checking Tags Filter at Runtime 305 305 306 - You can use `TestRunner.matchesTagsFilter` (since Vitest 4.1.1) to check whether the current tags filter matches a set of tags. This is useful for conditionally running expensive setup logic only when relevant tests are included: 306 + You can use `TestRunner.matchesTags` (since Vitest 4.1.1) to check whether the current tags filter matches a set of tags. This is useful for conditionally running expensive setup logic only when relevant tests are included: 307 307 308 308 ```ts 309 309 import { beforeAll, TestRunner } from 'vitest' 310 310 311 311 beforeAll(async () => { 312 312 // Seed database when "vitest --tags-filter db" is used 313 - if (TestRunner.matchesTagsFilter(['db'])) { 313 + if (TestRunner.matchesTags(['db'])) { 314 314 await seedDatabase() 315 315 } 316 316 })
+21 -21
test/cli/test/test-tags.test.ts
··· 1361 1361 `) 1362 1362 }) 1363 1363 1364 - test('matchesTagsFilter returns true when no filter is configured', async () => { 1364 + test('matchesTags returns true when no filter is configured', async () => { 1365 1365 const { stderr, testTree } = await runInlineTests({ 1366 1366 'basic.test.js': ` 1367 1367 import { TestRunner, beforeAll, describe, expect, test } from 'vitest' ··· 1369 1369 let matchResult 1370 1370 1371 1371 beforeAll(() => { 1372 - matchResult = TestRunner.matchesTagsFilter(['unit']) 1372 + matchResult = TestRunner.matchesTags(['unit']) 1373 1373 }) 1374 1374 1375 1375 test('test 1', { tags: ['unit'] }, () => { ··· 1392 1392 `) 1393 1393 }) 1394 1394 1395 - test('matchesTagsFilter returns true when tags match the filter', async () => { 1395 + test('matchesTags returns true when tags match the filter', async () => { 1396 1396 const { stderr, testTree } = await runInlineTests({ 1397 1397 'basic.test.js': ` 1398 1398 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1400 1400 let matchUnit, matchE2e 1401 1401 1402 1402 beforeAll(() => { 1403 - matchUnit = TestRunner.matchesTagsFilter(['unit']) 1404 - matchE2e = TestRunner.matchesTagsFilter(['e2e']) 1403 + matchUnit = TestRunner.matchesTags(['unit']) 1404 + matchE2e = TestRunner.matchesTags(['e2e']) 1405 1405 }) 1406 1406 1407 1407 test('unit matches', { tags: ['unit'] }, () => { ··· 1427 1427 `) 1428 1428 }) 1429 1429 1430 - test('matchesTagsFilter supports NOT expressions', async () => { 1430 + test('matchesTags supports NOT expressions', async () => { 1431 1431 const { stderr, testTree } = await runInlineTests({ 1432 1432 'basic.test.js': ` 1433 1433 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1435 1435 let matchUnit, matchSlow 1436 1436 1437 1437 beforeAll(() => { 1438 - matchUnit = TestRunner.matchesTagsFilter(['unit']) 1439 - matchSlow = TestRunner.matchesTagsFilter(['slow']) 1438 + matchUnit = TestRunner.matchesTags(['unit']) 1439 + matchSlow = TestRunner.matchesTags(['slow']) 1440 1440 }) 1441 1441 1442 1442 test('unit passes NOT slow', { tags: ['unit'] }, () => { ··· 1462 1462 `) 1463 1463 }) 1464 1464 1465 - test('matchesTagsFilter supports AND/OR expressions', async () => { 1465 + test('matchesTags supports AND/OR expressions', async () => { 1466 1466 const { stderr, testTree } = await runInlineTests({ 1467 1467 'basic.test.js': ` 1468 1468 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1470 1470 let matchUnitFast, matchUnitSlow, matchE2eFast, matchEmpty 1471 1471 1472 1472 beforeAll(() => { 1473 - matchUnitFast = TestRunner.matchesTagsFilter(['unit', 'fast']) 1474 - matchUnitSlow = TestRunner.matchesTagsFilter(['unit', 'slow']) 1475 - matchE2eFast = TestRunner.matchesTagsFilter(['e2e', 'fast']) 1476 - matchEmpty = TestRunner.matchesTagsFilter([]) 1473 + matchUnitFast = TestRunner.matchesTags(['unit', 'fast']) 1474 + matchUnitSlow = TestRunner.matchesTags(['unit', 'slow']) 1475 + matchE2eFast = TestRunner.matchesTags(['e2e', 'fast']) 1476 + matchEmpty = TestRunner.matchesTags([]) 1477 1477 }) 1478 1478 1479 1479 test('matches complex expression', { tags: ['unit', 'fast'] }, () => { ··· 1506 1506 `) 1507 1507 }) 1508 1508 1509 - test('matchesTagsFilter supports wildcard patterns', async () => { 1509 + test('matchesTags supports wildcard patterns', async () => { 1510 1510 const { stderr, testTree } = await runInlineTests({ 1511 1511 'basic.test.js': ` 1512 1512 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1514 1514 let matchBrowserChrome, matchNode 1515 1515 1516 1516 beforeAll(() => { 1517 - matchBrowserChrome = TestRunner.matchesTagsFilter(['browser-chrome']) 1518 - matchNode = TestRunner.matchesTagsFilter(['node']) 1517 + matchBrowserChrome = TestRunner.matchesTags(['browser-chrome']) 1518 + matchNode = TestRunner.matchesTags(['node']) 1519 1519 }) 1520 1520 1521 1521 test('wildcard matches', { tags: ['browser-chrome'] }, () => { ··· 1545 1545 `) 1546 1546 }) 1547 1547 1548 - test('matchesTagsFilter with empty tags array and no filter returns true', async () => { 1548 + test('matchesTags with empty tags array and no filter returns true', async () => { 1549 1549 const { stderr, testTree } = await runInlineTests({ 1550 1550 'basic.test.js': ` 1551 1551 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1553 1553 let matchEmpty 1554 1554 1555 1555 beforeAll(() => { 1556 - matchEmpty = TestRunner.matchesTagsFilter([]) 1556 + matchEmpty = TestRunner.matchesTags([]) 1557 1557 }) 1558 1558 1559 1559 test('empty tags no filter', () => { ··· 1651 1651 }) 1652 1652 }) 1653 1653 1654 - test('matchesTagsFilter uses per-specification filter instead of global filter', async () => { 1654 + test('matchesTags uses per-specification filter instead of global filter', async () => { 1655 1655 const { fs, ctx, errorTree } = await runInlineTests({ 1656 1656 'basic.test.js': ` 1657 1657 import { TestRunner, beforeAll, expect, test } from 'vitest' ··· 1659 1659 let matchUnit, matchE2e 1660 1660 1661 1661 beforeAll(() => { 1662 - matchUnit = TestRunner.matchesTagsFilter(['unit']) 1663 - matchE2e = TestRunner.matchesTagsFilter(['e2e']) 1662 + matchUnit = TestRunner.matchesTags(['unit']) 1663 + matchE2e = TestRunner.matchesTags(['e2e']) 1664 1664 }) 1665 1665 1666 1666 test('check filter', { tags: ['e2e'] }, () => {
+1 -1
packages/runner/src/utils/index.ts
··· 10 10 } from './collect' 11 11 export { limitConcurrency } from './limit-concurrency' 12 12 export { partitionSuiteChildren } from './suite' 13 - export { createTagsFilter, matchesTagsFilter, validateTags } from './tags' 13 + export { createTagsFilter, matchesTags, validateTags } from './tags' 14 14 export { 15 15 createTaskName, 16 16 getFullName,
+1 -1
packages/runner/src/utils/tags.ts
··· 6 6 /** 7 7 * @experimental 8 8 */ 9 - export function matchesTagsFilter(testTags: string[]): boolean { 9 + export function matchesTags(testTags: string[]): boolean { 10 10 const runner = getRunner() 11 11 const tagsFilter = runner._currentSpecification?.testTagsFilter ?? runner.config.tagsFilter 12 12 if (!tagsFilter) {
+2 -2
packages/vitest/src/runtime/runners/test.ts
··· 22 22 getFn, 23 23 getHooks, 24 24 } from '@vitest/runner' 25 - import { createChainable, getNames, getTestName, getTests, matchesTagsFilter } from '@vitest/runner/utils' 25 + import { createChainable, getNames, getTestName, getTests, matchesTags } from '@vitest/runner/utils' 26 26 import { processError } from '@vitest/utils/error' 27 27 import { normalize } from 'pathe' 28 28 import { createExpect } from '../../integrations/chai/index' ··· 278 278 static getTestFn: typeof getFn = getFn 279 279 static setSuiteHooks: typeof getHooks = getHooks 280 280 static setTestFn: typeof getFn = getFn 281 - static matchesTagsFilter: typeof matchesTagsFilter = matchesTagsFilter 281 + static matchesTags: typeof matchesTags = matchesTags 282 282 283 283 /** 284 284 * @deprecated