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 277 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
277 commits
Select commit Hold shift + click to select a range
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
9b4e396
Apply suggestions from code review
JCQuintas Nov 14, 2024
1d38796
Merge commit 'e9c13ba43f7200a22f06e8b1d7063f31594d09b1' into vitest-x…
JCQuintas Nov 14, 2024
0bfd396
code review
JCQuintas Nov 14, 2024
4788163
use bigger class executor
JCQuintas Nov 14, 2024
ff510c2
dedupe
JCQuintas Nov 14, 2024
e5859c4
fix issues
JCQuintas Nov 14, 2024
0ac9091
Merge branch 'master' into vitest-x-browser-working
JCQuintas Nov 14, 2024
10d594d
revert thread usage
JCQuintas Nov 14, 2024
ed4e45c
update vitest and dedupe
JCQuintas Nov 14, 2024
8143ff0
update renovate
JCQuintas Nov 15, 2024
6145ec0
update configs and test
JCQuintas Nov 15, 2024
6137a65
stop using core setupVitest
JCQuintas Nov 15, 2024
2501941
try limiting mem size
JCQuintas Nov 15, 2024
0daad6b
dedupe
JCQuintas Nov 15, 2024
ab3517c
Merge commit '485054067c53685ca72a8c86c8bcc30deec4068c' into vitest-x…
JCQuintas Nov 15, 2024
399898f
upgrade playwright
JCQuintas Nov 15, 2024
ff30d99
revert images...
JCQuintas Nov 15, 2024
9af685b
try not using static playwirhgt image
JCQuintas Nov 15, 2024
2750a58
Revert "try not using static playwirhgt image"
JCQuintas Nov 15, 2024
9d49f6d
downgrade playwright
JCQuintas Nov 15, 2024
bc93279
fix new test cases
JCQuintas Nov 15, 2024
b8d1d31
Revert "Revert "try not using static playwirhgt image""
JCQuintas Nov 15, 2024
d3a6684
run all browser
JCQuintas Nov 15, 2024
5058664
Merge commit '130063b9b3fb3131e275525b49d48a4bf930e6ed' into vitest-x…
JCQuintas Nov 18, 2024
6a85d6f
Merge commit 'bf6bd17a4d005c69ad2c3571b37c9a646e058a8d' into vitest-x…
JCQuintas Nov 19, 2024
dcb21c0
Merge branch 'master' into vitest-x-browser-working
JCQuintas Nov 19, 2024
de5877b
Revert "Revert "Revert "try not using static playwirhgt image"""
JCQuintas Nov 19, 2024
c881448
Merge branch 'master' into vitest-x-browser-working
JCQuintas Nov 19, 2024
20d745c
use latest versions
JCQuintas Nov 19, 2024
8edef9d
use noble images as focal are old
JCQuintas Nov 19, 2024
7e62e43
install ffmpeg
JCQuintas Nov 19, 2024
efd2e32
use forks instead of threads
JCQuintas Nov 19, 2024
149bf34
remove sudo
JCQuintas Nov 19, 2024
69c594c
auto accept
JCQuintas Nov 19, 2024
441b4ec
set default timeout
JCQuintas Nov 19, 2024
db141ec
revert playwright bump
JCQuintas Nov 19, 2024
3498128
force all playwright to be specific version
JCQuintas Nov 19, 2024
d1bf2d4
Merge branch 'master' into vitest-x-browser-working
JCQuintas Nov 19, 2024
9d8828a
fix local tests
JCQuintas Nov 19, 2024
f411f01
Revert "fix local tests"
JCQuintas Nov 19, 2024
ebc3172
use fake clock
JCQuintas Nov 19, 2024
c9ad767
add warning
JCQuintas Nov 19, 2024
58681e0
dedupe
JCQuintas Nov 19, 2024
4f9cc56
fix issues
JCQuintas Nov 20, 2024
e040b42
use more native behaviours
JCQuintas Nov 20, 2024
25fafe2
improve regression logic
JCQuintas Nov 20, 2024
71bf483
Merge branch 'master' into vitest-x-browser-working
JCQuintas Nov 20, 2024
825d24f
add base route
JCQuintas Nov 20, 2024
43fea96
navigate by name
JCQuintas Nov 20, 2024
bdff27a
large runner
JCQuintas Nov 20, 2024
ff2846f
try giving tests a little time
JCQuintas Nov 20, 2024
5a9c982
go back to threads
JCQuintas Nov 20, 2024
0b0a0c3
make tests slower (revert)
JCQuintas Nov 20, 2024
4797a30
revert change
JCQuintas Nov 20, 2024
d1c9d7e
revert flags
JCQuintas Nov 20, 2024
dc988a6
Merge commit '1b9df943b2270b2f6624ce7dcca02bcd83d47983' into vitest-x…
JCQuintas Nov 20, 2024
608d851
threads
JCQuintas Nov 20, 2024
d66936e
decrease thread count
JCQuintas Nov 20, 2024
4438aa1
Merge commit '6fc697840107147a8003e5e58c7ac044e24f2751' into vitest-x…
JCQuintas Nov 20, 2024
093f61e
decrease ram
JCQuintas Nov 20, 2024
8707b71
dot reporter
JCQuintas Nov 20, 2024
8302086
run browser for datagrid only
JCQuintas Nov 20, 2024
393db84
changes
JCQuintas Nov 20, 2024
1b08251
use forks
JCQuintas Nov 20, 2024
5e2e9c0
threads again...
JCQuintas Nov 20, 2024
73df0e5
increase limit
JCQuintas Nov 20, 2024
ba2e15a
allow more ram
JCQuintas Nov 20, 2024
49010a8
run only dg pro
JCQuintas Nov 20, 2024
70272b7
try a lot of params
JCQuintas Nov 21, 2024
d265568
more config
JCQuintas Nov 21, 2024
5cbc098
Merge commit '69c48b21f3e23c4e016290137721e28826799944' into vitest-x…
JCQuintas Nov 21, 2024
924da97
fix vitest test
JCQuintas Nov 21, 2024
d0f94cd
try using single fork
JCQuintas Nov 21, 2024
f7fa812
skip optimizer
JCQuintas Nov 21, 2024
c98fd74
checking
JCQuintas Nov 21, 2024
f125aab
use istanbul
JCQuintas Dec 2, 2024
b8868bb
Use coverage in browser
JCQuintas Dec 2, 2024
2364ccf
Merge commit '82d46ab329a11bf9308e8a1cf57786ac0cec37ad' into vitest-x…
JCQuintas Dec 2, 2024
6f15cae
dedupe
JCQuintas Dec 2, 2024
6408abe
fix versions
JCQuintas Dec 2, 2024
c440d24
Merge commit '65ca2086efbeb526b734db560a8e19f833562aa5' into vitest-x…
JCQuintas Dec 2, 2024
e38c84e
Merge commit 'd85fff19138b109a8d81655d55de62dbca2c6065' into vitest-x…
JCQuintas Jan 2, 2025
cdeda36
remove browser file mention
JCQuintas Jan 2, 2025
451c335
babel datefns
JCQuintas Jan 2, 2025
982e939
arrow functions
JCQuintas Jan 2, 2025
e1e0ea9
remove comments
JCQuintas Jan 2, 2025
0c04687
fix missed skip patterns
JCQuintas Jan 2, 2025
d1984a5
remove old pattern
JCQuintas Jan 2, 2025
15a057e
no return needed
JCQuintas Jan 2, 2025
ed81020
fix testskipif
JCQuintas Jan 2, 2025
e54ed0a
dedupe
JCQuintas Jan 2, 2025
b2c73f5
fix types
JCQuintas Jan 2, 2025
56c8f7e
datefns types
JCQuintas Jan 2, 2025
81a2390
fix test
JCQuintas Jan 2, 2025
5b86840
fix replace
JCQuintas Jan 2, 2025
0030cf7
use negative lookahead in datefns regexp
JCQuintas Jan 2, 2025
d796401
remove act warnings
JCQuintas Jan 2, 2025
d742e1a
fix act and remove unnecessary timers
JCQuintas Jan 2, 2025
87bf972
fix act in rows
JCQuintas Jan 2, 2025
73c5bb0
fix another act
JCQuintas Jan 2, 2025
4440524
fix act
JCQuintas Jan 2, 2025
4ab09dc
fix act
JCQuintas Jan 2, 2025
6f4194b
fix act
JCQuintas Jan 2, 2025
fbe8f10
fix act
JCQuintas Jan 2, 2025
5a1bb97
fix act
JCQuintas Jan 2, 2025
4e628db
fix act
JCQuintas Jan 2, 2025
ece6211
fix act
JCQuintas Jan 2, 2025
fbb59e5
fix act
JCQuintas Jan 2, 2025
c1caef1
act
JCQuintas Jan 3, 2025
d7db870
act
JCQuintas Jan 3, 2025
ee7522c
remove skip if
JCQuintas Jan 3, 2025
eb4fa2d
act
JCQuintas Jan 3, 2025
ed68a3d
act
JCQuintas Jan 3, 2025
cc7def7
act
JCQuintas Jan 3, 2025
e431909
act
JCQuintas Jan 3, 2025
8783db0
act
JCQuintas Jan 3, 2025
4e0a70f
act
JCQuintas Jan 3, 2025
dba0d1a
ensure time has passed
JCQuintas Jan 3, 2025
4a217e9
fixes
JCQuintas Jan 3, 2025
e1222d0
remove comment
JCQuintas Jan 3, 2025
c4590d2
Merge commit '513b8f6c404b0058636c625a4835f88c311f8468' into vitest-x…
JCQuintas Jan 3, 2025
e4e290a
IS_REACT_ACT_ENVIRONMENT and flaky tests
JCQuintas Jan 6, 2025
5140d87
fix timeout
JCQuintas Jan 6, 2025
717884e
update initial events
JCQuintas Jan 6, 2025
36397bb
use sleep for throttle
JCQuintas Jan 7, 2025
c26eba7
Merge commit '0a8dff6c944f928e8d8636b8f3df4f3731955e13' into vitest-x…
JCQuintas Jan 7, 2025
51279df
Merge commit '86d6e2a6660abc8aa8bbaa0f766aafd09ff3c8f7' into vitest-x…
JCQuintas Jan 8, 2025
2f5f809
mock fomatters
JCQuintas Jan 8, 2025
944e2b1
Merge commit '296a499c56404f7a35e0699865a694170be0842d' into vitest-x…
JCQuintas Jan 9, 2025
7c42626
Merge commit '6412b8c0a29f205a76a233ec4f07d89d179a4d8f' into vitest-x…
JCQuintas Jan 9, 2025
367629a
[AdapterDateFnsJalaliV2] Update mocks to use date-fns-jalali-v2 imports
JCQuintas Jan 14, 2025
e803e18
Merge commit 'bdd82aeac9faf01ad68ed2e8f3258c39fc29ee49' into vitest-x…
JCQuintas Jan 14, 2025
ff58b72
[test] Add long formatters mock for date-fns in AdapterDateFns tests
JCQuintas Jan 14, 2025
1b05f5a
adapters
JCQuintas Jan 14, 2025
61919e2
fix async
JCQuintas Jan 14, 2025
f6ef256
reset datefns legacy tests
JCQuintas Jan 14, 2025
d57a049
use vitest replace plugin instead of vi.mock due to typescript issues
JCQuintas Jan 14, 2025
94c1fcd
fix tests
JCQuintas Jan 14, 2025
314a9cc
fix datagrid test
JCQuintas Jan 14, 2025
f370f89
fix act warnings
JCQuintas Jan 14, 2025
3fbb79d
fix
JCQuintas Jan 14, 2025
406bf75
Merge branch 'master' into vitest-x-browser-working
JCQuintas Jan 14, 2025
f05cd7f
wait longer
JCQuintas Jan 14, 2025
f11f3df
individual configs
JCQuintas Jan 15, 2025
85df890
Merge commit '6dc3f848e886351d5c825d38381b25a3d1def904' into vitest-x…
JCQuintas Jan 15, 2025
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
52 changes: 52 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ 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 --reporter dot --project "jsdom/*" --coverage
- 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 @@ -272,6 +295,27 @@ jobs:
# hardcoded in karma-webpack
path: /tmp/_karma_webpack_
destination: artifact-file

test_browser_vitest:
<<: *default-job
docker:
- image: mcr.microsoft.com/playwright:v1.49.0-noble
resource_class: medium+
steps:
- checkout
- install_js:
browsers: true
- run:
name: Tests real browsers (vitest)
command: pnpm vitest --reporter dot --project "browser/*" --coverage
- run:
name: Check coverage generated
command: |
if ! [[ -s coverage/lcov.info ]]
then
exit 1
fi

test_types:
<<: *default-job
steps:
Expand Down Expand Up @@ -350,6 +394,10 @@ workflows:
<<: *default-context
requires:
- checkout
- test_unit_vitest:
<<: *default-context
requires:
- checkout
- test_lint:
<<: *default-context
requires:
Expand All @@ -362,6 +410,10 @@ workflows:
<<: *default-context
requires:
- checkout
- test_browser_vitest:
<<: *default-context
requires:
- checkout
- test_types:
<<: *default-context
requires:
Expand Down
14 changes: 7 additions & 7 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,7 +58,7 @@ 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}`],
files: [`packages/${root}/src/**/*.?(c|m)[jt]s?(x)`],
excludedFiles: [
'*.d.ts',
'*.spec.ts',
Expand Down Expand Up @@ -95,8 +95,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 @@ -251,8 +251,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 @@ -274,7 +274,7 @@ module.exports = {
},
},
{
files: ['docs/**/*{.ts,.tsx,.js}'],
files: ['docs/**/*.?(c|m)[jt]s?(x)'],
excludedFiles: ['*.d.ts'],
rules: {
'no-restricted-imports': [
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/vitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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

Copy link
Member

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? 🤔


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

permissions: {}

jobs:
vitest-jsdom:
name: Vitest Tests (jsdom)
runs-on: ubuntu-latest
timeout-minutes: 20
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
timeout-minutes: 20
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/*"
1 change: 1 addition & 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 Down
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ module.exports = function getBabelConfig(api) {
],
];

if (process.env.NODE_ENV === 'test') {
// TODO: Remove once vitest is our default runner
if (process.env.NODE_ENV === 'test' && process.env.VITEST !== 'true') {
plugins.push(['@babel/plugin-transform-export-namespace-from']);
// We replace `date-fns` imports with an aliased `date-fns@v2` version installed as `date-fns-v2` for tests.
plugins.push([
JCQuintas marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"esModuleInterop": true,
"incremental": true
"incremental": true,
"types": ["@mui/internal-test-utils/initMatchers", "chai-dom", "mocha"]
},
"include": ["next-env.d.ts", "next.config.mjs", "docs-env.d.ts", "src", "pages/**/*.ts*", "data"],
"exclude": ["docs/.next", "docs/export", "pages/playground"]
Expand Down
13 changes: 13 additions & 0 deletions docs/vitest.config.jsdom.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../vitest.shared.mts';
import packageJson from './package.json';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: `jsdom/${packageJson.name.split('/')[1]}`,
environment: 'jsdom',
},
}),
);
18 changes: 15 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,10 @@
"@octokit/plugin-retry": "^7.1.3",
"@octokit/rest": "^21.1.0",
"@playwright/test": "^1.49.1",
"@testing-library/dom": "^10.4.0",
"@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 @@ -117,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.8",
"@vitest/coverage-istanbul": "^2.1.8",
"autoprefixer": "^10.4.20",
"axe-core": "4.10.2",
"babel-loader": "^9.2.1",
Expand Down Expand Up @@ -191,14 +196,21 @@
"typescript": "^5.7.3",
"unist-util-visit": "^5.0.0",
"util": "^0.12.5",
"vite-plugin-filter-replace": "^0.1.14",
"vitest": "2.1.8",
"vitest-fail-on-console": "^0.7.1",
"webpack": "^5.97.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^6.0.1",
"yargs": "^17.7.2"
},
"resolutions": {
"react-is": "^19.0.0",
"@types/node": "^20.17.12"
"@types/node": "^20.17.12",
"@playwright/test": "1.49.1",
"playwright": "1.49.1",
"@vitest/browser>playwright": "1.49.1",
"@mui/internal-test-utils>playwright": "1.49.1"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
19 changes: 19 additions & 0 deletions packages/x-charts-pro/vitest.config.browser.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared.mts';
import packageJson from './package.json';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: `browser/${packageJson.name.split('/')[1]}`,
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
headless: true,
screenshotFailures: false,
},
},
}),
);
13 changes: 13 additions & 0 deletions packages/x-charts-pro/vitest.config.jsdom.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared.mts';
import packageJson from './package.json';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: `jsdom/${packageJson.name.split('/')[1]}`,
environment: 'jsdom',
},
}),
);
19 changes: 19 additions & 0 deletions packages/x-charts-vendor/vitest.config.browser.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared.mts';
import packageJson from './package.json';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: `browser/${packageJson.name.split('/')[1]}`,
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
headless: true,
screenshotFailures: false,
},
},
}),
);
13 changes: 13 additions & 0 deletions packages/x-charts-vendor/vitest.config.jsdom.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared.mts';
import packageJson from './package.json';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
name: `jsdom/${packageJson.name.split('/')[1]}`,
environment: 'jsdom',
},
}),
);
15 changes: 12 additions & 3 deletions packages/x-charts/src/BarChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,25 @@ const config = {
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 +30 to +40
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', () => {
// can't do Pointer event with JSDom https://github.com/jsdom/jsdom/issues/2527
testSkipIf(isJSDOM)('should provide the right context as second argument', () => {
const onAxisClick = spy();
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
Expand Down Expand Up @@ -85,7 +96,6 @@ describe('BarChart - click event', () => {
render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
Expand Down Expand Up @@ -157,7 +167,6 @@ describe('BarChart - click event', () => {
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
Loading