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 CI step for storybook test runner #935

Open
wants to merge 25 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ jobs:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
zip: true
exitZeroOnChanges: true
onlyChanged: true
onlyChanged: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

@martha I am wondering about the choice to user storybook test runner on CI as opposed to running tests via Chromatic on CI. The storybook gives the example that you might want to "Use [test runner] locally and Chromatic on your CI". I would guess that a benefit of Chromatic would be if the tests fail, maybe you can see some more detailed output on chromatic as opposed to just test logs. (Judging from chromatic docs about PR workflow it seems pretty advanced).

Linking https://github.com/open-path/Green-River/issues/6687 for reference too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I didn't read all the way through your description 🙈

I believe, alternatively, it's possible to run tests in CI against a Chromatic instance (see this other recipe), but based on the existing "Run Chromatic" build step, it looks like we only want to run chromatic on push to a release branch and not on pull request.

That was set up mostly for the purpose of publishing the "release version" of the storybook. I don't have anything against using chromatic to run testing on PRs. (And I guess publishing, maybe that's the norm for chromatic usage).

Copy link
Contributor Author

@martha martha Oct 8, 2024

Choose a reason for hiding this comment

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

Sounds good, I updated the PR to run the tests against the Chromatic instance of Storybook.

We do still need the test runner to run the accessibility tests. Chromatic supports running interaction tests, but doesn't support a11y tests as far as I can tell. You can see this in the example build here. The test runner step shows a11y failures, but the Chromatic step succeeds. In the corresponding Chromatic build for that action, there are 51 "unreviewed changes" (bc I had temporarily turned on the "visual tests" setting) but there are no a11y-related failures or warnings.

- name: Storybook test
run: |
npx playwright install --with-deps
yarn build-storybook --quiet
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server storybook-static --port 6006 --silent" \
"npx wait-on tcp:127.0.0.1:6006 && yarn test-storybook"
26 changes: 26 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// COMMENTED OUT for now until we want to actually turn on accessibility tests on CI
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do the tests pass for you locally? test-storybook passed for me (which I was surprised by, if it included accessibility tests?) but I'm not 100% confident that I resolved the merge conflicts correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can see the accessibility failures both locally and on CI by uncommenting the contents of this file. See this build, for example.

Do you want to actually turn this on now and make all our CI tests fail until we fix the a11y issues? I had assumed not yet...

But maybe it would be a good idea to turn it on and factor it out into a separate build step, that way when it fails we can immediately recognize the failure is expected, instead of clicking into the gh action log to make sure it's failing on the expected step?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh okay I wasn't seeing them locally, but I'll try again. No I agree, lets not intentionally have CI fail.

// See docs for more details including story- and component-level configuration:
// https://storybook.js.org/docs/writing-tests/accessibility-testing#automate-accessibility-tests-with-test-runner

// import type { TestRunnerConfig } from '@storybook/test-runner';
// import { injectAxe, checkA11y } from 'axe-playwright';
//
// /*
// * See https://storybook.js.org/docs/writing-tests/test-runner#test-hook-api
// * to learn more about the test-runner hooks API.
// */
// const config: TestRunnerConfig = {
// async preVisit(page) {
// await injectAxe(page);
// },
// async postVisit(page) {
// await checkA11y(page, '#storybook-root', {
// detailedReport: true,
// detailedReportOptions: {
// html: true,
// },
// });
// },
// };
//
// export default config;
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"postinstall": "husky install",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test-storybook": "test-storybook",
"graphql:codegen": "graphql-codegen --config codegen.yml && node scripts/generateEnumDescriptions.js && prettier --write ./src/types/* graphql.schema.json"
},
"lint-staged": {
Expand Down Expand Up @@ -125,11 +126,14 @@
"@storybook/react": "^8.2.9",
"@storybook/react-vite": "^8.2.9",
"@storybook/test": "^8.2.9",
"@storybook/test-runner": "^0.19.1",
"@types/lodash-es": "^4.17.12",
"@types/rails__activestorage": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"axe-playwright": "^2.0.2",
"chromatic": "^11.10.2",
"concurrently": "^9.0.1",
"cross-env": "^7.0.3",
"eslint": "^8.46.0",
"eslint-config-airbnb": "^19.0.4",
Expand All @@ -141,6 +145,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-vitest": "^0.4.1",
"http-server": "^14.1.1",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"lint-staged": "^12.4.1",
Expand All @@ -149,6 +154,7 @@
"storybook": "^8.2.9",
"storybook-addon-apollo-client": "^7.3.0",
"ts-node": "^10.9.2",
"vite-plugin-mkcert": "^1.17.6"
"vite-plugin-mkcert": "^1.17.6",
"wait-on": "^8.0.1"
}
}
Loading
Loading