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

feat(assert): add assert accessible api #7

Merged
merged 41 commits into from
Apr 8, 2020

Conversation

mohanraj-r
Copy link
Contributor

@mohanraj-r mohanraj-r commented Mar 31, 2020

  • assert: add assert package with assertAccessible API (0726678)
    • This would be paired with a jest matcher (TBD)
  • format: add basic a11y results format package (b28dc2a)
    • This would be fleshed out in a future PR
  • rules: fix import paths of modules in rules package (fc54a76)

@mohanraj-r mohanraj-r marked this pull request as ready for review April 1, 2020 00:07
@mohanraj-r mohanraj-r requested a review from a team April 1, 2020 00:07
@mohanraj-r mohanraj-r self-assigned this Apr 1, 2020
@mohanraj-r mohanraj-r changed the title Feat/add assert accessible api feat(assert): add assert accessible api Apr 1, 2020
// TODO: Rename getA11yConfig() to getA11yConfig
const errConfig = getA11yConfig(['non-existent-rule']);
await assertAccessible(document, errConfig).catch((e) => {
expect(e).toBeDefined();

Choose a reason for hiding this comment

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

If assertAccessible does not throw an error to enter the catch block the test will still pass.

There are many ways to solve this. One simple way is to declare the number of assertions you expect in each test case to guarantee they are run: https://jestjs.io/docs/en/expect#expectassertionsnumber

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I was wondering about this too .. Fixed in all tests now.
Fixed the names too. Thanks for the tip 👍

</script>
</body>
</html>`;
await assertAccessible(document, jsdomRules).catch((error) => expect(error).toBeUndefined());

Choose a reason for hiding this comment

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

This flow feels weird to me. To me it would make more sense to not have the catch block and let the error thrown bubble up and fail the test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Fixed.

</body>
</html>`;
await assertAccessible(document, jsdomRules).catch((e) => {
expect(e).toBeDefined();

Choose a reason for hiding this comment

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

Same issue as above. You should guarantee these assertions are actually run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -62,7 +69,8 @@
"jest": "^25.1.0",
"lerna": "^3.20.2",
"lint-staged": "^10.0.8",
"prettier": "1.19.1",
"lockfile-lint": "^4.2.2",

Choose a reason for hiding this comment

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

Nice. I didn't know this existed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yes this is helpful esp since yarn doesn't seem to respect project npmrc when installing deps in packages (yarnpkg/yarn#4458)

Btw looking for a tool that can help ensure the same version of dependency is used across all the packages in the project (something like https://www.npmjs.com/package/syncpack). If you have any recommendations, please let me know.

});
});

it('dom with no a11y issues', async () => {

Choose a reason for hiding this comment

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

These test names should be more explicit. These are JUnit style names 😛. Something like "does not throw error when no a11y issues in DOM" would be better. Then when you read the describe + it block it fully describes what exactly you are testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense 👍 Updated.

await assertAccessible(document, jsdomRules).catch((error) => expect(error).toBeUndefined());
});

it('dom with a11y issues', async () => {

Choose a reason for hiding this comment

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

Better name as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

@mohanraj-r mohanraj-r left a comment

Choose a reason for hiding this comment

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

Thanks for the review @trevor-bliss ! Appreciate the comments.
Took care of them. Please review.

@@ -62,7 +69,8 @@
"jest": "^25.1.0",
"lerna": "^3.20.2",
"lint-staged": "^10.0.8",
"prettier": "1.19.1",
"lockfile-lint": "^4.2.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yes this is helpful esp since yarn doesn't seem to respect project npmrc when installing deps in packages (yarnpkg/yarn#4458)

Btw looking for a tool that can help ensure the same version of dependency is used across all the packages in the project (something like https://www.npmjs.com/package/syncpack). If you have any recommendations, please let me know.

// TODO: Rename getA11yConfig() to getA11yConfig
const errConfig = getA11yConfig(['non-existent-rule']);
await assertAccessible(document, errConfig).catch((e) => {
expect(e).toBeDefined();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I was wondering about this too .. Fixed in all tests now.
Fixed the names too. Thanks for the tip 👍

trevor-bliss
trevor-bliss previously approved these changes Apr 3, 2020
* @param formatter - Function to format a11y violations
* @throws error - with the accessibility issues found
* */
export async function assertAccessible(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @cordeliadillon Can you please review the assert API. I would like to merge this by EOD tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at it now! Thanks for the nudge. :)

import { assertAccessible } from '@sa11y/assert';

// Setup DOM ..
await assertAccessible();
Copy link
Contributor

Choose a reason for hiding this comment

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

Who's the audience for this readme file? Should this have more detail around assertAccessible's params, what types of errors it throws, and how it can be used in context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, Updated readme.
Added a TODO to look into generating usage docs from the code comments - as right now its duplicating doc from code and it needs to be kept in sync with code etc.

* @param violations - Result list from axe
* */
// TODO: Add handlebars template for formatting
// TODO: Add support for different output formats console(colored), plain text, HTML, xUnit
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -8,9 +8,9 @@
import { RunOptions } from 'axe-core';

/**
* AxeConfig is limited to subset of options that we need and use in this library
* A11yConfig contains options to trigger a accessibility run, specifying list of rules to test
Copy link
Contributor

Choose a reason for hiding this comment

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

"trigger a accessibility run" seems vague. By "accessibility run," do you mean "run of AXE accessibility checks"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated doc.

@github-actions
Copy link

github-actions bot commented Apr 3, 2020

Total Coverage: 100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   recommended.ts100%100%100%

@mohanraj-r
Copy link
Contributor Author

Looks like the CI setup has some issues. Debugging it now. Will post here once it is fixed.

All CI issues are fixed now.
@cordeliadillon Can you please review and approve.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Coverage after merging feat/add_assert_accessible_api into master

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   index.ts100%100%100%
   recommended.ts100%100%100%

Fix changelog script to append rather then regen
@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Coverage after merging feat/add_assert_accessible_api into master

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   index.ts100%100%100%
   recommended.ts100%100%100%

@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Coverage after merging feat/add_assert_accessible_api into master

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   index.ts100%100%100%
   recommended.ts100%100%100%

@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Coverage after merging feat/add_assert_accessible_api into master

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   index.ts100%100%100%
   recommended.ts100%100%100%

to include bug fixes, vulnerability fixes in recent releases
@github-actions
Copy link

github-actions bot commented Apr 7, 2020

Coverage after merging feat/add_assert_accessible_api into master

100.00%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
packages/assert/src
   assert.ts100%100%100%
packages/format/src
   format.ts100%100%100%
packages/preset-rules/src
   a11yConfig.ts100%100%100%
   extended.ts100%100%100%
   index.ts100%100%100%
   recommended.ts100%100%100%

Copy link
Contributor

@cordeliadillon cordeliadillon left a comment

Choose a reason for hiding this comment

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

👍

@mohanraj-r mohanraj-r merged commit 1294f76 into master Apr 8, 2020
@mohanraj-r mohanraj-r deleted the feat/add_assert_accessible_api branch April 8, 2020 21:15
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.

3 participants