vitest-dev / vitest-dev/vitest

Feature: deterministic VITEST_WORKER_ID for each file

Open
#2,945 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement 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

Would be awesome if we could have a deterministic assignment to VITEST_WORKER_ID.
At the moment each spec file runs in a random worker depending on some random events liek for example speed of other spec files before the current one.
For example I would like to initialize faker with unique seed per worker, like this:

faker.seed(11+Number(process.env.VITEST_WORKER_ID))

and if it is deterministic I can use snapshots with generated data and they will always match.

Suggested solution

calculate total number of workers(is this possible?), put all the spec files in array, sort them by created date and assign X to each worker.
This means that tests created first will always keep the VITEST_WORKER_ID 1, whereas all new tests will get the highest VITEST_WORKER_ID.

Alternative

No response

Additional context

No response

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 how spec files are assigned to workers and how VITEST_WORKER_ID is set. Evaluate whether a stable assignment can account for the total worker count and file ordering, then verify that repeated runs give each file the same worker ID and support stable faker seeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.