Sharding

04 04 Problem
Our test files are running in parallel and our test cases are running concurrently, but we can do more with Vitest. Large test suites can still be slow even despite all of that parallelism simply because there are a lot of tests to run.
This is where it comes in handy to split our entire test suite into groups (or shards) using a technique called sharding.
With sharding, we can split a huge test suite in smaller pieces and run them individually and in parallel. It will mean multiple Vitest processes running different portions of the test suite.
Sharing is particularly handy in CI where you can split a huge test suite into groups and run them in parallel jobs, giving you faster test runs and, as a result, faster iteration loop even when you've got a lot of tests across the product.

Your task

Right now, you've got a big test suite on your hands:
 βœ“ src/one.test.ts (5000 tests) 2645ms
 βœ“ src/two.test.ts (5000 tests) 2643ms

 Test Files  2 passed (2)
      Tests  10000 passed (10000)
   Start at  11:31:23
   Duration  2.93s (transform 24ms, setup 0ms, collect 75ms, tests 5.29s, environment 0ms, prepare 68ms)
These 10,000 tests take almost 3 seconds to complete. That won't do!
πŸ‘¨β€πŸ’Ό In this exercise, your task is to split these tests into shards. This will mean writing a custom script that will run your tests at
run-tests.sh
. Open that file and complete it to enable sharding.
Once you're done, verify your setup by running that Bash script:
./run-tests.sh
Then, merge the test reports generated by Vitest using this command:
npx vitest run --merge-reports
Preview the merged reports to see the test summary from your sharded run.
Good luck!

Please set the playground first

Loading "Sharding"
Loading "Sharding"