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

[test] Disable react-transition-group transitions in unit testing #16288

Merged
merged 39 commits into from
Jan 31, 2025

Conversation

lauri865
Copy link
Contributor

@lauri865 lauri865 commented Jan 21, 2025

An experiment to remove transitions from unit tests in order to make tests more stable. Lots of tests breaking due to act errors, which more often than not are related to the Transition component of react-transition-group. Would be good to disable it globally, and get rid of unnecessary waitFor calls as a result to make testing faster as well as more stable.

I don't have more time to dig into this now, so will leave it at this, if anyone wants to explore it further. Some tests broke as a result.

UPDATE (Lukas)

  • Used config.disabled = true to disable transitions in mocha and karma tests
  • Remove waitFor usage where it was possible (mostly since transitions are no longer causing the need for it)

@lauri865 lauri865 changed the title Draft: [tests] override react transition group Draft: [tests] disable animations in unit testing Jan 21, 2025
@mui-bot
Copy link

mui-bot commented Jan 21, 2025

Deploy preview: https://deploy-preview-16288--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against d05549a

@LukasTy LukasTy added the test label Jan 22, 2025
@LukasTy LukasTy changed the title Draft: [tests] disable animations in unit testing [test] disable animations in unit testing Jan 22, 2025
@LukasTy LukasTy marked this pull request as draft January 22, 2025 07:03
test/utils/mochaHooks.js Outdated Show resolved Hide resolved
@LukasTy
Copy link
Member

LukasTy commented Jan 22, 2025

@lauri865 @mui/xgrid WDYT about the updated approach of https://reactcommunity.org/react-transition-group/testing/? 🤔
Some problematic tests would have to be adjusted. 🙈

@lauri865
Copy link
Contributor Author

@lauri865 @mui/xgrid WDYT about the updated approach of https://reactcommunity.org/react-transition-group/testing/? 🤔 Some problematic tests would have to be adjusted. 🙈

Ah, nice find! Seems to break less tests it seems as well.

Wonder why they suggested an alternative approach here? 🤔
https://testing-library.com/docs/example-react-transition-group/

@LukasTy
Copy link
Member

LukasTy commented Jan 23, 2025

Ah, nice find! Seems to break less tests it seems as well.

Wonder why they suggested an alternative approach here? 🤔 https://testing-library.com/docs/example-react-transition-group/

I am not sure; maybe they are suggesting going for maximum efficiency and completely mocking the module to avoid any potential overhead.
I've used sinon.stub in the latest implementation to assert this idea. 😉
There are some Data Grid browser tests failing after this. 🤔

@lauri865
Copy link
Contributor Author

lauri865 commented Jan 23, 2025

Ah, nice find! Seems to break less tests it seems as well.
Wonder why they suggested an alternative approach here? 🤔 https://testing-library.com/docs/example-react-transition-group/

I am not sure; maybe they are suggesting going for maximum efficiency and completely mocking the module to avoid any potential overhead. I've used sinon.stub in the latest implementation to assert this idea. 😉 There are some Data Grid browser tests failing after this. 🤔

I'm not insinuating it's better. I found it difficult to fake the components due to some state being dependent on transition life-cycle events, hence I overrode props instead.

Are you use the latest one works? Transition component children are functions in many instances, and this should error out ("functions are not valid children" yaddayadda).

function FakeTransition({ children }) { return <React.Fragment>{children}</React.Fragment>; };

If the config prop works, I think it's probably the best bet.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 27, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 27, 2025
@@ -1776,6 +1777,10 @@ describe('<DataGridPremium /> - Row grouping', () => {
});

it('should add a "Stop grouping {field}" menu item for each grouping criteria on the grouping column when prop.rowGroupingColumnMode = "single"', () => {
const restoreDisabledConfig = config.disabled;
// enable `react-transition-group` transitions for this test
config.disabled = false;
Copy link
Member

Choose a reason for hiding this comment

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

This test needs animations or refactoring.

@@ -198,6 +199,10 @@ describe('<DataGridPro /> - Column headers', () => {
});

it('should remove the MuiDataGrid-menuOpen CSS class only after the transition has ended', () => {
const restoreDisabledConfig = config.disabled;
// enable `react-transition-group` transitions for this test
config.disabled = false;
Copy link
Member

Choose a reason for hiding this comment

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

This test needs animations with timeouts or a complete refactor/removal

@LukasTy LukasTy changed the title [test] disable animations in unit testing [test] Disable react-transition-group transitions in unit testing Jan 27, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 27, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@LukasTy LukasTy added the scope: code-infra Specific to the core-infra product label Jan 29, 2025
@LukasTy LukasTy marked this pull request as ready for review January 29, 2025 12:21
@LukasTy
Copy link
Member

LukasTy commented Jan 29, 2025

@lauri865 Thank you for the suggestion. 👌
I think the PR is ready for review. 👍
P.S. I've ran the additional tests pipeline to check if there are any new failing tests, but it seems that those are the same from master.

@LukasTy LukasTy requested review from a team January 29, 2025 14:28
@LukasTy
Copy link
Member

LukasTy commented Jan 30, 2025

It feels as if we can't move forward with this until Data Grid tests are stabilized. 🙈
On every new run, some new tests might start failing...

@lauri865
Copy link
Contributor Author

lauri865 commented Jan 30, 2025

Great work! Curiously though, the unit tests seem to run much slower now 🙈 Although I would pick stability over performance in this case, but still.

Regarding randomly breaking tests, tell me about it... wants to make me give up on opening any new PRs.

@LukasTy
Copy link
Member

LukasTy commented Jan 30, 2025

Great work! Curiously though, the unit tests seem to run much slower now 🙈 Although I would pick stability over performance in this case, but still.

It could be due to a slower container. 🤔
The previous run was way quicker and quicker than the current median...
Or, setting config.disabled before every test might actually have a tangible performance drawback as compared to beforeAll... 🤷

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 30, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 30, 2025
@LukasTy LukasTy requested a review from Janpot January 30, 2025 14:57
@LukasTy
Copy link
Member

LukasTy commented Jan 30, 2025

After merging with the latest master branch the CI seems stable and React 18 tests are passing. 🤔

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Looks good, but I'd do a separate PR to fix those act calls

@LukasTy
Copy link
Member

LukasTy commented Jan 31, 2025

@mui/xgrid should I wait for a review from you, given that test changes are in Grid packages? 🤔

@LukasTy LukasTy merged commit 804bb40 into mui:master Jan 31, 2025
18 checks passed
A-s-h-o-k pushed a commit to A-s-h-o-k/mui-x that referenced this pull request Feb 4, 2025
JCQuintas pushed a commit to JCQuintas/mui-x that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: code-infra Specific to the core-infra product test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants