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

[code-infra] vitest browser & jsdom modes #14508

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
eff3bca
vitest browser mode working charts
JCQuintas Sep 5, 2024
bd11253
Merge commit 'cc2a9a3669a362d7fe17e555a74f62ebb401f2ca' into vitest-x…
JCQuintas Sep 5, 2024
9a6cbf8
Fix mocha + vitest
JCQuintas Sep 5, 2024
4a27d05
push runnable change
JCQuintas Sep 5, 2024
fb7c2de
mocha vs vitest
JCQuintas Sep 6, 2024
118a532
Remove playwright direct dep
JCQuintas Sep 6, 2024
33293ca
try normalizing container
JCQuintas Sep 6, 2024
d14ad46
try clearing the body margin
JCQuintas Sep 6, 2024
5a67c1b
Merge commit 'c25374458e4a5f7f244494accc9666a6a9c1d1d8' into vitest-x…
JCQuintas Sep 10, 2024
d39f9e4
Fix new tests
JCQuintas Sep 10, 2024
aa6b60d
fix jsdom
JCQuintas Sep 10, 2024
1db9bbb
browser and dom together
JCQuintas Sep 10, 2024
3e5caf5
packages
JCQuintas Sep 10, 2024
a1234b6
add workflow
JCQuintas Sep 10, 2024
9a6eb21
fix playwright install
JCQuintas Sep 10, 2024
09de9d7
check permission
JCQuintas Sep 10, 2024
91c67c0
try removing duplicate dep
JCQuintas Sep 10, 2024
94bbb95
upgrade playwright
JCQuintas Sep 10, 2024
8d37f26
dedupe
JCQuintas Sep 10, 2024
e47aa21
Fix chai assertions
JCQuintas Sep 10, 2024
7f19f37
revert playwright
JCQuintas Sep 10, 2024
ad28046
overwrite playwright in internal packages
JCQuintas Sep 10, 2024
d522dab
easy config
JCQuintas Sep 10, 2024
795d4af
Add date pickers to alias
JCQuintas Sep 10, 2024
18b7a5c
fix skips in date pickers
JCQuintas Sep 10, 2024
593e59c
Merge commit '0ea5ef2a430d85d5266ec6a333fc41c10961f988' into vitest-x…
JCQuintas Sep 11, 2024
bbeed7f
Revert "fix skips in date pickers"
JCQuintas Sep 11, 2024
8e375a2
Add skip logic
JCQuintas Sep 11, 2024
3eced20
Fix low hanging fruits
JCQuintas Sep 11, 2024
2893eef
Add touch, remove timeout
JCQuintas Sep 11, 2024
4645e72
Run test in utc
JCQuintas Sep 11, 2024
a8464a9
update config
JCQuintas Sep 11, 2024
8f540d7
global override pnpm
JCQuintas Sep 11, 2024
4507e81
Refactor Touch class to support non-browser mode
JCQuintas Sep 11, 2024
90754d6
divide jsdom/browser tests
JCQuintas Sep 11, 2024
8218f0e
fix pickers setup
JCQuintas Sep 12, 2024
a9af3e4
Fix date-fns-v3 imports
JCQuintas Sep 12, 2024
6fffa88
Ignore datefnsv3 in browser
JCQuintas Sep 12, 2024
2b0754e
Revert unnecessary check
JCQuintas Sep 12, 2024
23925ac
jsdom working for charts and datepickers
JCQuintas Sep 12, 2024
5c85b9f
add small config changes
JCQuintas Sep 13, 2024
f1269fd
import vitest only if in vitest
JCQuintas Sep 13, 2024
3e2fbe4
types/chai clash with vitest
JCQuintas Sep 13, 2024
164ec72
Merge commit 'e745af36e1f56fe2e73a6c052ffa9cbe3e17a719' into vitest-x…
JCQuintas Sep 13, 2024
e396545
Use global vi
JCQuintas Sep 13, 2024
5121079
Use globalThis.vi
JCQuintas Sep 13, 2024
570e939
Fix test functions without closure
JCQuintas Sep 13, 2024
8812678
browser only test example
JCQuintas Sep 16, 2024
a06bb50
Fix moment imports
JCQuintas Sep 16, 2024
f3da275
fix russian tests
JCQuintas Sep 16, 2024
7ba380b
fix field keyboard test
JCQuintas Sep 16, 2024
ca22dde
Fix karma config
JCQuintas Sep 16, 2024
ff6c715
mocha ignore browser/jsdom extensions
JCQuintas Sep 16, 2024
90d0af7
Remove browser example to fix typescript
JCQuintas Sep 16, 2024
db2817d
Update .mocharc.js
JCQuintas Oct 4, 2024
b2b8628
update packages
JCQuintas Oct 4, 2024
8434b41
use x-package for names
JCQuintas Oct 4, 2024
0f8b218
try urls
JCQuintas Oct 8, 2024
2d5d395
mock datefns in files instead of globally
JCQuintas Oct 8, 2024
4d58fb9
Merge commit 'b99d38aa07a4990c873ee63371a368b1d5c14870' into vitest-x…
JCQuintas Oct 8, 2024
493133d
use datefnsv4
JCQuintas Oct 8, 2024
f338a12
dedupe
JCQuintas Oct 8, 2024
66c410e
try fixing babelconfig
JCQuintas Oct 8, 2024
94b4443
fix typescript
JCQuintas Oct 8, 2024
43ce018
add license and pro packages
JCQuintas Oct 8, 2024
b219263
add license and internals tests
JCQuintas Oct 8, 2024
f530667
add todo
JCQuintas Oct 8, 2024
4fd6d33
run test without mocking timers
JCQuintas Oct 8, 2024
8d3601c
update internals
JCQuintas Oct 9, 2024
23bb8c2
Merge commit 'b4b179483a7d616456ba52620ab7b5e2cf947f48' into vitest-x…
JCQuintas Oct 9, 2024
4497dd8
remove unused clock var
JCQuintas Oct 9, 2024
6539759
make test work in vitest and mocha
JCQuintas Oct 9, 2024
b20b1bb
sequence.hooks = list
JCQuintas Oct 11, 2024
840c4b6
Fix datepickes pro test
JCQuintas Oct 11, 2024
6db68b8
ignore failing browser tests
JCQuintas Oct 11, 2024
9f6f828
add lib alias config
JCQuintas Oct 11, 2024
a353cb6
init data-grid and replace skips
JCQuintas Oct 11, 2024
1885222
fix toerror
JCQuintas Oct 11, 2024
f985554
datagrid cleanup
JCQuintas Oct 11, 2024
b869545
fix jsdom issues
JCQuintas Oct 11, 2024
739c2d4
fix browser tests datagrid
JCQuintas Oct 11, 2024
8b38fd9
datagrid pro skips
JCQuintas Oct 11, 2024
f5493b8
Fix weird prop logic
JCQuintas Oct 11, 2024
820bbd5
Also change rendereditcell
JCQuintas Oct 11, 2024
8342499
refactor row editing
JCQuintas Oct 11, 2024
163ed7e
fix jsdom specific logic for vitest
JCQuintas Oct 11, 2024
953059d
fix issues with playwright scrollbar
JCQuintas Oct 11, 2024
dac3923
Revert "fix issues with playwright scrollbar"
JCQuintas Oct 14, 2024
ddc252d
update headless config to show scrollbar
JCQuintas Oct 14, 2024
8d28a7b
fix static analysis
JCQuintas Oct 14, 2024
1d47d30
Merge commit '5b4890961904b946bb7dccfd26b5e44b016d88e7' into vitest-x…
JCQuintas Oct 14, 2024
0e13811
try different config
JCQuintas Oct 14, 2024
88378a6
Merge commit '9c563ef908a49b40511201c55e7c002f9db98d51' into vitest-x…
JCQuintas Oct 14, 2024
d32bfe5
use different values for vitest and karma
JCQuintas Oct 14, 2024
dd40b0e
initial data-grid-premium
JCQuintas Oct 14, 2024
0bba870
remove unnecessary cleanup
JCQuintas Oct 14, 2024
f06ff48
use user events
JCQuintas Oct 14, 2024
5c57167
fix access
JCQuintas Oct 14, 2024
c264163
enable treeview and skips
JCQuintas Oct 14, 2024
a1feb9b
fix treeview
JCQuintas Oct 14, 2024
3615198
enable treeview pro
JCQuintas Oct 14, 2024
8757aa4
rename setup file
JCQuintas Oct 14, 2024
9799824
update mui-internals and dedupe
JCQuintas Oct 14, 2024
ed6dbb8
fix tests
JCQuintas Oct 14, 2024
7c62bfc
update comments
JCQuintas Oct 14, 2024
4f6b9c4
jsdom only packages
JCQuintas Oct 14, 2024
5442abd
setup circleci and enable coverage
JCQuintas Oct 15, 2024
aba0b63
dedupe
JCQuintas Oct 15, 2024
5a930f1
make helper libs also testable under vitest
JCQuintas Oct 15, 2024
8066b23
fix x-charts-vendor should import from esm
JCQuintas Oct 15, 2024
3bc1fa7
Merge commit 'c1e882ce9832b2a52a9d620a1d8b70a3dbad3059' into vitest-x…
JCQuintas Oct 15, 2024
98013ae
run coverage in vitest gha
JCQuintas Oct 15, 2024
f3b6d1f
add to workflow
JCQuintas Nov 5, 2024
7cf9c69
apply glob suggestions
JCQuintas Nov 5, 2024
0098dbc
Merge commit 'f50938c40ac76dba7a02ea883c54b685c9503a74' into vitest-x…
JCQuintas Nov 5, 2024
fa96d91
Merge commit 'c41bfaa2ec5ac8412b30b506bff0208fffedb3f0' into vitest-x…
JCQuintas Nov 5, 2024
0085b9e
dedupe
JCQuintas Nov 5, 2024
121bde4
fix skipping new tests
JCQuintas Nov 5, 2024
dd2621b
Revert user events for some date pickers
JCQuintas Nov 5, 2024
fd39e32
try to optimize threads
JCQuintas Nov 6, 2024
a154440
fix run
JCQuintas Nov 6, 2024
10523ec
simpler reporter
JCQuintas Nov 6, 2024
96d1d12
reporters
JCQuintas Nov 6, 2024
d86d6cf
try not using image
JCQuintas Nov 6, 2024
9d486d6
Merge commit '941f15d056549773572a5abea6023421cfafdc3b' into vitest-x…
JCQuintas Nov 6, 2024
3bfdce8
remove "browser" tag
JCQuintas Nov 6, 2024
73b10fe
try a single fork in browser mode
JCQuintas Nov 6, 2024
be83e61
threads
JCQuintas Nov 6, 2024
1ff3ea1
try options
JCQuintas Nov 7, 2024
1da790d
Merge commit '706186588abf34b75dc843e7575f17d9de54a643' into vitest-x…
JCQuintas Nov 7, 2024
6a5056e
run only one
JCQuintas Nov 7, 2024
ee14aa5
more threads
JCQuintas Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ jobs:
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -Z -F "$REACT_VERSION-jsdom"

