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

docs: add query ByRole performance notes #1349

Merged
merged 1 commit into from
Jan 13, 2024

Conversation

agentdylan
Copy link
Contributor

@agentdylan agentdylan commented Dec 6, 2023

Adds notes about performance of *ByRole queries to the Queries > ByRole page.

getByRole and the likes are known to be slow at times and documentation has been requested123 to help make this more visible.

This has been known for several years1 and performance remains a concern4 so I believe it is worthwhile adding to the docs.

I think it's important to have a balance of conveying the importance of getByRole while still sharing this information about the performance so users can make an informed decision if performance is a problem.

This relates to issues

These issues have great discussion around this topic, which I've attempted to consolidate.

Footnotes

  1. https://github.com/testing-library/dom-testing-library/issues/820#issuecomment-726812393 2

  2. https://github.com/testing-library/dom-testing-library/issues/820#issuecomment-726980009

  3. https://github.com/testing-library/dom-testing-library/issues/820#issuecomment-726994803

  4. https://github.com/testing-library/dom-testing-library/issues/698

Copy link

netlify bot commented Dec 6, 2023

Deploy Preview for testing-library ready!

Name Link
🔨 Latest commit 762309c
🔍 Latest deploy log https://app.netlify.com/sites/testing-library/deploys/65705a18cd09dc0008b7abc0
😎 Deploy Preview https://deploy-preview-1349--testing-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -462,3 +462,20 @@ You can query a specific element like this
```js
getByRole('alertdialog', {description: 'Your session is about to expire'})
```

## Performance
Copy link
Member

Choose a reason for hiding this comment

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

This looks good to me, but I'd like to keep it open for second reviewer.
One additional comment we might encourage is to use happy-dom as that should be faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'd be happy to add a note about happy-dom as I agree it is likely the best option if it works for people (I've seen some users report it isn't a viable option for them yet).

What do we think about adding something like this?

"Firstly, if you are using jsdom we'd encourage trying happy-dom as it is much more efficient. If this works for you it is your best option, improving performance while keeping test confidence.

Otherwise the suggestions below may help."

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it like this for now, as this will likely break something.
We can always revisit it later.

Choose a reason for hiding this comment

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

From my research, happy-dom is faster but lacks the fetureset of JSDOM, and that is reason folks often revert back to JSDOM after attempting a migration.

@timdeschryver timdeschryver merged commit e301036 into testing-library:main Jan 13, 2024
4 checks passed
@timdeschryver
Copy link
Member

@all-contributors please add @agentdylan for docs

Copy link
Contributor

@timdeschryver

I've put up a pull request to add @agentdylan! 🎉

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.

3 participants