material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[code-infra] Optimize `@testing-library/user-event`

Open Janpot opened this issue 1 year ago • 3 comments

See this thread

I've seen this reduce the time of running userEvent.keyboard by an order of magnitude, eliminating the motivation to avoid using this library. It comes at the cost of slightly changed semantics. But even with these different semantics, we'd be better off compared to the way we currently test.

It would be best for us to primarily optimize our tests for refactorability. Tests that require updates on every implementation detail change miss the mark. We should aim at tests that maximize interfacing with public API and minimize reliance on implementation details. Therefore, unless we specifically want to test an implementation detail, we should prefer userEvent.

Closes https://github.com/mui/mui-x/pull/14668

Janpot avatar Sep 18 '24 08:09 Janpot

Netlify deploy preview

https://deploy-preview-43804--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by :no_entry_sign: dangerJS against 45bb823db5e2963daeb219fd28424dabe991ea5d

mui-bot avatar Sep 18 '24 08:09 mui-bot

Can this break MUI X tests?

Technically yes, but unlikely. We could try it out before merging.

Do we need to release this in a way that allows some tests to configure this behavior?

We could add a parameter to createRenderer, but you can also just set up your own const user = userEvent.setup() instance and use that for a specific test. IMO over time we should work towards moving things out of createRenderer and make the wrapper unnecessary.

Janpot avatar Sep 18 '24 10:09 Janpot

🙂 Yep, trying this in X breaks the tests, ~but looks like it's not caused by this change, see https://github.com/mui/mui-x/pull/14671~

Edit: Looks like it now fails consistently

Janpot avatar Sep 19 '24 09:09 Janpot

closing as it breaks X

Janpot avatar Dec 09 '25 12:12 Janpot