Skip to content

feat: add --json formatter#1613

Open
pushpak1300 wants to merge 10 commits intopestphp:4.xfrom
pushpak1300:4.x
Open

feat: add --json formatter#1613
pushpak1300 wants to merge 10 commits intopestphp:4.xfrom
pushpak1300:4.x

Conversation

@pushpak1300
Copy link

@pushpak1300 pushpak1300 commented Jan 24, 2026

Summary

  • Adds a --json flag that outputs structured JSON instead of formatted console output
  • AI agents (Claude Code, Cursor, Gemini CLI, Codex, etc.) are auto-detected via shipfastlabs/agent-detector and automatically switch to JSON output — no flags needed
  • Uses a JsonOutput decorator that wraps ConsoleOutput and buffers all write()/writeln() calls, so plugins work without any modification

How it works

  1. --json flag or agent auto-detection sets PEST_JSON_OUTPUT=true
  2. JsonOutput replaces ConsoleOutput — plugins write normally but output is suppressed
  3. The Json plugin reads test results from PHPUnit's Facade::result() and emits structured JSON
  4. A shutdown handler catches early exit(1) errors and emits {"status":"error","message":"..."}

Output

Pass:

{"status":"pass"}

Fail:

{"status":"fail","failures":[{"test":"failing test","message":"Failed asserting that true is false.","location":"tests/Example.php:10","trace":"..."}]}

Token usage impact

Running Pest's test suite shows ~99% reduction in output tokens — critical for AI agents to lower costs and preserve context window space.

@pushpak1300 pushpak1300 changed the title feat: add Agent formatter feat: add --agent formatter Jan 24, 2026
@pushpak1300 pushpak1300 marked this pull request as draft January 25, 2026 15:19
@pushpak1300 pushpak1300 changed the title feat: add --agent formatter feat: replace --agent with --json formatter Feb 12, 2026
@pushpak1300 pushpak1300 changed the title feat: replace --agent with --json formatter feat: add --json formatter Feb 12, 2026
@pushpak1300 pushpak1300 marked this pull request as ready for review February 12, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant