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

ci: minimum working example for jest-axe accessibility CI #412

Merged
merged 5 commits into from
Jan 31, 2022

Conversation

mattxwang
Copy link
Member

@mattxwang mattxwang commented Jan 28, 2022

This PR implements the minimum overhead required to run jest-axe via GitHub Actions on a set of predefined components. In order, we:

  1. install jest, jest-axe, @testing-library/react, @testing-library/jest-dom, the minimum set up for a viable test infrastructure
    1. to install jest, we add a general jest.config.js as a jest configuration file, and jest.setup.js as a pre-test setup file (automatically importing our dependencies)
    2. creates a set of mock module mappers for "non-code" webpack elements; a stub file mock (__mocks__/fileMock.js) for most files, and the identity-obj-proxy to proxy-back CSS/SASS/SCSS class names
    3. adds the next preset to babel
    4. adjusts the ESLint config to use the jest environment
  2. implements a rudimentary accessibility test in NewsArticle.test.js, which is a simple subcomponent with no errors. You can validate this working by adding an arbitrary <img /> to NewsArticle.js; npm test will throw an error.
  3. implements a rudimentary failing accessibility test in Footer.test.js, where an <ul> has children that are not <li> - showing that negatives work. I then resolve this issue.
  4. updates the "Node.JS CI" action to be "Build and Test", and runs npm test in it

Ideally, you should be able to add more test files following the configuration in NewsArticle.test.js; note the strange let pattern with the async version of act.

I didn't use the native next testing plugin, since that seems blocked by the upgrade to Next 12 (#409).

Part of #218, supersedes #301.

Relevant reading:

@mattxwang
Copy link
Member Author

Note that I've introduced a failing test for footer in 03bebdc, and then resolved it in 9a90696 - indicating that the test pattern works.

@mattxwang mattxwang requested a review from a team January 28, 2022 01:53
@mattxwang mattxwang mentioned this pull request Jan 28, 2022
Copy link
Contributor

@advaithg advaithg left a comment

Choose a reason for hiding this comment

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

Looks good!

@mattxwang mattxwang merged commit ba8a649 into main Jan 31, 2022
@mattxwang mattxwang deleted the automated-accessibility-jest-axe branch January 31, 2022 08:44
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.

2 participants