Skip to content

docs(reporters): .vitest results directory convention#9993

Open
AriPerkkio wants to merge 1 commit intovitest-dev:mainfrom
AriPerkkio:docs/reporter-directory-convention
Open

docs(reporters): .vitest results directory convention#9993
AriPerkkio wants to merge 1 commit intovitest-dev:mainfrom
AriPerkkio:docs/reporter-directory-convention

Conversation

@AriPerkkio
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio commented Mar 27, 2026

Description

Resolves #9952

Once merged, I'll create follow-up issue for using .vitest in 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:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 06dff21
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69c68d4ff8699c00087a2935
😎 Deploy Preview https://deploy-preview-9993--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +46 to +52
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/
```

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +75 to +97
## 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
```

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it simpler for custom reporters to use this convention by exposing utilities on something like vitest.report?

  • vitest.report.writeFile
  • vitest.report.deleteFile
  • vitest.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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

@hi-ogawa
Copy link
Copy Markdown
Collaborator

hi-ogawa commented Mar 29, 2026

Looks good to me. For the follow-up, would we also add .vitest for various default ignore/exclude like test, coverage, etc? (also watch ignore?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define convention for test reporter output directory

3 participants