Skip to content

tests: Add <live-region> placement tests #15

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

Merged
merged 3 commits into from
Apr 11, 2025

Conversation

smockle
Copy link
Contributor

@smockle smockle commented Apr 11, 2025

Fixes #14

This PR:

  1. Moves existing Guidepup tests to tests/guidepup and renames the associated npm run task to test:guidepup.
  2. Adds new Web Test Runner tests in tests/web-test-runner and an associated npm run task: test. These tests have about 88% coverage of ariaNotify-polyfill. They ensure the <live-region> custom element is placed inside <dialog> or [role="dialog"] elements (and <body> otherwise).
  3. Adds a “Test” workflow that runs the Web Test Runner tests in CI for PRs (example: https://github.com/github/ariaNotify-polyfill/actions/runs/14405607806/job/40401267225?pr=15). I added a branch policy to require this check.

I’ve tested this locally:

$ npm install --legacy-peer-deps
$ npm test

> @github/arianotify-polyfill@0.0.0-development test
> web-test-runner


Chrome: |██████████████████████████████| 3/3 test files | 3 passed, 0 failed

Code coverage: 88.48 %
View full coverage report at coverage/lcov-report/index.html

Finished running tests in 6.7s, all tests passed! 🎉

Note

The publish workflow calls npm test, which was previously a no-op, since Guidepup required NVDA or VoiceOver, which are not installed on Linux Actions runners. Now, npm test runs Web Test Runner tests, so this we’ll have extra confidence in future publishes!

Verified

This commit was signed with the committer’s verified signature.
smockle Clay Miller
@Copilot Copilot AI review requested due to automatic review settings April 11, 2025 13:52
@smockle smockle requested a review from a team as a code owner April 11, 2025 13:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds new end-to-end tests to verify that the is correctly placed in the DOM when used with dialog elements and, by default, within the body. It also organizes existing Guidepup tests under a dedicated folder and updates npm run tasks accordingly.

  • Introduces a new Web Test Runner configuration to dynamically include the ariaNotify-polyfill and run tests.
  • Adds three new test files to check the proper placement of the element in different DOM contexts.
  • Moves Guidepup tests and renames the associated task.

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
web-test-runner.config.js Configures polyfill injection and test runner setup.
tests/web-test-runner/live-region-placement-dialog.test.html Provides a test case for a element scenario.
tests/web-test-runner/live-region-placement-dialog-role.test.html Provides a test case for a role="dialog" scenario.
tests/web-test-runner/live-region-placement-body.test.html Provides a test case for a default placement within .
tests/web-test-runner/ariaNotify-polyfill.test.js Contains tests to validate the live-region placement behavior.
tests/web-test-runner/ariaNotify-polyfill.js Contains a reference to the polyfill file.
Files not reviewed (1)
  • package.json: Language not supported

@smockle smockle requested a review from khiga8 April 11, 2025 13:58
let count = 0;
for (const container of document.querySelectorAll("[data-should-contain-live-region]")) {
container.ariaNotify("Hello, world!");
const liveRegion = Array.from(container.childNodes).find((node) => node.nodeType === Node.ELEMENT_NODE && node.tagName.match(/^live-region/i));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something simpler, like liveRegion = container.querySelector("live-region"), wouldn’t work here, because the custom element’s tagName is appended with a random string (to prevent web authors from depending on its behavior, since it won’t exist in native ariaNotify implementations).

Verified

This commit was signed with the committer’s verified signature.
smockle Clay Miller

Verified

This commit was signed with the committer’s verified signature.
smockle Clay Miller
Copy link
Contributor

@khiga8 khiga8 left a comment

Choose a reason for hiding this comment

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

Looks great! 🙌 for more test coverage!

expect(liveRegion).to.not.be.undefined;
count++;
}
expect(count).to.be.above(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool assertion! .to.be.above

@@ -0,0 +1,20 @@
name: Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🎉

@smockle smockle merged commit 173af81 into main Apr 11, 2025
4 checks passed
@smockle smockle deleted the smockle/add-live-region-placement-tests branch April 11, 2025 15:40
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.

Add tests to ensure live region is added to dialog
2 participants