question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance issue with the byRole query causing timeout errors

See original GitHub issue
  • @testing-library/jest-dom version: 5.11.0
  • node version: 12.14.1
  • yarn version: 1.21.1

What you did:

I converted several tests of the project I work on, which were using manual queries with container and querySelector, to use screen prioritizing the query byRole as recommended.

What happened:

There are some timeout errors when I run some tests after the conversion to use screen and the byRole selector.

image

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 to byText.

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 as byText.

Below is the time it takes me 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).

image image

Then, the time it takes to perform the same test, but using the byText selector. I have run the test several times this way and with this selector I did not give a timeout because it is fast.

image image

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.

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!!!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:28
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
idanencommented, Oct 4, 2020

I totally agree with @eps1lon , but if there is something to do to improve performance we should give it a try, shouldn’t we? The difference between getByRole and getByLabelText is pretty big (notice in the test I compared to 5 times the duration and it’s still longer than that), so I think we should at least make some effort to reduce it

5reactions
eps1loncommented, Jul 15, 2020

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 accname spec. These checks are expensive but have a higher confidence that what you’re testing is actually what a screen reader would “see”.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect query timeout errors with Extended Events
When these start showing up in an application log, it is a good indicator that a performance issue may be occurring in SQL...
Read more >
The Top 5 Most Common SQL Server Performance Problems
I'm going to focus on operation timeouts, since they are the most common. Operation timeout errors from various software tools might be the...
Read more >
Common mistakes with React Testing Library - Kent C. Dodds
Using the wrong query · Using container to query for elements · Not querying by text · Not using *ByRole most of the...
Read more >
Troubleshooting Poorly Performing Queries
Is there an expensive workload or query that is causing a spike and could be ... is still having performance issues, consider the...
Read more >
Timeout errors on SQL server - HxGN SDx - Update 46
Problem Timeout errors occur on a SQL Server site when loading published documents and executing queries. Solution Run the following SQL on your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found