-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
mohanraj-r
commented
Mar 31, 2020
•
edited
Loading
edited
- 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)
also update cspell ignored word list
tests now pass using the wrapper
to not expose implementation details unnecessarily
// TODO: Rename getA11yConfig() to getA11yConfig | ||
const errConfig = getA11yConfig(['non-existent-rule']); | ||
await assertAccessible(document, errConfig).catch((e) => { | ||
expect(e).toBeDefined(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better name as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
rename test names to be more descriptive
There was a problem hiding this 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", |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 👍
* @param formatter - Function to format a11y violations | ||
* @throws error - with the accessibility issues found | ||
* */ | ||
export async function assertAccessible( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, updated doc.
to check if that fixes the code cov action failure in CI
to a different fork: ziishaned/jest-reporter-action#3
due to issues with current code cov action
Total Coverage: 100.00% Coverage Report
|
All CI issues are fixed now. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Coverage after merging feat/add_assert_accessible_api into master
Coverage Report
|
Fix changelog script to append rather then regen
Coverage after merging feat/add_assert_accessible_api into master
Coverage Report
|
fix test snapshot caused by change in output: header -> heading; dequelabs/axe-core@8890063
Coverage after merging feat/add_assert_accessible_api into master
Coverage Report
|
and update packages
Coverage after merging feat/add_assert_accessible_api into master
Coverage Report
|
to include bug fixes, vulnerability fixes in recent releases
Coverage after merging feat/add_assert_accessible_api into master
Coverage Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