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 30 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.03 0%
initSize 144 MB 144 MB 8.54 kB -0.31 0%
diffSize 65.1 MB 65.1 MB 8.54 kB -0.67 0%
buildSize 6.83 MB 6.83 MB 3.84 kB -1.04 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 331 B -1.18 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 -1.09 0.1%
buildPreviewSize 3 MB 3 MB 0 B 0.96 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 24.3s 5.6s 0.97 23.2%
generateTime 21.8s 17.9s -3s -869ms -1.01 -21.5%
initTime 18.2s 13s -5s -218ms -1.15 -39.9%
buildTime 7.9s 8.2s 264ms -0.64 3.2%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.8s 6.1s 241ms 0.53 3.9%
devManagerResponsive 3.7s 3.8s 135ms 0.71 3.5%
devManagerHeaderVisible 637ms 554ms -83ms -0.15 -15%
devManagerIndexVisible 669ms 634ms -35ms -0.03 -5.5%
devStoryVisibleUncached 1.1s 910ms -245ms -0.51 -26.9%
devStoryVisible 668ms 631ms -37ms 0.09 -5.9%
devAutodocsVisible 477ms 543ms 66ms 0.74 12.2%
devMDXVisible 499ms 558ms 59ms 0.94 10.6%
buildManagerHeaderVisible 602ms 539ms -63ms -0.28 -11.7%
buildManagerIndexVisible 612ms 549ms -63ms -0.37 -11.5%
buildStoryVisible 603ms 529ms -74ms -0.4 -14%
buildAutodocsVisible 444ms 464ms 20ms -0.22 4.3%
buildMDXVisible 504ms 453ms -51ms 0.08 -11.3%

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 66931ce. 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: 66931ce, ran on 20 November 2024 at 13:31:23 UTC

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

@storybook/addon-a11y

Before After Difference
Dependency count 3 3 0
Self size 44 KB 55 KB 🚨 +10 KB 🚨
Dependency size 2.80 MB 2.80 MB 0 B
Bundle Size Analyzer Link Link

@storybook/addon-docs

Before After Difference
Dependency count 17 17 0
Self size 2.20 MB 2.20 MB 0 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 0 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 0 B
Dependency size 12.44 MB 12.43 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/addon-links

Before After Difference
Dependency count 4 4 0
Self size 19 KB 19 KB 🚨 +21 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 0 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 587 KB 588 KB 🚨 +201 B 🚨
Dependency size 13.86 MB 13.85 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/core

Before After Difference
Dependency count 46 46 0
Self size 19.04 MB 19.05 MB 🚨 +8 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 0 B
Dependency size 31.30 MB 31.29 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 587 587 0
Self size 464 KB 464 KB 0 B
Dependency size 83.68 MB 83.67 MB 🎉 -11 KB 🎉
Bundle Size Analyzer Link Link

@storybook/server-webpack5

Before After Difference
Dependency count 241 241 0
Self size 14 KB 14 KB 0 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 🚨 +21 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 🚨 +21 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.52 MB 🚨 +21 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 0 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 🚨 +21 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