patterntypescriptTip
Test tagging and filtering: label tests by type, owner, and speed to run targeted subsets
Viewed 0 times
test tagstest filteringplaywright tagsjest greptest organizationtest subset
Problem
All tests live in the same suite with no way to run only integration tests, only tests owned by a specific team, or only fast tests. Every test run is all-or-nothing.
Solution
Tag tests using Jest's
--testNamePattern, Vitest's describe.skip, or Playwright's tag option (v1.42+). Use naming conventions like [integration], [smoke], @slow in test titles and filter via --grep. In Playwright, use test.tag('@smoke') and run with --grep @smoke.Why
Tagged tests enable targeted runs: run only smoke tests after deploy, run only your team's tests during development, run only fast tests on save. This improves developer experience without changing test logic.
Gotchas
- Playwright's official tag syntax requires v1.42+; use grep patterns in older versions
- Tags embedded in test names (
it('[unit] does X')) work but produce ugly output; prefer official tag mechanisms - Tag taxonomy must be agreed on by the team — inconsistent tags reduce their value
- Do not over-tag — a tag that applies to 95% of tests is useless; tags should meaningfully discriminate
Code Snippets
Playwright test tagging and grep filter
// Playwright v1.42+ tag syntax
test('homepage loads', { tag: '@smoke' }, async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle(/My App/);
});
// Run: npx playwright test --grep @smokeRevisions (0)
No revisions yet.