-
Notifications
You must be signed in to change notification settings - Fork 470
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
Performance issue with the byRole query causing timeout errors #698
Comments
I have the same problem. |
If you're confident that you can manually verify the checks ByRole provides then I suggest switching to other queries. ByRole considers the a11y tree, styles and the It's like any other tool: If you don't need the features then you should switch to a tool with smaller feature set. If test performance is a bigger issue for you than test confidence then ByRole is not the right tool. One thing: A real-world repro would help us a lot improving performance. We've had success in the past with good repros since they help us identify bottlenecks. Screenshots of code don't help us very much. Small examples that don't reproduce the issue are also not helpful. |
Shouldn't this issue be moved to @testing-library/dom? |
What's also very important is the environment e.g. which browser or if you're running from node (via e.g. |
Thank you very much for responding! I will try to reproduce the code we have to make it clearer.
|
I've made a contrived repo here: https://github.com/jihchi/698_byrole_performance_issue there is a 3rd-party datetime picker and it would take ~1 second when you opened the calendar and pick a specific date in the calendar by using |
Tried a PR adding a test like:
I think this gives a roughly good start. I'd be happy to continue if anyone has better idea of where might be a bottleneck, or how can I profile it. (does anyone see any value in a PR with just the failing test?) |
According to my investigation, @eps1lon has summarized the causes pretty clear and I agree with him:
Simply say, you may encounter slowness of |
I totally agree with @eps1lon , but if there is something to do to improve performance we should give it a try, shouldn't we? |
@idanen For sure, I would definitely love to see any improvements of |
I believe that the accessibility checks are nice, but in some cases you don't need them- take for example a UI framework. That's one of the times where you absolutely do want these checks. I think it very much depends on your needs. Not to mention some people have separate pipelines for these checks (eg. lighthouse) |
I also experience this problem but only on my CI runners, not on my local machine. I understand that |
@kentcdodds any updates on this? We are still hitting this 3 years later with However, I did see there is a v6 for jest-dom. But not sure if that addresses this issue. |
I can reproduce this issue with let start = new Date()
screen.getByRole('row', { name: rowRegex })
let duration = (new Date()) - start
console.log(rowRegex, duration)
start = new Date()
screen.getAllByRole('row')
duration = (new Date()) - start
console.log('all row', duration)
Yeahhhh you read well near 700ms to find one row matching an innerText vs 20 ms to get all the row. And |
As promise serious testing materials https://github.com/HugoPoi/bug-perf-demo-getByRole/tree/main |
I'm curious if the same query takes a similarly long time in Playwright. They implement all the Testing Library queries natively. I have also noticed performance differences between JSDOM with RTL vs Shadow DOM TL, which patches JSDOM to allow traversing shadow roots. Somehow the patches seem to avoid an expensive serialization step (or something) |
@alexkrolick I doubt it. Based on the research I did, it looks like our major bottleneck is |
Yes maybe the issue reside in JSDom but the method causing lags is |
Uh oh! @MatheusPoliCamilo, the image you shared is missing helpful alt text. Check your issue body. Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image. Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs. |
@testing-library/jest-dom
version: 5.11.0node
version: 12.14.1yarn
version: 1.21.1What you did:
I converted several tests of the project I work on, which were using manual queries with
container
andquerySelector
, to usescreen
prioritizing the querybyRole
as recommended.What happened:
There are some timeout errors when I run some tests after the conversion to use
screen
and thebyRole
selector.Reproduction:
I made a small example to demonstrate the difference in ms in a small case, like a table with 8 cells, when using the query
byRole
compared tobyText
.Problem description:
At the moment there is a certain performance problem with the
byRole
selector, which even causes a timeout problem in tests, something that does not happen with other selectors such asbyText
.Below is the time it takes to run a test on the project I work on when using the
byRole
query (in which there is a timeout error in some moments for taking too long).Then, the time it takes to perform the same test, but using the
byText
selector. I've run the test several times this way and with this selector there is no timeout, in addition to being much faster.Suggested solution:
I believe that for now the solution would be not to suggest the query
byRole
as a priority, at least until there are some more performance improvements to get closer to the other selectors and avoid timeouts.I apologize because I did not get to look at the code in depth to try to understand a little if there is a way to bring about an improvement in
byRole
. I am also aware of the benefits that this selector brings and I am willing to waste more time to run the tests to use it, however the time difference is still large and causing timeout errors. Thank you in advance!!!The text was updated successfully, but these errors were encountered: