Skip to content

rtk vitest run loses the whole result on vitest 5: the JSON reporter writes to .vitest/json/output.json, not stdout #4224

Open

Description

@Maelstromeous

Summary

With vitest 5, rtk vitest run loses the test result entirely. rtk adds --reporter=json and parses stdout, but vitest 5's JSON reporter writes the report to a file by default and prints only its path. Every parser tier fails, rtk passes through that one line, and it records the run as ~99.8% saved.

Environment

  • rtk 0.44.1 (hook installed for Claude Code)
  • vitest 5.0.1, pnpm workspace, Linux

Reproduce

In any vitest 5 project:

pnpm exec vitest run     # the hook rewrites this to: rtk vitest run

What I get

The whole output, for a 624-test suite that passed:

[RTK:PASSTHROUGH] vitest parser: All parsing tiers failed
JSON report written to <project>/.vitest/json/output.json
  • No pass/fail counts and no failures. A failing run looks the same apart from its exit code.
  • rtk gain logs the run as 13,514 input tokens and 24 output tokens, so a run that returned no result counts as a near-perfect saving.
  • It leaves an untracked .vitest/json/output.json (209 KB here) in the package directory.

Cause

In vitest 5.0.1 the JSON reporter only prints to stdout when its stdout option is set. Otherwise it writes outputFile, or .vitest/json/output.json when no outputFile is configured, and logs JSON report written to <path>. From JsonReporter in vitest/dist:

const outputFile = this.options.outputFile ?? getOutputFile(this.ctx.config, "json");
if (outputFile) { /* writes the file */ }
else if (this.options.stdout) this.ctx.logger.log(resultString);
else {
  const report = this.ctx.createReport("json");
  await report.writeFile("output.json", resultString);
  this.ctx.logger.log(`JSON report written to ${resolve(report.root, "output.json")}`);
}

rtk's parser expects that JSON on stdout.

Possible fixes

  • Pass --outputFile.json=<temp file> alongside --reporter=json, read the report from that file, then delete it. That works whichever way vitest sends reporter output and leaves nothing in the project.
  • Or, on vitest 5 and later, turn on the reporter's stdout option.
  • Separately, when every parser tier fails, it would help if rtk passed through the command's real output (or at least its tail) and didn't record the run as saved.

For now I've excluded ^pnpm exec vitest\b in [hooks] exclude_commands.

Activity

  1. amilligan commented on Nov 25, 2026

    @amilligan

    Confirming on the current release, with the consequence in a real project and a tested workaround.

    Environment: rtk 1.2.1, vitest 5.1.2, macOS.

    Reproduction: a scratch project with two passing tests, and rtk vitest run from the project directory. The whole output is the two lines from this report ([RTK:PASSTHROUGH] vitest parser: All parsing tiers failed and JSON report written to <project>/.vitest/json/output.json). The file (1,057 bytes) is left in the project root, and no .vitest directory existed before the run.

    Consequence in a real project: the stray file failed a Prettier format check twice, because the check reads untracked files, and a broad git add could commit it. Agents ran plain npx vitest run, and the hook rewrote it to rtk vitest, so nobody asked for the wrapper. Three worktrees of one project ended up with the file.

    Workaround checked: exclude_commands = ["vitest"] under [hooks]. With it, rtk rewrite gives no rewrite (exit 1) for npx vitest run ..., pnpm exec vitest run ..., and bare vitest run. Before it, each exited 3 and printed rtk vitest .... A control (npx jest run) still rewrites. This was checked with rtk rewrite only, not with a full run after the change.

    The first fix proposed above (an explicit output file in the temp directory, read back and deleted) fits. It was not tested here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions