docs(reporters): .vitest results directory convention#9993
docs(reporters): .vitest results directory convention#9993AriPerkkio wants to merge 1 commit intovitest-dev:mainfrom
.vitest results directory convention#9993Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
| Vitest and third party integrations can use `.vitest` directory to store generated artifacts. It's recommended to add this in your `.gitignore`. | ||
|
|
||
| ``` sh [.gitignore] | ||
| # Vitest reports and artifacts | ||
| .vitest/ | ||
| ``` | ||
|
|
There was a problem hiding this comment.
| ## Storing artifacts on file system | ||
|
|
||
| If your custom reporter needs to store any artifacts on file system it should place them inside `.vitest` directory. This directory is a convention that Vitest reporters and third party integrations can use to co-locate their results in a single directory. This way users of your custom reporter do not need to add multiple exclusion in their `.gitignore`. Only the `.vitest` is needed. | ||
|
|
||
| Reporters and other integrations should respect following rules around `.vitest` directory: | ||
|
|
||
| - `.vitest` directory is placed in [the `root` of the project](/config/root) | ||
| - Reporter can create `.vitest` directory if it does not already exist | ||
| - Reporter should never remove `.vitest` directory | ||
| - Reporter should create their own directory inside `.vitest`, for example `.vitest/yaml-reporter/` | ||
| - Reporter can remove their own specific directory inside `.vitest`, for example `.vitest/yaml-reporter/` | ||
|
|
||
| ```ansi | ||
| .vitest | ||
| │ | ||
| ├── yaml-reporter | ||
| │ ├── results.yaml | ||
| │ └── summary.yaml | ||
| │ | ||
| └── junit-reporter | ||
| └── report.xml | ||
| ``` | ||
|
|
There was a problem hiding this comment.
|
|
||
| ## Storing artifacts on file system | ||
|
|
||
| If your custom reporter needs to store any artifacts on file system it should place them inside `.vitest` directory. This directory is a convention that Vitest reporters and third party integrations can use to co-locate their results in a single directory. This way users of your custom reporter do not need to add multiple exclusion in their `.gitignore`. Only the `.vitest` is needed. |
There was a problem hiding this comment.
Should we make it simpler for custom reporters to use this convention by exposing utilities on something like vitest.report?
vitest.report.writeFilevitest.report.deleteFilevitest.report.readFile
It accepts a file relative to .vitest folder. If .vitest folder doesn't exist, we create it. This could also be useful for internal reporters.
There was a problem hiding this comment.
Sounds good - anything to make it easier for users to follow these guidelines.
Maybe it something like:
// Automatically creates `<root>/.vitest` and `.vitest/my-yaml-reporter`.
// All actions are scoped to `.vitest/my-yaml-reporter`.
// resultWriter cannot remove '.vitest'.
const resultWriter = vitest.report.createResultWriter("my-yaml-reporter");
// Removes and re-creates `.vitest/my-yaml-reporter`.
resultWriter.clean();
// Writes `.vitest/my-yaml-reporter/result.yml`.
resultWriter.write("- key: value", "result.yml");
// Reads `.vitest/my-yaml-reporter/result.yml`.
resultWriter.read("result.yml");
// Deletes `.vitest/my-yaml-reporter/result.yml`.
resultWriter.delete("result.yml");|
Looks good to me. For the follow-up, would we also add |
Description
Resolves #9952
Once merged, I'll create follow-up issue for using
.vitestin Vitest's built-in reporters (at least html?) and for other artifacts. Changing default values will be breaking change.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.