-
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(jest): add custom results processor for a11y failures #62
feat(jest): add custom results processor for a11y failures #62
Conversation
add jest/circus as test runner due to jestjs/jest#11405
Codecov Report
@@ Coverage Diff @@
## master #62 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 19 +1
Lines 208 234 +26
Branches 27 31 +4
=========================================
+ Hits 208 234 +26
|
937720b
to
57fa2be
Compare
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.
Overall looks good. Couple questions.
* Modify existing test suites, test results containing a11y errors after a11y errors | ||
* are extracted out into their own test suites and results. | ||
*/ | ||
function modifyTestSuiteResults(results: AggregatedResult, testSuite: TestResult, testResult: AssertionResult) { |
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.
I don't really understand what the purpose of this function is. Can you explain more?
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.
Since the custom reporter is transforming the a11y errors into their own test failures contained within a new suite based on the a11y rule (const suiteKey = [Sa11y ${a11yResult.wcag} ${a11yResult.id} ${suiteName}]
), the original test in which the a11y error occurred is being disabled and test failure counts adjusted accordingly. Guess if the main logic is refactored to use map/filter without using any intermediates, it might be possible to just filter these out instead of disabling (the test counts will still need to be adjusted I think).
I have updated the PR desc to include docs/screenshots to illustrate this. Please check them out and let me know if it makes sense and if we can include them as part of jest README.
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.
Ok. I just want to make sure we don't mess up the overall test and failure counts. E.g., If we have a functional failure and then that is fixed but replaced by an a11y failure, then the total tests and failure counts should remain the same.
It sounds like you're accounting for that. Just wanted to make sure.
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.
That is a good point. The failure count and the total test count could increase with the sa11y results processor - because each a11y failure from a test would be extracted to be its own test failure. When there is only 1 a11y failure in a test, the count would stay the same. But when there are multiple unique a11y failures in a test, the count could increase. But the results processor doesn't affect default console reporter or other reporters - it affects just the JSON output. Added a limitations section to the doc to reflect this and other points - can you please review.
Also created #66 as it is important and deserves its own issue.
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 👍
I have addressed/responded to your comments. Please take a look.
* Modify existing test suites, test results containing a11y errors after a11y errors | ||
* are extracted out into their own test suites and results. | ||
*/ | ||
function modifyTestSuiteResults(results: AggregatedResult, testSuite: TestResult, testResult: AssertionResult) { |
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.
Since the custom reporter is transforming the a11y errors into their own test failures contained within a new suite based on the a11y rule (const suiteKey = [Sa11y ${a11yResult.wcag} ${a11yResult.id} ${suiteName}]
), the original test in which the a11y error occurred is being disabled and test failure counts adjusted accordingly. Guess if the main logic is refactored to use map/filter without using any intermediates, it might be possible to just filter these out instead of disabling (the test counts will still need to be adjusted I think).
I have updated the PR desc to include docs/screenshots to illustrate this. Please check them out and let me know if it makes sense and if we can include them as part of jest README.
packages/jest/README.md
Outdated
- Automatic check is triggered regardless of the test status which would result in the original test failure if any getting overwritten by a11y failures if any from automatic checks ([#66](https://github.com/salesforce/sa11y/issues/66)) | ||
- Tests using the sa11y jest api would get tested twice with automatic checks - once as part of the sa11y API in the test and again as part of the automatic check | ||
- a11y issues from automatic checks would overwrite the a11y issues found by the API | ||
- If the sa11y API has been added to the test to check specific intermediate states of the DOM, enabling automatic checks could result in missed a11y issues |
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.
I think this point is also covered by the next one below.
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.
Yes it is related, but there is also a fine difference - Enabling automatic checks without using the API vs while also using the API. Please check if the rewording now makes sense.
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.
I guess to me since you say the automatic check is only at the end of the test it was clear to me that checking intermediate states of the DOM, whether you called the API or not, would not be caught. I'm fine to keep it worded like this though if you think it's more clear.
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 Trevor. I will try to revisit and reword/remove it in a subsequent PR.
packages/jest/README.md
Outdated
- Workaround: Remove the DOM cleanup code from the test and opt-in to using sa11y to clean-up the DOM using the options as described above (`cleanupAfterEach: true` or `SA11Y_CLEANUP=1`) | ||
- With the sa11y results processor | ||
- Though the originating test from which the a11y failures are extracted is disabled, and test counts adjusted accordingly - the original test suite failure message still contains the a11y failures. | ||
- The test suite failure message is typically not displayed or used in testing workflows. But if your testing workflow uses the test suite failure message, this might cause confusion. |
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.
The double indentation here feels a little confusing to me. Can we combine these 3 bullets into a single bullet and a couple sentences maybe?
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.
Agree, modified - please take a look.
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.
@trevor-bliss modified the docs (and also did some last bits of cleanup/refactoring). Can you please take a look.
packages/jest/README.md
Outdated
- Automatic check is triggered regardless of the test status which would result in the original test failure if any getting overwritten by a11y failures if any from automatic checks ([#66](https://github.com/salesforce/sa11y/issues/66)) | ||
- Tests using the sa11y jest api would get tested twice with automatic checks - once as part of the sa11y API in the test and again as part of the automatic check | ||
- a11y issues from automatic checks would overwrite the a11y issues found by the API | ||
- If the sa11y API has been added to the test to check specific intermediate states of the DOM, enabling automatic checks could result in missed a11y issues |
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.
Yes it is related, but there is also a fine difference - Enabling automatic checks without using the API vs while also using the API. Please check if the rewording now makes sense.
packages/jest/README.md
Outdated
- Workaround: Remove the DOM cleanup code from the test and opt-in to using sa11y to clean-up the DOM using the options as described above (`cleanupAfterEach: true` or `SA11Y_CLEANUP=1`) | ||
- With the sa11y results processor | ||
- Though the originating test from which the a11y failures are extracted is disabled, and test counts adjusted accordingly - the original test suite failure message still contains the a11y failures. | ||
- The test suite failure message is typically not displayed or used in testing workflows. But if your testing workflow uses the test suite failure message, this might cause confusion. |
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.
Agree, modified - please take a look.
Features ✨
Jest automatic checks 🤖
Results
Before - with default results processor (a11y error is embedded within the test failure)
JSON result:
After - with new sa11y results processor added in this PR (and automatic checks)
Original JSON test result (failure with embedded a11y error) is now disabled
New JSON test result created to represent the a11y failure bringing a11y metadata to forefront
TODO
/* istanbul ignore next */
) as much as possible esp the non-edge cases