Set up test scripts
This guide writes the test, coverage, and test:watch scripts into package.json for Jest or Vitest.
-
Install the test runner, or its repobuddy preset package.
buddydetects the runner from either.Terminal window # Jestpnpm add -D jest @repobuddy/jest# Vitestpnpm add -D vitest @repobuddy/vitest -
Install
repobuddy.Terminal window pnpm add -D repobuddy -
Run
buddy test-scriptsfrom the project directory.Terminal window pnpm exec buddy test-scriptsFor a package in a workspace, run it from the root and name the package:
Terminal window pnpm exec buddy test-scripts --cwd packages/app -
If the project depends on both runners, or on neither, name the runner.
Terminal window pnpm exec buddy test-scripts --runner vitest -
Read the output.
addedandadjustedlines are changes. Askippedline with your own command meansbuddykept a customized script.
Result
Section titled “Result”For a Vitest project, package.json now holds:
{ "scripts": { "test": "vitest run", "coverage": "vitest run --coverage", "test:watch": "vitest" }}For Jest the values are jest, jest --coverage, and jest --watch.
Verify
Section titled “Verify”- Run the command again. It prints
the vitest scripts are already what they should be(orjest). - Run
pnpm test.
Move from Jest to Vitest
Section titled “Move from Jest to Vitest”Run the command again after you switch runners. Scripts that still hold the Jest values from the table are adjusted to the Vitest values. A script you changed by hand stays as it is.