Crates.io | cargo-test-json-2-html |
lib.rs | cargo-test-json-2-html |
version | 0.1.1 |
created_at | 2025-09-06 19:11:37.993837+00 |
updated_at | 2025-09-07 20:18:26.86435+00 |
description | Convert cargo test JSON output to beautiful, self-contained HTML reports |
homepage | |
repository | https://github.com/rcoh/cargo-test-json-2-html |
max_upload_size | |
id | 1827382 |
size | 137,627 |
Convert cargo test JSON output to beautiful, self-contained HTML reports.
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:
cargo install --locked cargo-test-json-2-html
Generate JSON test output and convert to HTML:
# Generate test report
cargo +nightly test -- --format json -Z unstable-options --show-output > test-output.json 2>&1
cargo-test-json-2-html -i test-output.json -o report.html
# Direct pipeline (requires nightly Rust)
cargo +nightly test -- --format json -Z unstable-options --show-output 2>&1 | cargo-test-json-2-html -o report.html
use cargo_test_json_2_html::{convert_to_html, Config, SourceLinker};
// Basic usage
let json_output = r#"{ "type": "test", "name": "my_test", "event": "ok" }"#;
let config = Config::default();
let html = convert_to_html(json_output, config);
// With custom source linking
struct GitHubLinker {
repo: String,
}
impl SourceLinker for GitHubLinker {
fn link(&self, file: &str, line: u32) -> Option<String> {
Some(format!("https://github.com/{}/blob/main/{}#L{}", self.repo, file, line))
}
}
let config = Config::builder()
.source_linker(Box::new(GitHubLinker {
repo: "user/repo".to_string()
}))
.build();
let html = convert_to_html(json_output, config);
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
# Run tests and generate HTML report
cargo +nightly test -- --format json -Z unstable-options --show-output > test-results.json 2>&1
cargo-test-json-2-html -i test-results.json -o test-report.html
open test-report.html # macOS
# or
xdg-open test-report.html # Linux
# 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
The tool gracefully handles various input scenarios:
--format json -Z unstable-options
)The generated HTML report includes:
Contributions welcome! Please check the issues for planned features.
To generate a test report for debugging the HTML output:
# Generate test output from this project
cargo +nightly test -- --format json -Z unstable-options --show-output > test-output.json 2>&1
# Convert to HTML report
cargo run -- -i test-output.json -o test-report.html
# Open the report
open test-report.html # macOS
# or
xdg-open test-report.html # Linux
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.
MIT OR Apache-2.0