-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[code-infra] vitest
browser & jsdom modes
#14508
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-14508--material-ui-x.netlify.app/ |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
vitest
browser mode working - chartsvitest
browser mode
vitest
browser modevitest
browser & jsdom modes
@LukasTy @flaviendelangle @noraleonte @arthurbalduini I think I've fixed most of the issues with date-pickers in vitest that I could without going super deep on how everything works 😅 I now need some help with understanding the current errors, and possible ideas on how to fix them. You can check the current failing tests here: |
vitest.workspace.ts
Outdated
browser: { | ||
enabled: true, | ||
name: 'chromium', | ||
provider: 'playwright', | ||
headless: true, | ||
// https://playwright.dev | ||
providerOptions: {}, | ||
screenshotFailures: false, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting
.github/workflows/vitest.yml
Outdated
@@ -0,0 +1,51 @@ | |||
name: Vitest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CircleCI please: https://www.notion.so/mui-org/code-infra-Migrate-out-of-CircleCI-42350363b7344380a9961cf9731aae31 for the final version of this effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is just for ensuring the changes work while working on them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the GH workflow given that CircleCI is already setup? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The speed of the tests in the CI looks encouraging 👍 . A bit early to see if there is a real difference with the current CI though (test coverage vs. none, CircleCI vs. GitHub Action).
@@ -37,7 +37,7 @@ const addReactCompilerRule = (packagesNames, isEnabled) => | |||
!isEnabled | |||
? [] | |||
: packagesNames.map((packageName) => ({ | |||
files: [`packages/${packageName}/src/**/*{.ts,.tsx,.js}`], | |||
files: [`packages/${packageName}/src/**/*.?(c|m)[jt]s?(x)`], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this regex, it seems hard to search in the codebase for, e.g. .tsx
, I suspect that listing all the permutations would be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why you would need to search for that though. As you will have to sweep over all configuration files when doing a change that would require updating that anyways 😅
Replacing it to list all the permutations is quite unnecessary in my view: {.ts,.tsx,.js,.cjs,.cjsx,.mjs,.mjsx,.cts,.ctsx,.mts,.mtsx}
We could cleanup some unlikely exts like {.ts,.tsx,.js,.cjs,.mjs,.mts}
which would be simpler, but less complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but less complete.
Could it actually be great? I assume we will never need those other extensions, so if someone create them, he might be more likely to realize those are wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it actually be great? I assume we will never need those other extensions, so if someone create them, he might be more likely to realize those are wrong?
Quite the contrary, we sometimes need those extensions:
- When running scripts natively on node (or through
tsx
), we need a way to signal node which module system is being used. - We need .cjs in edge-cases for upcoming ESM support in places where we want to bridge between ESM and CJS, e.g. to deal with importing
next/document
in ESM. - Tooling like
esbuild
,tsx
andvitest
rely on the extension to determine whether JSX needs to be transformed or not. This is currently giving problems as we have a bunch of jsx in.js
files. See Enable JSX in.js
files privatenumber/tsx#644 and Allow JSX in .js files vitest-dev/vitest#1564. For the latter I have a workaround but it also forces our.ts
files to adhere to the JSX rules, which required me to refactor some code. - If we want our output to be interpreted correctly as ESM in node, it will need the correct extension. (granted, this code is not authored and thus not linted)
- ...
We shouldn't restrict extensions, they're not for cosmetic reasons. We should just prefer .ts
/.tsx
unless specific runtime requirements demand otherwise.
Besides that, I think the logic of "so if someone create them, he might be more likely to realize those are wrong?" is flawed. They likely won't realize anything, starting with not realizing eslint is not running on their code 😄. Better is to apply the rules to any file that could contain javascript/typescript and if we need to enforce a specific extension we should use a specific rule for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They likely won't realize anything
@Janpot If a developer can't run the tests he/she try to write in dev mode, I think he/she will notice that something is off.
For eslint specifically, yeah, agree, the ideal is to lint the file and have an eslint rule that error because the extension is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a developer can't run the tests he/she try to write in dev mode, I think he/she will notice that something is off.
In any case, why have them waste time reverse engineering the tests to find out they're using the wrong extension if the eslint plugin can tell them in context in the editor? 🤔 Not that there would be anything wrong with using .jsx instead of .js for JSX files, contrary, it would kind of make things easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the eslint plugin can tell them in context in the editor?
👍 https://www.npmjs.com/package/eslint-plugin-filename-rules sounds great.
Not that there would be anything wrong with using .jsx instead of .js for JSX files
I think that the value of only having .js
is about not having to think about extensions. Having to rename a file after refactoring its content and moving the code around is friction to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we can't get around this friction in typescript. Finishing the typescript migration means imposing this friction across the codebase anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a developer can't run the tests he/she try to write in dev mode, I think he/she will notice that something is off.
🙂 Coincidentally, I'm just running into a problem that illustrates why this is harmful. Just trying to figure out why I have a failing test locally in vitest that doesn't seem to break in mocha. The following produces a failing test:
pnpm --filter @mui/icons-material test -- -g "\"should produce the expected output\""
But when you try running the global command:
pnpm test:coverage -- -g "\"should produce the expected output\""
Whoops, no test is running. What happened? Somewhere along the way we started running the build script natively in node. The file was renamed to .mjs. The test runner only looks for .js, .ts, and .tsx. The author didn't see any tests break after running them and assumed they were good. They didn't realize the test stopped running altogether. If the test framework was configured to run on any encountered javascript file, nothing would have been broken.
It took me a while to realize the test wasn't running, my first instinct was "something fails in vitest that breaks in mocha".
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Related mui/material-ui#43625
Minimal changes to have
charts
tests working in browser modeCharts are the smallest test suit though
Help toward mui/mui-public#170.
Currently ignoring
DateFnsV3
adapter tests in the browser due to vitest-dev/vitest#6483 they work normally in jsdom though.Running tests