Feature: deterministic VITEST_WORKER_ID for each file
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
This is how worker ID is generated:
https://github.com/vitest-dev/vitest/blob/819c6cbe40e4b670b5b3d77bc2cc53da4522a3c9/packages/vitest/src/node/pools/threads.ts#L78
I think you can just use the file name:
faker.seed(generateHash(expect.getState().testPath))
I am not sure if it works right now outside of a test function, but in theory, it should.