buddy test-scripts
buddy test-scripts adds or adjusts the test, coverage, and test:watch scripts in package.json for the
project’s test runner.
buddy test-scripts [--cwd <dir>] [--runner jest|vitest]Options
Section titled “Options”| Option | Type | Default | Effect |
|---|---|---|---|
--cwd |
string | the current directory | The directory that holds the package.json to edit. |
--runner |
jest | vitest |
detected | The runner to write scripts for. Required when the project depends on both runners or on neither. |
The global options also apply.
Scripts it writes
Section titled “Scripts it writes”| Script | Jest | Vitest |
|---|---|---|
test |
jest |
vitest run |
coverage |
jest --coverage |
vitest run --coverage |
test:watch |
jest --watch |
vitest |
Runner detection
Section titled “Runner detection”buddy reads dependencies and devDependencies of package.json.
jestor@repobuddy/jestmeans Jest.vitestor@repobuddy/vitestmeans Vitest.
When it finds exactly one runner, it uses that runner. When it finds both or neither, it stops with exit code 1 and
asks for --runner. --runner always wins over detection.
Behavior
Section titled “Behavior”Each of the three scripts gets one action:
- added: the script is missing.
buddywrites the value from the table. - adjusted: the script holds a value from the table, for either runner, that differs from the chosen runner’s
value.
buddyreplaces it. This is how a project that moved from Jest to Vitest picks up the new commands. - skipped: the script already holds the chosen runner’s value, or it holds any other value. Any other value is a
customization, and
buddyleaves it alone.
Other details:
- A second run changes nothing.
buddywrites the file only when at least one script is added or adjusted.- It keeps the file’s indentation (tabs or spaces) and its trailing newline.
- It does not install the runner.
Output
Section titled “Output”One line per script, then a summary when nothing changed:
added "test": jestadded "coverage": jest --coverageadded "test:watch": jest --watchskipped "test": jestskipped "coverage": jest --coverageskipped "test:watch": jest --watchthe jest scripts are already what they should beExit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
The scripts were written, or were already correct. |
1 |
No package.json in the directory, or the runner cannot be detected. |
2 |
An unknown option, or a --runner value other than jest or vitest. |
Examples
Section titled “Examples”Add Jest scripts
Section titled “Add Jest scripts”package.json before:
{ "name": "jest-app", "devDependencies": { "jest": "^30.0.0" }}buddy test-scriptsadded "test": jestadded "coverage": jest --coverageadded "test:watch": jest --watchSwitch from Jest to Vitest
Section titled “Switch from Jest to Vitest”A project depends on @repobuddy/vitest and still has the Jest scripts:
{ "devDependencies": { "@repobuddy/vitest": "^2.0.0" }, "scripts": { "test": "jest", "coverage": "jest --coverage", "test:watch": "jest --watch" }}adjusted "test": jest -> vitest runadjusted "coverage": jest --coverage -> vitest run --coverageadjusted "test:watch": jest --watch -> vitestKeep a customized script
Section titled “Keep a customized script”"test": "vitest run --project unit" is not a value from the table, so it stays:
skipped "test": vitest run --project unitadded "coverage": vitest run --coverageadded "test:watch": vitestA project with both runners
Section titled “A project with both runners”buddy test-scriptscannot tell which test runner this project uses: it depends on jest and vitestname the one the scripts are for with --runner jest|vitestbuddy test-scripts --runner vitestA directory with no package.json
Section titled “A directory with no package.json”buddy test-scripts --cwd nopeno package.json in noperun this from the project directory, or point at it with --cwd