vitest-dev / vitest-dev/vitest

Per-file opt-in isolation

Open
#8,010 7 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-to-be-discussed
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Clear and concise description of the problem

--no-isolate is a great way to increase performance, drastically speeding things up in our large monorepo. However, we also have leaky files that mutate global state, which break other tests. It's inconvenient to fix all of these tests for us, and it would be very convenient if we could say "isolate just these test files". By far the biggest time sink for us with Vitest is the collect step, because basically every single file in the monorepo has to be re-imported for each test file.

It's not even really that we want those test files to be isolated themselves, we really just want the worker to be cleaned up after those test files, so that changes in that one file don't leak into other test files.

I think this would be a great middle ground for performance, where most tests that don't leak run quickly, and the few that need isolation can opt-in to it.

Suggested solution

Perhaps a comment like // @vitest-environment - // @vitest-isolate?

Alternative

I guess the config could have some sort of file matching regex as well, like environmentMatchGlobs (though that's deprecated I know)

Additional context

I know adding even more features and configuration isn't the best, but in the name of performance I think it would be worth it.

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the collect step and worker lifecycle described in the issue, including how per-file isolation could be selected. Done means a test file can opt into cleanup without forcing isolation for every file, while non-leaky files retain the performance benefit of --no-isolate; add or update coverage for both behaviors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
performance, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.