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

fix(test): strip ansi colors in junit output #23371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marvinhagemeister
Copy link
Contributor

This PR strips ansi escape codes in the JUnit reporter.

Fixes #23316

Comment on lines +11 to +12
static ANSI_ESCAPE_REMOVE: Lazy<Regex> =
lazy_regex::lazy_regex!(r#"\x1b\[([\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])"#);
Copy link
Member

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...

Copy link
Member

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

Comment on lines +5 to +6
// deno-lint-ignore no-explicit-any
Deno.test("step fail color", async (t: any) => {
Copy link
Member

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?

Comment on lines +39 to +53
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![],
}
}
Copy link
Member

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.

@bartlomieju bartlomieju added this to the 1.44 milestone May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strip ANSI escape codes when writing test reports to non-tty
3 participants