[docs] Improve jsdom section#48098
Conversation
Netlify deploy previewBundle size report
|
The ecosystem standardized on production/development to disable debug logs, enable optimizations, disable caches,... These behaviors must be testable. therefore the test suite can't overload the environment selection with its own logic. If you want to branch on "test environment" in end-user code (avoid at all cost), you should use a different signal. i.e. There is no wide-spread consensus on
One of:
It says:
This is close to what I'm proposing, we only compare
If this is desired behavior then it needs to be testable. i.e. test suite needs to turn on/off dev mode and verify the difference in behavior. |
@Janpot It feels that it's different in practice. NODE_ENV=test is usually the default when running tests:
On the opposite side of the coin, there is something I don't understand. What's the value of never testing NODE_ENV === 'test'. To what I understand, we use this check to improve the default experience for people who test the wrapped version of our products. It avoid the need for people to configure what they would want 90% of the time. But we still make it possible to test a different behavior. |
The fact that 5 environments do 3 different things confirms to me that there is no consensus. To note that if we strictly rely on comparing only with
To me this is the problem: We used this check to tune the library for browsers that don't support layout. We naively used As the Node.js doc you mention points out, environment checks are just bad architecture. It assumes that everyone's testing environment and requirements are the same. Better to build individual switches if you need specific features turned off/on. |
@Janpot This aspect does seem like it's more correct code behavior, agree.
But I'm still confused. When I try to understand why we would not have a single NODE_ENV=test branch in the code, the only logic I can find is: it's about making it easier for us, maintainers, we would have fewer combinations to think about. But this comes at the expense of making the default behavior worse for the developers because they would need to configure more things.
In this case (license verificator), to test the behavior of the code that would happen in "prod", we need to change process.env.NODE_ENV to set it to "test".
This feels like more complexe that it needs to be, if Overall, when we look at all the places where we have
So overall, removing "The |
Why not in test env? We should give the users the choice: You want to verify your license is still valid in your tests? Great, add a license to your test env. You don't care and don't want a renovate update be flagged when it breaks the license? Also great, suppress the warning in your test env. |
I have moved this thread to the initial change https://github.com/mui/mui-x/pull/21121/changes#r2991594432. So overall, it looks like we should work toward:
But we are not there yet, we might even need the test frameworks to change some of the way their code behaves. |
Co-authored-by: Olivier Tassinari <oliviertassinari@users.noreply.github.com> Signed-off-by: Olivier Tassinari <oliviertassinari@users.noreply.github.com>
|
I see that we do vale validation through both Github actions and also run it in CircliCI. I know that running on GH provides nice annotations within the code review UI. Do we want to do this in both CIs or can we just keep one of these ? |
I noticed the casing issue while reading https://next.mui.com/material-ui/migration/upgrade-to-v9/#jsdom-support. So I went to fix the case.
While I read the sentence, I was confused about the copies, e.g., "for for", line break for each sentence, use of future tense, use of we, etc. So I fixed those.
As for the change itself, looking closer, I don't see how it's possible to only use
NODE_ENVfor tree shaking. It seems wrong, we need process.env.NODE_ENV to represent the environment, 'development', 'test', 'production', so I have softened the messaging.Why:
https://github.com/mui/mui-x/blob/7dc081233c1fb95afa9f8131d2c48a762fc6f716/packages/x-charts/src/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.ts#L79
This policy seems compatible with https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production. And mui/mui-x#1151 touches on the need to make the default test DX great.
Context:
Preview: https://deploy-preview-48098--material-ui.netlify.app/material-ui/migration/upgrade-to-v9/#jsdom-support