test_unit_vitest:
<<: *default-job
steps:
- checkout
- install_js
- run:
name: Tests fake browser (vitest)
command: pnpm vitest --project "jsdom/*" --coverage --pool=threads
environment:
VITEST_MAX_THREADS: 6
VITEST_MIN_THREADS: 2
- run:
name: Check coverage generated
command: |
if ! [[ -s coverage/lcov.info ]]
then
exit 1
fi
# - run:
# name: Coverage
# command: |
# curl -Os https://uploader.codecov.io/latest/linux/codecov
# chmod +x codecov
# ./codecov -t ${CODECOV_TOKEN} -Z -F "$REACT_VERSION-jsdom"

test_lint:
<<: *default-job
steps:
Expand Down Expand Up @@ -237,6 +263,22 @@ jobs:
# hardcoded in karma-webpack
path: /tmp/_karma_webpack_
destination: artifact-file

test_browser_vitest:
<<: *default-job
docker:
- image: mcr.microsoft.com/playwright:v1.44.1-focal
steps:
- checkout
- install_js:
browsers: true
- run:
name: Tests real browsers (vitest)
command: pnpm vitest --project "browser/x-data-grid" --pool=threads
environment:
VITEST_MAX_THREADS: 1
VITEST_MIN_THREADS: 1

