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

Adding _registerHook / _runHooks functionality allow adding work start/end of test helpers #878

Merged
merged 17 commits into from
Jun 10, 2020

Conversation

scalvert
Copy link
Contributor

@scalvert scalvert commented Jun 4, 2020

Description

Adds new hooks API, allowing external code to be 'hooked' into test helpers. This adds extensibility points that will allow consumers to define additional, custom behaviors to happen at specific points in the test invocation.

A good example of where this could be used is for accessibility testing - hooking into the visit:end to run audits without requiring audits be explicitly written into tests themselves.

Details

Adds the following public API:

function registerHook(helperName: string, hook: Function): HookUnregister

This allows registering a hook for a specific helper. Hooks can be registered to run at the start of the function, or the end.

Example:

Registering a fillIn hook to be run at the start of the visit invocation:

registerHook('fillIn:start', (target, test) => {
  // validate that target has a specific label
});

This also incorporates the previous log addition, which logs DOM elements, to use the new hooks API.

@scalvert scalvert force-pushed the register-hooks branch 2 times, most recently from 771e78e to 8db15fe Compare June 4, 2020 20:16
@scalvert scalvert marked this pull request as ready for review June 4, 2020 21:02
@scalvert scalvert requested a review from rwjblue June 4, 2020 21:02
@scalvert scalvert requested a review from rwjblue June 5, 2020 17:43
addon-test-support/@ember/test-helpers/index.ts Outdated Show resolved Hide resolved
tests/unit/dom/focus-test.js Outdated Show resolved Hide resolved
tests/unit/dom/helper-hooks-test.js Outdated Show resolved Hide resolved
tests/integration/dom/scroll-to-test.js Show resolved Hide resolved
tests/unit/dom/blur-test.js Outdated Show resolved Hide resolved
tests/unit/dom/click-test.js Outdated Show resolved Hide resolved
tests/unit/dom/double-click-test.js Outdated Show resolved Hide resolved
tests/unit/dom/fill-in-test.js Outdated Show resolved Hide resolved
tests/unit/dom/helper-hooks-test.js Outdated Show resolved Hide resolved
tests/unit/dom/helper-hooks-test.js Outdated Show resolved Hide resolved
tests/unit/dom/helper-hooks-test.js Outdated Show resolved Hide resolved
@scalvert scalvert requested a review from rwjblue June 8, 2020 20:09
@rwjblue rwjblue merged commit dd5fbb1 into emberjs:master Jun 10, 2020
@rwjblue rwjblue changed the title Adding hooks to allow adding work start/end of test helpers Adding _registerHook / _runHooks functionality allow adding work start/end of test helpers Jun 10, 2020
@fivetanley
Copy link
Member

This would be a very handy thing to have for our accessibility testing also (we're hoping to contribute some back to ember-a11y-testing but still learning a lot). Is there a path to this become a stable exported api? (I noticed the words "internal" and also exports with underscores so I assume I shouldn't use them, but I would love to be wrong)

@scalvert
Copy link
Contributor Author

@fivetanley this is actually precisely one of the use cases we're looking to support! The plan is definitely to have this be a publicly, supported API. We typically iterate on this type of API actively before we publish it for general consumption, as that helps validate our assumptions about the functionality.

Please let us know if there's anything you need from these APIs that we're missing.

@scalvert
Copy link
Contributor Author

@fivetanley this is a late follow-up, but not sure you've seen https://github.com/ember-a11y/ember-a11y-testing/blob/master/addon-test-support/setup-global-a11y-hooks.ts#L20, which is where this is used in ember-a11y-testing with the new global hooks functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants