Skip to content

Per-file opt-in isolation #8010

@abrenneke

Description

@abrenneke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-to-be-discussedEnhancement under consideration (priority)

    Projects

    Status

    Discussing

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions