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

Add WCAG PR check #274

Merged
merged 39 commits into from Aug 5, 2022
Merged

Add WCAG PR check #274

merged 39 commits into from Aug 5, 2022

Conversation

nmanu1
Copy link
Collaborator

@nmanu1 nmanu1 commented Aug 2, 2022

Add a GH workflow to check for WCAG violations. If the check fails, the PR will be blocked from merging into main. There are some WCAG violations that we ignore, namely color contrast failures on stories where components are in a "loading" state. Using config options, that rule is disabled for those particular stories. To get the automated WCAG checks, Storybook has to be running while the npm run wcag command is run.

Note, Jest had to be downgraded to v27 to work with @storybook/test-runner. But, it looks like they will be adding support for v28 shortly (storybookjs/test-runner#154), so we should be able to upgrade again soon. In the meantime, we haven't been using any features from v28, so the downgrade didn't affect any tests.

Also, the Snyk checks are failing, but the new license and one of new vulnerabilities are both approved by legal in Juliann's PR. The other new vulnerability is also introduced only through Storybook, so we wouldn't be susceptible to it.

J=SLAP-2289
TEST=auto

See that the check runs as expected on this PR and passes.

@coveralls
Copy link

coveralls commented Aug 2, 2022

Coverage Status

Coverage remained the same at 85.126% when pulling 8e581aa on dev/wcag-pr-check into f3c4ad0 on main.

@nmanu1 nmanu1 marked this pull request as ready for review August 3, 2022 00:19
@nmanu1 nmanu1 requested a review from a team as a code owner August 3, 2022 00:19
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
build_script: 'npm run storybook & sleep 10 && curl http://localhost:6006 -I'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure you looked into this but can we avoid the sleep 10? Maybe some option in start-storybook?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I tried finding a way to not use sleep and checked again in the start-storybook options. The closest option to what we want is --smoke-test, but that stops serving the site once it successfully starts. We need the site to be running when the test-storybook command is run. The only other way I saw to do this as part of a GH workflow was either to host the site somewhere public, or involved setting up service containers. Service containers seemed like they might be overkill, but I can look into it more

Copy link
Contributor

Choose a reason for hiding this comment

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

is something like this possible? I don't have any experience trying stuff like this https://stackoverflow.com/questions/21475639/wait-until-service-starts-in-bash-script

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure! I updated it to be a while loop instead so it keeps checking every second, instead of having an arbitrary sleep time of 10 seconds

Copy link
Contributor

@oshi97 oshi97 Aug 4, 2022

Choose a reason for hiding this comment

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

nice! this is very cool

@nmanu1 nmanu1 requested a review from oshi97 August 3, 2022 20:01
@nmanu1 nmanu1 requested a review from oshi97 August 4, 2022 18:05
nmanu1 pushed a commit that referenced this pull request Aug 4, 2022
Use storybook test-runner and `@storybook/addon-coverage` to get visual coverage report. The setup requires spinning up storybook before generating the coverage numbers. Now, we have three test scripts:
- test => combined test coverage
- test:unit => jest test coverage only
- test:visual => story book coverage only (note: this only collect coverage on src/components)

Updated coverage github action to also create/update comment which display code coverage percentage for unit, visual, and combined tests

the test-runner only works with jest v27 right now. As nidhi noted in her [pr](#274), storybook will be adding support for v28 shortly (storybookjs/test-runner#154).

[playwright](https://www.npmjs.com/package/playwright) library is needed in the github action for test-storybook.
<img width="600" alt="Screen Shot 2022-08-03 at 4 51 03 PM" src="https://user-images.githubusercontent.com/36055303/182709211-0189bad6-e978-4f82-9ee4-ba62be350283.png">

NOTE: The report generated from `nyc` merge command may not be super accurate after some comparison between to the unit vs visual vs merge report (ex: [github issue](istanbuljs/nyc#1302)).

J=SLAP-2269 & SLAP-2270
TEST=manual&auto

- See that running `npm run test:visual` generates lcov report in coverage/visual folder. And the report is printed out in terminal.
- See that a comment is made to the PR about the three coverage percentages.
- See that coverall percentage increase without changes to tests (increased due to combined test coverage)
.storybook/test-runner.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

Current unit coverage is 88.60759493670886%
Current visual coverage is 77.55331088664423%
Current combined coverage is 88.92405063291139%

.storybook/test-runner.ts Outdated Show resolved Hide resolved
@nmanu1 nmanu1 requested review from yen-tt and oshi97 and removed request for oshi97 August 4, 2022 21:11
@nmanu1 nmanu1 requested a review from oshi97 August 5, 2022 13:46
@nmanu1 nmanu1 merged commit d734620 into main Aug 5, 2022
@nmanu1 nmanu1 deleted the dev/wcag-pr-check branch August 5, 2022 14:25
yen-tt added a commit that referenced this pull request Sep 28, 2022
Use storybook test-runner and `@storybook/addon-coverage` to get visual coverage report. The setup requires spinning up storybook before generating the coverage numbers. Now, we have three test scripts:
- test => combined test coverage
- test:unit => jest test coverage only
- test:visual => story book coverage only (note: this only collect coverage on src/components)

Updated coverage github action to also create/update comment which display code coverage percentage for unit, visual, and combined tests

the test-runner only works with jest v27 right now. As nidhi noted in her [pr](#274), storybook will be adding support for v28 shortly (storybookjs/test-runner#154).

[playwright](https://www.npmjs.com/package/playwright) library is needed in the github action for test-storybook.
<img width="600" alt="Screen Shot 2022-08-03 at 4 51 03 PM" src="https://user-images.githubusercontent.com/36055303/182709211-0189bad6-e978-4f82-9ee4-ba62be350283.png">

NOTE: The report generated from `nyc` merge command may not be super accurate after some comparison between to the unit vs visual vs merge report (ex: [github issue](istanbuljs/nyc#1302)).

J=SLAP-2269 & SLAP-2270
TEST=manual&auto

- See that running `npm run test:visual` generates lcov report in coverage/visual folder. And the report is printed out in terminal.
- See that a comment is made to the PR about the three coverage percentages.
- See that coverall percentage increase without changes to tests (increased due to combined test coverage)
yen-tt pushed a commit that referenced this pull request Sep 28, 2022
Add a GH workflow to check for WCAG violations. If the check fails, the PR will be blocked from merging into main. There are some WCAG violations that we ignore, namely color contrast failures on stories where components are in a "loading" state. Using config options, that rule is disabled for those particular stories. To get the automated WCAG checks, Storybook has to be running while the `npm run wcag` command is run.

Note, Jest had to be downgraded to v27 to work with `@storybook/test-runner`. But, it looks like they will be adding support for v28 shortly (storybookjs/test-runner#154), so we should be able to upgrade again soon. In the meantime, we haven't been using any features from v28, so the downgrade didn't affect any tests.

Also, the Snyk checks are failing, but the new license and one of new vulnerabilities are both approved by legal in Juliann's [PR](#264 (comment)). The other new vulnerability is also introduced only through Storybook, so we wouldn't be susceptible to it.

J=SLAP-2289
TEST=auto

See that the check runs as expected on this PR and passes.
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.

None yet

5 participants