test_types:
<<: *default-job
steps:
Expand Down Expand Up @@ -311,6 +353,10 @@ workflows:
<<: *default-context
requires:
- checkout
- test_unit_vitest:
<<: *default-context
requires:
- checkout
- test_lint:
<<: *default-context
requires:
Expand All @@ -323,6 +369,10 @@ workflows:
<<: *default-context
requires:
- checkout
- test_browser_vitest:
<<: *default-context
requires:
- checkout
- test_types:
<<: *default-context
requires:
Expand Down
22 changes: 14 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`],
Copy link
Member

@oliviertassinari oliviertassinari Sep 18, 2024

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

@Janpot Janpot Oct 17, 2024

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 and vitest 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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 17, 2024

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.

Copy link
Member

@Janpot Janpot Oct 17, 2024

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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 17, 2024

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.

Copy link
Member

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.

Copy link
Member

@Janpot Janpot Oct 17, 2024

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".

rules: {
'react-compiler/react-compiler': 'error',
},
Expand All @@ -58,8 +58,8 @@ const RESTRICTED_TOP_LEVEL_IMPORTS = [
// It needs to know about the parent "no-restricted-imports" to not override them.
const buildPackageRestrictedImports = (packageName, root, allowRootImports = true) => [
{
files: [`packages/${root}/src/**/*{.ts,.tsx,.js}`],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx', '**.test.tx', '**.test.tsx'],
files: [`packages/${root}/src/**/*.?(c|m)[jt]s?(x)`],
excludedFiles: ['*.d.ts', '*.spec.*', '*.test.*'],
rules: {
'no-restricted-imports': [
'error',
Expand Down Expand Up @@ -94,8 +94,8 @@ const buildPackageRestrictedImports = (packageName, root, allowRootImports = tru
: [
{
files: [
`packages/${root}/src/**/*.test{.ts,.tsx,.js}`,
`packages/${root}/src/**/*.spec{.ts,.tsx,.js}`,
`packages/${root}/src/**/*.test.?(c|m)[jt]s?(x)`,
`packages/${root}/src/**/*.spec.?(c|m)[jt]s?(x)`,
],
excludedFiles: ['*.d.ts'],
rules: {
Expand Down Expand Up @@ -244,8 +244,8 @@ module.exports = {
},
},
{
files: ['packages/*/src/**/*{.ts,.tsx,.js}'],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx'],
files: ['packages/*/src/**/*.?(c|m)[jt]s?(x)'],
excludedFiles: ['*.d.ts', '*.spec.*'],
rules: {
'material-ui/mui-name-matches-component-name': [
'error',
Expand All @@ -267,7 +267,7 @@ module.exports = {
},
},
{
files: ['docs/**/*{.ts,.tsx,.js}'],
files: ['docs/**/*.?(c|m)[jt]s?(x)'],
excludedFiles: ['*.d.ts'],
rules: {
'no-restricted-imports': [
Expand Down Expand Up @@ -297,6 +297,12 @@ module.exports = {
],
},
},
{
files: ['**/*.browser.test.?(c|m)[jt]s?(x)'],
rules: {
'testing-library/prefer-screen-queries': 'off',
},
},
...buildPackageRestrictedImports('@mui/x-charts', 'x-charts', false),
...buildPackageRestrictedImports('@mui/x-charts-pro', 'x-charts-pro', false),
...buildPackageRestrictedImports('@mui/x-codemod', 'x-codemod', false),
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/vitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Vitest
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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


on:
push:
branches:
- 'master'
- 'next'
pull_request:
branches:
- 'master'
- 'next'

permissions: {}

jobs:
vitest-jsdom:
name: Vitest Tests (jsdom)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false
- name: Use Node.js 20.x
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: 20
cache: 'pnpm' # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-dependencies
- run: pnpm install --frozen-lockfile
- name: Install Playwright Browsers
run: pnpm playwright install --with-deps
- name: Run Tests
run: pnpm vitest --project "jsdom/*" --coverage
vitest-browser:
name: Vitest Tests (browser)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false
- name: Use Node.js 20.x
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: 20
cache: 'pnpm' # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-dependencies
- run: pnpm install --frozen-lockfile
- name: Install Playwright Browsers
run: pnpm playwright install --with-deps
- name: Run Tests
run: pnpm vitest --project "browser/*"
3 changes: 3 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// We can't import the `.mocharc.js` of the monorepo, otherwise we trigger its `setupBabel`.

module.exports = {
extension: ['js', 'ts', 'tsx'],
ignore: [
Expand All @@ -7,6 +8,8 @@ module.exports = {
// Mocha seems to ignore .next anyway (maybe because dotfiles?).
// We're leaving this to make sure.
'docs/.next/**',
'packages/**/*.browser.test.{js,ts,tsx,jsx}',
Copy link
Member

Choose a reason for hiding this comment

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

Is this a new file extension we're introducing? Can't find any such file.

'packages/**/*.jsdom.test.{js,ts,tsx,jsx}',
],
recursive: true,
timeout: (process.env.CIRCLECI === 'true' ? 5 : 2) * 1000, // Circle CI has low-performance CPUs.
Expand Down
8 changes: 4 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ module.exports = function getBabelConfig(api) {
plugins.push([
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a TODO here to remove these plugins once fully migrated to vitest?

'babel-plugin-replace-imports',
{
test: /date-fns/i,
replacer: 'date-fns-v4',
test: /date-fns\//i,
replacer: 'date-fns-v4/',
// This option is provided by the `patches/[email protected]` patch
filenameIncludes: 'src/AdapterDateFnsV3/',
},
]);
plugins.push([
'babel-plugin-replace-imports',
{
test: /date-fns-jalali/i,
replacer: 'date-fns-jalali-v3',
test: /date-fns-jalali\//i,
replacer: 'date-fns-jalali-v3/',
// This option is provided by the `patches/[email protected]` patch
filenameIncludes: 'src/AdapterDateFnsJalaliV3/',
},
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"release:publish:dry-run": "pnpm publish --recursive --tag next --registry=\"http://localhost:4873/\"",
"release:tag": "node scripts/releaseTag.mjs",
"validate": "concurrently \"pnpm prettier && pnpm eslint\" \"pnpm proptypes\" \"pnpm docs:typescript:formatted\" \"pnpm docs:api\"",
"clean:node_modules": "rimraf --glob \"**/node_modules\""
"clean:node_modules": "rimraf --glob \"**/node_modules\"",
"vitest": "cross-env TZ=UTC vitest"
},
"devDependencies": {
"@actions/core": "^1.11.1",
Expand Down Expand Up @@ -101,9 +102,9 @@
"@octokit/plugin-retry": "^7.1.2",
"@octokit/rest": "^21.0.2",
"@playwright/test": "^1.44.1",
"@testing-library/react": "^16.0.1",
"@types/babel__core": "^7.20.5",
"@types/babel__traverse": "^7.20.6",
"@types/chai": "^4.3.20",
"@types/chai-dom": "^1.11.3",
"@types/fs-extra": "^11.0.4",
"@types/karma": "^6.3.9",
Expand All @@ -118,6 +119,9 @@
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-react": "^4.3.2",
"@vitest/browser": "^2.1.3",
"@vitest/coverage-v8": "^2.1.3",
"autoprefixer": "^10.4.20",
"axe-core": "4.10.2",
"babel-loader": "^9.2.1",
Expand Down Expand Up @@ -192,14 +196,18 @@
"typescript": "^5.6.3",
"unist-util-visit": "^5.0.0",
"util": "^0.12.5",
"vitest": "2.1.3",
"webpack": "^5.95.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"yargs": "^17.7.2"
},
"resolutions": {
"react-is": "^18.3.1",
"@types/node": "^20.17.3"
"@types/node": "^20.17.3",
"@playwright/test": "1.44.1",
"playwright": "1.44.1",
"@mui/internal-test-utils": "https://pkg.csb.dev/mui/material-ui/commit/92c23999/@mui/internal-test-utils"
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be changed when mui/material-ui#43625 is merged.

I would still leave it as a resolution so all packages use the same.

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I would avoid all resolutions if we can, it tends to be misunderstood and overused and could result into setups that break on the user end but not on our end. (probably not for this dependency though)

If the version ranges are equal, there should be no duplication. And it shouldn't break in the first place if there was duplication.

},
"packageManager": "[email protected]",
"engines": {
Expand Down
33 changes: 24 additions & 9 deletions packages/x-charts/src/BarChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,30 @@ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
describe('BarChart - click event', () => {
const { render } = createRenderer();

beforeEach(() => {
if (window?.document?.body?.style) {
window.document.body.style.margin = '0';
}
});

afterEach(() => {
if (window?.document?.body?.style) {
window.document.body.style.margin = '8px';
}
});
Comment on lines +31 to +41
Copy link
Member Author

Choose a reason for hiding this comment

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

Some charts tests are reliant screen position, and margins are different for karma and vitest, so we force one. 🙃


describe('onAxisClick', () => {
it('should provide the right context as second argument', function test() {
it('should provide the right context as second argument', function test(t = {}) {
if (isJSDOM) {
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527
this.skip();
// @ts-expect-error to support mocha and vitest
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() || t?.skip();
Comment on lines +44 to +49
Copy link
Member Author

Choose a reason for hiding this comment

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

You will see this pattern across multiple files, t = {} tells mocha to treat this as an "empty" parameter, thus not triggering the logic to provide the done() callback to it.

Without this mocha will fail because it waits for the done() to be called.

This can then be migrated to just a .skip, but vitest offers many ways of skipping test.

function test(t) {
      if (isJSDOM) {
        t.skip();
      }
}

Copy link
Member

@Janpot Janpot Oct 16, 2024

Choose a reason for hiding this comment

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

I added a shim in ./setupVitest that we cold use while the tests run in both vitest and mocha. That prevents us in core from having to update all of these right now:
https://github.com/mui/material-ui/pull/43625/files#diff-21f1d3337bd5d6e3869ad10c93fa99770a34761876017b90bc1ed1ceaa7c93a9R45-R55
Want to move this to it.skipIf eventually

The same couldn't be done for describe.skipIf that only exists in vitest, I added a shim for that in test utils:

https://github.com/mui/material-ui/pull/43625/files#diff-52e69abe336786febd0b84dbd2d9b32ba0e8f74fcf5f71669c8917d9a434c4dcR3-R9

Don't necessarily have to use it, but it can keep the amount of code changes in tests down.

}
const onAxisClick = spy();
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
Expand Down Expand Up @@ -81,16 +94,17 @@ describe('BarChart - click event', () => {
});
});

it('should provide the right context as second argument with layout="horizontal"', function test() {
it('should provide the right context as second argument with layout="horizontal"', function test(t = {}) {
if (isJSDOM) {
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527
this.skip();
// @ts-expect-error to support mocha and vitest
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() || t?.skip();
}
const onAxisClick = spy();
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
Expand Down Expand Up @@ -155,16 +169,17 @@ describe('BarChart - click event', () => {
).to.deep.equal(['pointer', 'pointer', 'pointer', 'pointer']);
});

it('should provide the right context as second argument', function test() {
it('should provide the right context as second argument', function test(t = {}) {
if (isJSDOM) {
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527
this.skip();
// @ts-expect-error to support mocha and vitest
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this?.skip?.() || t?.skip();
}
const onItemClick = spy();
render(
<div
style={{
margin: -8, // No idea why, but that make the SVG coordinates match the HTML coordinates
width: 400,
height: 400,
}}
Expand Down
Loading