vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Make `.vitest` artifact directory configurable

Open Brainshaker95 opened this issue 2 months ago • 5 comments

Clear and concise description of the problem

Vitest 5 moved its shared artifacts to .vitest/, but the directory is currently hard-coded in createReport() as resolve(config.root, '.vitest'). Individual outputs can still be configured with attachmentsDir, outputFile, outputDir, etc., but there is no way to change the root for artifacts created through createReport(). This also affects third-party reporters using the new API.

Suggested solution

Add an artifactsDir option with .vitest as the default.

createReport() and the default paths for attachmentsDir, mergeReports, and the blob/json/junit/html outputs should derive from it. Explicit paths should continue to take precedence.

Also add a matching --artifactsDir CLI option for CI.

Alternative

Configure each output separately. This doesn't cover createReport() artifacts and means maintaining a bunch of unrelated path settings.

Additional context

We keep tool caches and artifacts under one git-ignored directory. Vitest coverage already supports this via coverage.reportsDirectory.

Having a configurable artifact root would let .vitest follow the same convention instead of requiring another ignore entry per project.

AI assistance (Claude) was used to help draft this issue; the issue and proposed feature are from me.

Validations

Brainshaker95 avatar Sep 14 '26 21:09 Brainshaker95

We still have --outputFile option https://vitest.dev/config/outputfile.html and probably we should also decide what to do with that long run when considering new option for .vitest.

hi-ogawa avatar Sep 25 '26 08:09 hi-ogawa

We still have --outputFile option https://vitest.dev/config/outputfile.html and probably we should also decide what to do with that long run when considering new option for .vitest.

Let's remove that one in https://github.com/vitest-dev/vitest/issues/11355.

Configuring .vitest directory to another one sounds good to me. We'll just need to figure out what the option should be called:

  • artifactsDir
  • artifactsRoot
  • reportsDir
  • reportsRoot
  • outputDir (like https://playwright.dev/docs/api/class-testconfig#test-config-output-dir)

AriPerkkio avatar Sep 25 '26 08:09 AriPerkkio

We have a concept of a "test artifact" that can have attachments so I would avoid "artifact" in naming. I vote for reportsDir or outputDir

sheremet-va avatar Sep 30 '26 08:09 sheremet-va

We decided to go with outputDir

sheremet-va avatar Oct 09 '26 08:10 sheremet-va

I'd like to pick this up with the outputDir name decided above.

The plan: add a top-level outputDir option (default .vitest, resolved against root) and derive the current hard-coded .vitest paths from it:

  • createReport() (reporters/report.ts), so blob/json/junit and third-party reporters follow it
  • the attachmentsDir default (resolveConfig.ts)
  • the --merge-reports default path (cli-config.ts)
  • the html reporter's default (packages/ui/node/reporter.ts)

Paths set explicitly keep working as they do now. Two questions:

  1. The html reporter already has its own outputDir option. Should it keep it as an override of the top-level one, or should it be dropped to avoid two options with the same name?
  2. Should outputDir be root-only like createReport() today, or per project like attachmentsDir?

Happy to open a PR once this is approved.

nomadical avatar Nov 09 '26 08:11 nomadical