cargo-test-json-2-html
Convert cargo test JSON output to beautiful, self-contained HTML reports.
Features
- 🎨 Beautiful HTML reports - Clean, modern design with responsive layout
- 📊 Test statistics - Pass/fail/ignored counts
- 🔍 Detailed test output - Collapsible stdout/stderr for each test
- 🛡️ Robust error handling - Gracefully handles mixed JSON/non-JSON output
- 📱 Self-contained - Single HTML file with inline CSS and JavaScript
- 🔗 Source linking - Configurable source code links
Installation
Most users will probably want to integrate this as a library into an existing test runner system. However, absent of that, it is possible to run it as a CLI as well:
Usage
Basic Usage
Generate JSON test output and convert to HTML:
# Generate test report
Pipeline Usage
# Direct pipeline (requires nightly Rust)
|
Library Usage
use ;
// Basic usage
let json_output = r#"{ "type": "test", "name": "my_test", "event": "ok" }"#;
let config = default;
let html = convert_to_html;
// With custom source linking
let config = builder
.source_linker
.build;
let html = convert_to_html;
CLI Options
cargo-test-json-2-html [OPTIONS]
Options:
-i, --input <INPUT> Input file (use - for stdin) [default: -]
-o, --output <OUTPUT> Output file (use - for stdout) [default: -]
-h, --help Print help
Examples
Generate Report for Current Project
# Run tests and generate HTML report
# or
CI/CD Integration
# GitHub Actions example
- name: Run tests and generate report
run: |
cargo +nightly test -- --format json -Z unstable-options --show-output > test-results.json 2>&1 || true
cargo-test-json-2-html -i test-results.json -o test-report.html
- name: Upload test report
uses: actions/upload-artifact@v3
with:
name: test-report
path: test-report.html
Error Handling
The tool gracefully handles various input scenarios:
- Mixed output: Compilation messages mixed with JSON test results
- Invalid JSON: Malformed JSON lines are reported as errors
- Empty input: Generates a valid report even with no tests
- Parsing errors: Full error context included in the HTML report
Requirements
- For JSON output: Rust nightly (for
--format json -Z unstable-options) - For the tool: Rust stable (1.70+)
Output Format
The generated HTML report includes:
- Summary statistics with pass/fail/ignored counts
- Failed tests section with full error output
- Passed tests section with stdout/stderr (collapsible)
- Ignored tests section
- Parsing errors section (if any)
- Raw output section for non-JSON lines
Contributing
Contributions welcome! Please check the issues for planned features.
Development and Debugging
To generate a test report for debugging the HTML output:
# Generate test output from this project
# Convert to HTML report
# Open the report
# or
This will create a report showing the actual test results from this project, including any failures, which is useful for testing the HTML generation and styling.
License
MIT OR Apache-2.0