Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip ANSI escapes from JUnit output #426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions rust/pact_verifier_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ default = ["datetime", "xml", "plugins", "multipart", "junit"]
datetime = ["pact_models/datetime", "pact_verifier/datetime"] # Support for date/time matchers and expressions
xml = ["pact_models/xml", "pact_verifier/xml"] # support for matching XML documents
plugins = ["pact_verifier/plugins"]
multipart = ["pact_verifier/multipart"] # suport for MIME multipart bodies
junit = ["dep:junit-report"] # suport for MIME multipart bodies
multipart = ["pact_verifier/multipart"] # support for MIME multipart bodies
junit = ["dep:junit-report", "dep:strip-ansi-escapes"] # support for Junit format reports

[dependencies]
ansi_term = "0.12.1"
Expand All @@ -34,6 +34,7 @@ pact_verifier = { version = "~1.2.1", path = "../pact_verifier", default-feature
regex = "1.10.2"
reqwest = { version = "0.12.4", default-features = false, features = ["rustls-tls-native-roots", "blocking", "json"] }
serde_json = "1.0.108"
strip-ansi-escapes = { version = "0.2.0", optional = true }
time = "0.3.31"
tokio = { version = "1.35.1", features = ["full"] }
tracing = "0.1.40"
Expand Down
7 changes: 5 additions & 2 deletions rust/pact_verifier_cli/src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::File;
use std::io::Write;

#[cfg(feature = "junit")] use junit_report::{ReportBuilder, TestCaseBuilder, TestSuiteBuilder};
#[cfg(feature = "junit")] use strip_ansi_escapes;
use serde_json::Value;
use tracing::debug;

Expand All @@ -22,7 +23,8 @@ pub(crate) fn write_junit_report(result: &VerificationExecutionResult, file_name
let mut f = File::create(file_name)?;

let mut test_suite = TestSuiteBuilder::new(provider);
test_suite.set_system_out(result.output.join("\n").as_str());
let stripped_system_out = strip_ansi_escapes::strip_str(result.output.join("\n"));
test_suite.set_system_out(&stripped_system_out);
for interaction_result in &result.interaction_results {
let duration = time::Duration::try_from(interaction_result.duration).unwrap_or_default();
let test_case = match &interaction_result.result {
Expand All @@ -42,7 +44,8 @@ pub(crate) fn write_junit_report(result: &VerificationExecutionResult, file_name
"",
"Verification for interaction failed"
);
builder.set_system_out(output_buffer.join("\n").as_str());
let stripped_output = strip_ansi_escapes::strip_str(output_buffer.join("\n"));
builder.set_system_out(&stripped_output);
builder
},
MismatchResult::Error(error, _) => TestCaseBuilder::error(
Expand Down
Loading