-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: support tags #9478
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
Merged
feat: support tags #9478
Changes from 19 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
e6e834b
feat: support tags
sheremet-va c85fbba
fix: code to filter tags
sheremet-va d77b401
chore: fix filtering
sheremet-va 07c13eb
docs: improve tags docs
sheremet-va 072e115
docs: remove repeated example
sheremet-va 972574d
docs: add tags to config
sheremet-va 5adfef3
feat: support options inheritence
sheremet-va 09e07e1
test: cleanup
sheremet-va bff0b23
feat: add --strict-tags option
sheremet-va dfd225b
feat: support @tag jsdoc
sheremet-va 7f9df91
feat: support filter
sheremet-va 9378016
refactor: rename to tagsFilter
sheremet-va 6f1e45a
docs: cleanup
sheremet-va 7dde3b8
docs: document options
sheremet-va d4a55de
docs: fix generator
sheremet-va feef1f9
chore: cleanup
sheremet-va b1c8bc1
chore: note
sheremet-va 1882df2
docs: cleanup
sheremet-va fca2007
test: fix failing tests
sheremet-va c299640
refactor: rename @tag pragma to @module-tag
sheremet-va 5fc1ebc
fix: support projects properly
sheremet-va 68c78a5
docs: typos
sheremet-va 86c1a36
test: add more tests
sheremet-va a18ee38
test: fix tests
sheremet-va 9392799
test: remove only
sheremet-va 124a649
fix: validate test tag names
sheremet-va c9d7e3d
chore: cleanup
sheremet-va 25c0011
feat: add --list-tags
sheremet-va b9e2720
feat: support `--test-tags=json`
sheremet-va bcaba86
fix: support collecting tags statically
sheremet-va 958a081
fixx(ui): expand nodes when searching
sheremet-va d42bb25
feat(ui): display tags as badges, support filtering
sheremet-va 616ca0e
fix: pass down plugins
sheremet-va 6855ce1
Merge branch 'main' of github.com:vitest-dev/vitest into feat/support…
sheremet-va 43a9bf7
docs: add UI screenshots
sheremet-va 3ccbd66
chore: fix colors
sheremet-va 21510d2
chore: cleanup
sheremet-va 3d59854
chore: lint
sheremet-va 2cce331
docs: mention --list-tags in config
sheremet-va 072214a
refactor: don't use ternaries
sheremet-va 235fa9c
docs: review from raul
sheremet-va 0f3d9b5
test: fix ui test
sheremet-va 7b57c00
test(ui): add tags filter test
sheremet-va 60cabb6
test(ui): check unknown tag
sheremet-va 1995842
refactor: remove repetetive ode
sheremet-va 1d59571
chore: tag -> tagsFilter, fix type
sheremet-va aab5e5f
docs: clarify
sheremet-va d1075ff
chore: review
sheremet-va b29ecf6
chore: cleanup
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| title: strictTags | Config | ||
| outline: deep | ||
| --- | ||
|
|
||
| # strictTags <Version>4.1.0</Version> {#stricttags} | ||
|
|
||
| - **Type:** `boolean` | ||
| - **Default:** `true` | ||
| - **CLI:** `--strict-tags`, `--no-strict-tags` | ||
|
|
||
| Should Vitest throw an error if test has a [`tag`](/config/tags) that is not defined in the config to avoid silently doing something surprising due to mistyped names (applying the wrong configuration or skipping the test due to a `--tags-filter` flag). | ||
|
|
||
| Note that Vitest will always throw an error if `--tags-filter` flag defines a tag not present in the config. | ||
|
|
||
| For examle, this test will throw an error because the tag `fortnend` has a typo (it should be `frontend`): | ||
|
|
||
| ::: code-group | ||
| ```js [form.test.js] | ||
| test('renders a form', { tags: ['fortnend'] }, () => { | ||
| // ... | ||
| }) | ||
| ``` | ||
| ```js [vitest.config.js] | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| tags: [ | ||
| { name: 'frontend' }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
| ::: |
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,198 @@ | ||
| --- | ||
| title: tags | Config | ||
| outline: deep | ||
| --- | ||
|
|
||
| # tags <Version>4.1.0</Version> {#tags} | ||
|
|
||
| - **Type:** `TestTagDefinition[]` | ||
| - **Default:** `[]` | ||
|
|
||
| Defines all [available tags](/guide/test-tags) in your test project. By default, if test defines a name not listed here, Vitest will throw an error, but this can be configured via a [`strictTags`](/config/stricttags) option. | ||
|
|
||
| If you are using [`projects`](/config/projects), they will inherit all global tags definitions automatically. | ||
|
|
||
| Use [`--tags-filter`](/guide/test-tags#syntax) to filter tests by their tags. | ||
|
|
||
| ::: tip FILTERING | ||
| You can use a wildcard (*) to match any number of symbols. To ignore a tag, add an exclamation mark (!) at the start of the tag. | ||
| ::: | ||
|
|
||
| ## name | ||
|
|
||
| - **Type:** `string` | ||
| - **Required:** `true` | ||
|
|
||
| The name of the tag. This is what you use in the `tags` option in tests. | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| test: { | ||
| tags: [ | ||
| { name: 'unit' }, | ||
| { name: 'e2e' }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ::: tip | ||
| If you are using TypeScript, you can enforce what tags are available by augmenting the `TestTags` type with a property that containst a union of strings (make sure this file is included by your `tsconfig`): | ||
|
|
||
| ```ts [vitest.shims.ts] | ||
| import 'vitest' | ||
|
|
||
| declare module 'vitest' { | ||
| interface TestTags { | ||
| tags: | ||
| | 'frontend' | ||
| | 'backend' | ||
| | 'db' | ||
| | 'flaky' | ||
| } | ||
| } | ||
| ``` | ||
| ::: | ||
|
|
||
| ## description | ||
|
|
||
| - **Type:** `string` | ||
|
|
||
| A human-readable description for the tag. This will be shown in UI and inside error messages when a tag is not found. | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| test: { | ||
| tags: [ | ||
| { | ||
| name: 'slow', | ||
| description: 'Tests that take a long time to run.', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ## priority | ||
|
|
||
| - **Type:** `number` | ||
| - **Default:** `undefined` | ||
|
sheremet-va marked this conversation as resolved.
Outdated
|
||
|
|
||
| Priority for merging options when multiple tags with the same options are applied to a test. Lower number means higher priority (e.g., priority `1` takes precedence over priority `3`). | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| test: { | ||
| tags: [ | ||
| { | ||
| name: 'flaky', | ||
| timeout: 30_000, | ||
| priority: 1, // higher priority | ||
| }, | ||
| { | ||
| name: 'db', | ||
| timeout: 60_000, | ||
| priority: 2, // lower priority | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| When a test has both tags, the `timeout` will be `30_000` because `flaky` has a higher priority. | ||
|
|
||
| ## Test Options | ||
|
|
||
| Tags can define test options that will be applied to every test marked with the tag. These options are merged with the test's own options, with the test's options taking precedence. | ||
|
|
||
| ### timeout | ||
|
|
||
| - **Type:** `number` | ||
|
|
||
| Test timeout in milliseconds. | ||
|
|
||
| ### retry | ||
|
|
||
| - **Type:** `number | { count?: number, delay?: number, condition?: RegExp }` | ||
|
|
||
| Retry configuration for the test. If a number, specifies how many times to retry. If an object, allows fine-grained retry control. | ||
|
|
||
| ### repeats | ||
|
|
||
| - **Type:** `number` | ||
|
|
||
| How many times the test will run again. | ||
|
|
||
| ### concurrent | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Whether suites and tests run concurrently. | ||
|
|
||
| ### sequential | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Whether tests run sequentially. | ||
|
|
||
| ### skip | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Whether the test should be skipped. | ||
|
|
||
| ### only | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Should this test be the only one running in a suite. | ||
|
|
||
| ### todo | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Whether the test should be skipped and marked as a todo. | ||
|
|
||
| ### fails | ||
|
|
||
| - **Type:** `boolean` | ||
|
|
||
| Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail. | ||
|
|
||
| ## Example | ||
|
|
||
| ```ts | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| tags: [ | ||
| { | ||
| name: 'unit', | ||
| description: 'Unit tests.', | ||
| }, | ||
| { | ||
| name: 'e2e', | ||
| description: 'End-to-end tests.', | ||
| timeout: 60_000, | ||
| }, | ||
| { | ||
| name: 'flaky', | ||
| description: 'Flaky tests that need retries.', | ||
| retry: process.env.CI ? 3 : 0, | ||
| priority: 1, | ||
| }, | ||
| { | ||
| name: 'slow', | ||
| description: 'Slow tests.', | ||
| timeout: 120_000, | ||
| }, | ||
| { | ||
| name: 'skip-ci', | ||
| description: 'Tests to skip in CI.', | ||
| skip: !!process.env.CI, | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| ``` | ||
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
Oops, something went wrong.
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.