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!: async APIs #790

Merged
merged 8 commits into from
Nov 25, 2021
Merged

feat!: async APIs #790

merged 8 commits into from
Nov 25, 2021

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Nov 24, 2021

What:

Make all APIs asynchronous.
Restructure how we expose the APIs.

Why:

Closes #504

How:

  • Make all exported APIs return a Promise.
  • The APIs exposed per userEvent.anyApi() set up the effective APIs internally with the given options and then call it.
    This direct setup does not replace window.navigator.clipboard.
  • userEvent.setup sets up the effective APIs with the given options.
    This setup does replace window.navigator.clipboard. (We can make this optional).
  • Remove options that can be applied per setup from the APIs.
  • Moved code around to hopefully make it more obvious how the code is organized and where future fixes/features should live.
  • Wrap calls in asyncWrapper
  • Add comments on options

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

Next steps?

Callable default export

As we already move around a lot here:
Should we make the default export callable instead of adding setup to separate the special setup API from our functional APIs ?

const user = userEvent(/*...options...*/)
await user.anyAPI(/*...params...*/)

const sub = user(/*...additional options...*/) // share state and overwrite some options
await sub.anyAPI(/*...params...*/)

Making the default export callable does not result in a good developer experience as TS does not allow to remove the Function prototype methods/properties from the callable without reporting it as not-callable. So it's either a TS error or a polluted auto-complete.

Refactor tests

The tests have been roughly kept in place to make it easier to spot changes.
Files have been moved, modules have been rewritten and responsibilities have been shifted between parts of the codebase. Therefore a lot of tests are redundant. And some edge cases are covered by also testing for implementation details and noise. We have way to many snapshots and sometimes lack explicit assertions of the tested aspects.

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Nov 24, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 24, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d24ffee:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Nov 25, 2021

Codecov Report

Merging #790 (d24ffee) into alpha (b754dd4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             alpha      #790   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        76    +5     
  Lines         1603      1542   -61     
  Branches       602       575   -27     
=========================================
- Hits          1603      1542   -61     
Impacted Files Coverage Δ
src/pointer/pointerMove.ts 100.00% <ø> (ø)
src/pointer/pointerPress.ts 100.00% <ø> (ø)
src/clipboard/copy.ts 100.00% <100.00%> (ø)
src/clipboard/cut.ts 100.00% <100.00%> (ø)
src/clipboard/paste.ts 100.00% <100.00%> (ø)
src/convenience/click.ts 100.00% <100.00%> (ø)
src/convenience/hover.ts 100.00% <100.00%> (ø)
src/convenience/tab.ts 100.00% <100.00%> (ø)
src/keyboard/getNextKeyDef.ts 100.00% <100.00%> (ø)
src/keyboard/index.ts 100.00% <100.00%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b754dd4...d24ffee. Read the comment docs.

@ph-fritsche ph-fritsche marked this pull request as ready for review November 25, 2021 10:35
@ph-fritsche ph-fritsche mentioned this pull request Nov 25, 2021
3 tasks
@ph-fritsche ph-fritsche merged commit ca214d4 into alpha Nov 25, 2021
@ph-fritsche ph-fritsche deleted the feat-api branch November 25, 2021 11:41
@ph-fritsche ph-fritsche linked an issue Nov 25, 2021 that may be closed by this pull request
@github-actions
Copy link

🎉 This PR is included in version 14.0.0-alpha.15 🎉

The release is available on:

Your semantic-release bot 📦🚀

ph-fritsche added a commit that referenced this pull request Nov 28, 2021
BREAKING CHANGE: APIs always return a Promise.
andresmoschini added a commit to FromDoppler/doppler-editors-webapp that referenced this pull request Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-thinking approach to async event handling
1 participant