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

A11y: Create a11y test provider and revamp a11y addon #29643

Draft
wants to merge 38 commits into
base: next
Choose a base branch
from

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Nov 18, 2024

Closes #

What I did

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-storybook/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 78.4 MB 78.4 MB 0 B -0.19 0%
initSize 144 MB 144 MB -1.46 kB -0.35 0%
diffSize 65.1 MB 65.1 MB -1.46 kB -0.3 0%
buildSize 6.83 MB 6.84 MB 4.26 kB -0.47 0.1%
buildSbAddonsSize 1.51 MB 1.51 MB 1.95 kB Infinity 0.1%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.86 MB 1.86 MB 332 B -0.56 0%
buildSbPreviewSize 271 kB 272 kB 1.56 kB Infinity 0.6%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.83 MB 3.84 MB 3.84 kB -0.48 0.1%
buildPreviewSize 3 MB 3 MB 413 B 0.77 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 18.6s 13.4s -5s -161ms -0.77 -38.4%
generateTime 19.7s 20.4s 676ms -0.31 3.3%
initTime 13.5s 14.9s 1.4s -0.02 9.5%
buildTime 9.4s 8.4s -995ms -0.48 -11.8%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 4.8s 5.6s 846ms -0.28 14.9%
devManagerResponsive 3s 3.5s 432ms -0.34 12.3%
devManagerHeaderVisible 475ms 536ms 61ms -0.53 11.4%
devManagerIndexVisible 557ms 570ms 13ms -1.06 2.3%
devStoryVisibleUncached 968ms 1.1s 198ms 0.54 17%
devStoryVisible 504ms 568ms 64ms -0.83 11.3%
devAutodocsVisible 421ms 403ms -18ms -1.66 -4.5%
devMDXVisible 503ms 476ms -27ms -0.62 -5.7%
buildManagerHeaderVisible 481ms 667ms 186ms 1.26 🔺27.9%
buildManagerIndexVisible 491ms 689ms 198ms 1.17 28.7%
buildStoryVisible 475ms 656ms 181ms 1.03 27.6%
buildAutodocsVisible 406ms 453ms 47ms -0.33 10.4%
buildMDXVisible 412ms 562ms 150ms 1.16 26.7%

Greptile Summary

Based on the provided files and changes, here's a concise summary of the pull request:

Comprehensive revamp of Storybook's accessibility (a11y) addon with a new test provider and reporting system, focusing on improved test lifecycle management and result reporting.

Key changes:

  • Added new ReporterAPI and test lifecycle hooks for standardized accessibility test reporting
  • Simplified a11yRunner by removing state management and focusing on core axe-core functionality
  • Migrated A11YPanel state management to context-based approach with A11yContext
  • Added new STORY_FINISHED event and phases for proper test completion handling
  • Introduced afterEach hooks throughout the testing pipeline for proper cleanup

The changes appear well-structured but there are potential concerns around error handling and hook execution order that should be reviewed carefully.

Copy link

nx-cloud bot commented Nov 18, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5d084d4. 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.

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Nov 18, 2024

Package Benchmarks

Commit: 5d084d4, ran on 23 November 2024 at 06:21:04 UTC

The following packages have significant changes to their size or dependencies:

@storybook/addon-a11y

Before After Difference
Dependency count 3 59 🚨 +56 🚨
Self size 44 KB 58 KB 🚨 +14 KB 🚨
Dependency size 2.80 MB 13.16 MB 🚨 +10.35 MB 🚨
Bundle Size Analyzer Link Link

@storybook/addon-docs

Before After Difference
Dependency count 17 17 0
Self size 2.20 MB 2.20 MB 🚨 +5 B 🚨
Dependency size 7.88 MB 7.87 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-essentials

Before After Difference
Dependency count 36 36 0
Self size 17 KB 17 KB 🚨 +11 B 🚨
Dependency size 13.83 MB 13.82 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-interactions

Before After Difference
Dependency count 56 56 0
Self size 129 KB 129 KB 🚨 +4 B 🚨
Dependency size 12.44 MB 12.43 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-links

Before After Difference
Dependency count 4 4 0
Self size 19 KB 19 KB 🚨 +23 B 🚨
Dependency size 283 KB 272 KB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-storysource

Before After Difference
Dependency count 7 7 0
Self size 1.89 MB 1.89 MB 🚨 +3 B 🚨
Dependency size 10.12 MB 10.11 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/experimental-addon-test

Before After Difference
Dependency count 61 61 0
Self size 605 KB 605 KB 🚨 +252 B 🚨
Dependency size 13.86 MB 13.85 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/core

Before After Difference
Dependency count 46 46 0
Self size 19.04 MB 19.05 MB 🚨 +9 KB 🚨
Dependency size 14.29 MB 14.28 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/experimental-nextjs-vite

Before After Difference
Dependency count 87 87 0
Self size 231 KB 231 KB 🚨 +6 B 🚨
Dependency size 31.30 MB 31.29 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 587 587 0
Self size 464 KB 464 KB 🚨 +6 B 🚨
Dependency size 83.77 MB 83.76 MB 🎉 -10 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 241 241 0
Self size 14 KB 14 KB 🚨 +5 B 🚨
Dependency size 31.08 MB 31.07 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/blocks

Before After Difference
Dependency count 4 4 0
Self size 604 KB 604 KB 🚨 +26 B 🚨
Dependency size 1.49 MB 1.48 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/source-loader

Before After Difference
Dependency count 5 5 0
Self size 41 KB 41 KB 🚨 +23 B 🚨
Dependency size 10.07 MB 10.06 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/test

Before After Difference
Dependency count 53 53 0
Self size 1.52 MB 1.53 MB 🚨 +835 B 🚨
Dependency size 8.09 MB 8.08 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/preset-server-webpack

Before After Difference
Dependency count 20 20 0
Self size 10 KB 10 KB 🚨 +4 B 🚨
Dependency size 3.84 MB 3.83 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server

Before After Difference
Dependency count 9 9 0
Self size 13 KB 13 KB 🚨 +27 B 🚨
Dependency size 972 KB 961 KB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

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.

46 file(s) reviewed, 34 comment(s)
Edit PR Review Bot Settings | Greptile

code/addons/a11y/src/a11yRunner.ts Show resolved Hide resolved
Comment on lines +20 to +22
if (!htmlElement) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Should emit an error event when htmlElement is not found rather than silently returning undefined

status: 'initial',
handleManual: vi.fn(),
error: null,
} as Partial<A11yContextStore> as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: avoid double type assertion - consider creating a proper mock object that satisfies A11yContextStore

Comment on lines +75 to +77
passes: [{ id: 'pass1' } as any],
incomplete: [{ id: 'incomplete1' } as any],
violations: [{ id: 'violation1', nodes: [] } as any],
Copy link
Contributor

Choose a reason for hiding this comment

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

style: test data should include all required properties of the Result type instead of using 'as any'

Comment on lines +66 to +68
expect(
component.getByText('Please wait while the accessibility scan is running ...')
).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: text string assertion is brittle due to trailing spaces - consider using a more flexible matcher

@@ -43,7 +43,7 @@
"prep": "jiti ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@storybook/csf": "^0.1.11",
"@storybook/csf": "0.1.12--canary.110.7611f0c.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Pinning to a canary version could cause issues if this package is used by projects that require a different CSF version. Consider using a stable version or maintaining the flexible range.

Comment on lines 15 to 25
await expect(mocked(console.log).mock.calls).toEqual([
['1 - [from loaders]'],
['2 - [from meta beforeEach]'],
['3 - [from story beforeEach]'],
['4 - [before mount]'],
['5 - [from decorator]'],
['6 - [after mount]'],
['7 - [from onClick]'],
['8 - [from story afterEach]'],
['9 - [from meta afterEach]'],
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The expected order of hooks seems incorrect. The decorator (5) is being called after the play function's 'before mount' (4), but decorators should wrap the entire story execution including the play function. This could lead to inconsistent behavior in real-world scenarios.

Comment on lines 6 to 7
spyOn(console, 'log').mockName('console.log');
console.log('1 - [from loaders]');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: The spyOn call is using mockName() but the name isn't being used in any assertions. Consider removing mockName() if not needed.

@@ -123,7 +123,7 @@
"@storybook/codemod": "workspace:*",
"@storybook/core": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/csf": "0.1.11",
"@storybook/csf": "0.1.12--canary.110.7611f0c.0",
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 a canary version (0.1.12--canary.110.7611f0c.0) in production could lead to instability. Consider using a stable release.

@@ -46,7 +46,7 @@
},
"dependencies": {
"@storybook/components": "workspace:*",
"@storybook/csf": "^0.1.11",
"@storybook/csf": "0.1.12--canary.110.7611f0c.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Using a canary version in production dependencies could cause instability. Consider waiting for a stable release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants