use super::Reporter;
use crate::state::{TestResult, TestResults};
use anyhow::{Context, Result};
use std::fs::File;
use std::path::PathBuf;
pub struct JsonReporter {
output_path: PathBuf,
}
impl JsonReporter {
pub fn new(output_path: PathBuf) -> Self {
Self { output_path }
}
}
impl Reporter for JsonReporter {
fn on_test_start(&self, _test_name: &str) {
}
fn on_test_end(&self, _test_name: &str, _result: &TestResult) {
}
fn on_suite_end(&self, results: &TestResults) -> Result<()> {
let file = File::create(&self.output_path).with_context(|| {
format!(
"Failed to create JSON report file: {}",
self.output_path.display()
)
})?;
serde_json::to_writer_pretty(file, results)
.context("Failed to serialize test results to JSON")?;
Ok(())
}
}