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

Addon-Interactions: Use ansi-to-html for colored test errors #29110

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Sep 12, 2024

Closes #

What I did

Use ansi-to-html for colored test errors

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.3 MB 77.3 MB 150 B 0.95 0%
initSize 162 MB 162 MB 55.6 kB 1.14 0%
diffSize 84.9 MB 85 MB 55.5 kB 1.27 0.1%
buildSize 7.53 MB 7.58 MB 49.3 kB 3.78 0.7%
buildSbAddonsSize 1.62 MB 1.67 MB 49.3 kB 131.17 3%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.34 MB 2.34 MB 0 B 0.58 0%
buildSbPreviewSize 352 kB 352 kB 0 B 2 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.51 MB 4.55 MB 49.3 kB 4.21 1.1%
buildPreviewSize 3.02 MB 3.02 MB 9 B 1.85 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.1s 21.1s 14s 1.01 66.3%
generateTime 21.5s 21.5s -15ms 0.36 -0.1%
initTime 17.2s 18.1s 890ms 0.66 4.9%
buildTime 11.7s 13.3s 1.5s 0.59 11.3%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.5s 6.8s 333ms -0.09 4.9%
devManagerResponsive 4s 4.2s 165ms -0.31 3.9%
devManagerHeaderVisible 786ms 793ms 7ms -0.02 0.9%
devManagerIndexVisible 837ms 834ms -3ms 0 -0.4%
devStoryVisibleUncached 1.4s 1.3s -143ms -0.28 -10.9%
devStoryVisible 838ms 836ms -2ms 0.01 -0.2%
devAutodocsVisible 634ms 729ms 95ms 0.16 13%
devMDXVisible 663ms 669ms 6ms -0.34 0.9%
buildManagerHeaderVisible 645ms 690ms 45ms -0.39 6.5%
buildManagerIndexVisible 652ms 692ms 40ms -0.61 5.8%
buildStoryVisible 708ms 762ms 54ms -0.24 7.1%
buildAutodocsVisible 629ms 621ms -8ms -0.74 -1.3%
buildMDXVisible 608ms 599ms -9ms -0.89 -1.5%

Greptile Summary

This PR introduces ANSI to HTML conversion for colored test errors in the Storybook Interactions addon, enhancing the readability of error messages and test outputs.

  • Added 'ansi-to-html' as a development dependency in code/addons/interactions/package.json
  • Implemented useAnsiToHtmlFilter utility function in code/addons/interactions/src/utils.ts
  • Applied ANSI to HTML conversion in Interaction, InteractionsPanel, and MatcherResult components
  • Enhanced error message display by preserving original coloring in the Storybook UI
  • Potential security consideration: Use of dangerouslySetInnerHTML in MatcherResult.tsx

Copy link

nx-cloud bot commented Sep 12, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit e693dcd. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings

Comment on lines +137 to +140
<span
key={line + index}
dangerouslySetInnerHTML={{ __html: filter.toHtml(line) }}
></span>,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Using dangerouslySetInnerHTML could pose XSS risks. Ensure input is properly sanitized

Comment on lines +29 to +33
export function createAnsiToHtmlFilter(theme: StorybookTheme) {
return new Filter({
fg: theme.color.defaultText,
bg: theme.background.content,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Ensure this function is memoized if called frequently to avoid unnecessary Filter instance creation

Comment on lines +36 to +39
export function useAnsiToHtmlFilter() {
const theme = useTheme();
return createAnsiToHtmlFilter(theme);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider memoizing this hook to prevent unnecessary re-renders

@kasperpeulen kasperpeulen merged commit 1d27f37 into next Sep 13, 2024
56 checks passed
@kasperpeulen kasperpeulen deleted the kasper/fix-ansi-chars branch September 13, 2024 10:01
@github-actions github-actions bot mentioned this pull request Sep 13, 2024
21 tasks
@kasperpeulen kasperpeulen added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Sep 24, 2024
storybook-bot pushed a commit that referenced this pull request Sep 25, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
@github-actions github-actions bot mentioned this pull request Sep 25, 2024
4 tasks
storybook-bot pushed a commit that referenced this pull request Sep 25, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
storybook-bot pushed a commit that referenced this pull request Sep 26, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
storybook-bot pushed a commit that referenced this pull request Sep 26, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
storybook-bot pushed a commit that referenced this pull request Sep 27, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
storybook-bot pushed a commit that referenced this pull request Sep 27, 2024
Addon-Interactions: Use ansi-to-html for colored test errors
(cherry picked from commit 1d27f37)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant