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
fix(test): strip ansi colors in junit output #23371
base: main
Are you sure you want to change the base?
Conversation
static ANSI_ESCAPE_REMOVE: Lazy<Regex> = | ||
lazy_regex::lazy_regex!(r#"\x1b\[([\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])"#); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like we already have this code available somewhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you can import it from console_static_text::ansi::strip_ansi_codes
// deno-lint-ignore no-explicit-any | ||
Deno.test("step fail color", async (t: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this type annotation needed?
TestResult::Failed(failure) => { | ||
let message = failure.overview(); | ||
let detail = failure.detail(); | ||
let message_stripped = | ||
ANSI_ESCAPE_REMOVE.replace_all(message.as_str(), ""); | ||
let detail_stripped = | ||
ANSI_ESCAPE_REMOVE.replace_all(detail.as_str(), ""); | ||
quick_junit::TestCaseStatus::NonSuccess { | ||
kind: quick_junit::NonSuccessKind::Failure, | ||
message: Some(message_stripped.into()), | ||
ty: None, | ||
description: Some(detail_stripped.into()), | ||
reruns: vec![], | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that it would be great to remove escape codes only when printing to non-tty, but considering it further, now I feel this isn't really necessary given that JUnit XML output is not read by human but actually ingested by some other programs in 99.9% cases.
This PR strips ansi escape codes in the JUnit reporter.
Fixes #23316