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(vitest): strip ansi code from console output in junit reporter #5007

Closed
wants to merge 4 commits into from

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Jan 19, 2024

Description

I'm not sure the need of preserving color for this logging output, so I propose to always strip it for junit without configuration to toggle color. Please let me know if this makes sense.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jan 19, 2024

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 1cab176
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/65aa218c7f331e0008a41a66

@AriPerkkio
Copy link
Member

I remember adding this environment variable for reporters test case just because of this issue. Can we now remove it from here?

"test": "NO_COLOR=1 vitest run"

Comment on lines +50 to +52
const resultJson = parse(metaJson.replace(new RegExp(vitestRoot, 'g'), '<rootDir>'), (_key, value) => {
return typeof value === 'string' ? stripAnsi(value) : value
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO_COLOR was also affecting html reporter, so I stripped it just for this test case.

@hi-ogawa hi-ogawa marked this pull request as ready for review January 19, 2024 07:43
@sheremet-va
Copy link
Member

I am not sure why this is a problem. NO_COLOR disables this, right? What makes this reporter special that we always have to remove the colors?

@AriPerkkio
Copy link
Member

What makes this reporter special that we always have to remove the colors?

I think it makes sense for users to keep colors enabled for reporters that output on terminal on CI. But they would still like to generate other reports on file system and keep their content human-readable.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Jan 19, 2024

I think it makes sense for users to keep colors enabled for reporters that output on terminal on CI. But they would still like to generate other reports on file system and keep their content human-readable.

I haven't properly followed up with the issue author #4958 but I assumed that's the intention and made sense to me as a default junit reporter behavior. But, disabling entirely by NO_COLOR should be not a big deal and I totally get that applying stripAnsi here feels somewhat too artificial.
(for example, users might be intentionally doing console.log("\x1B[33m hi \x1B[39m") in the user code and expect it to appear in junit xml)

@sheremet-va
Copy link
Member

I think it makes sense for users to keep colors enabled for reporters that output on terminal on CI. But they would still like to generate other reports on file system and keep their content human-readable.

It just looks too irreversible to me. As @hi-ogawa, what if the color is expected? I think we can add an option to toggle this. We can even disable colors by default if you think it is a better experience for most people.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Jan 19, 2024

Thanks for the discussion. Yeah, I'll re-consider this change. Also, it's better to wait for the issue author's response to know the actual experience with current junit output and measure the significance of the issue. I will put this back to draft for now.

@hi-ogawa hi-ogawa marked this pull request as draft January 19, 2024 10:33
@AriPerkkio
Copy link
Member

Another approach for this would be support for reporter options. I would imagine something like:

{
  test: {
    reporters: ["verbose", ["junit", { color: false }], "html"],
  },
}

This was mentioned here #3691 (comment) but no actions were taken. This would also benefit third party reporters.

@sheremet-va
Copy link
Member

Another approach for this would be support for reporter options

I think that would be nice to support but we didn't create an issue yet, true.

@hi-ogawa hi-ogawa mentioned this pull request Jan 25, 2024
4 tasks
@hi-ogawa
Copy link
Contributor Author

That sounds good to me. I created an issue here #5042

@AriPerkkio
Copy link
Member

Now that #5042 is finished, the JUnit reporter accepts some reporter options:

export interface JUnitOptions {
outputFile?: string
classname?: string
suiteName?: string
}

Maybe a new option should be introduced there, color?: boolean that defaults to true. Then user's could disable it like shown in #5007 (comment).

@hi-ogawa
Copy link
Contributor Author

@AriPerkkio Thanks for the ping. For this junit issue, I'm becoming less convinced about this feature, so I'll close this for now. I think we can reconsider this if we get more reports.

@hi-ogawa hi-ogawa closed this Feb 12, 2024
@hi-ogawa hi-ogawa deleted the fix-junit-strip-ansi branch February 12, 2024 03:12
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.

JUnit reporter sometimes adds ansi colors to the report
3 participants