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

Draft
wants to merge 535 commits into
base: master
Choose a base branch
from
Draft
Changes from 104 commits
Commits
Show all changes
535 commits
Select commit Hold shift + click to select a range
9708607
config
JCQuintas Jan 20, 2025
dd7d81f
datepickers pro changes
JCQuintas Jan 20, 2025
a3340d9
date pickers
JCQuintas Jan 20, 2025
d591723
remove old settings
JCQuintas Jan 20, 2025
a2123a0
vitest 3 config
JCQuintas Jan 20, 2025
12a33cc
config
JCQuintas Jan 21, 2025
8b70d36
Merge commit '099602fcbd1e4a0c9b7a9b9a7b266fe2e7f08fa7' into vitest-x…
JCQuintas Jan 31, 2025
ec169bb
dedupe
JCQuintas Jan 31, 2025
0f417c8
changes
JCQuintas Jan 31, 2025
b2ee3a1
Merge commit 'f5f750567470094bcd21e301aca3a8438aa6865e' into vitest-x…
JCQuintas Feb 3, 2025
dd9b531
fix issues
JCQuintas Feb 3, 2025
28343a2
setup vitest
JCQuintas Feb 3, 2025
d51f71f
fix exclusion
JCQuintas Feb 3, 2025
b89d56d
grid
JCQuintas Feb 3, 2025
944a5f4
date pickers
JCQuintas Feb 3, 2025
5ca3e01
get rid of fake clock usage
JCQuintas Feb 3, 2025
de75e5f
remove unnecessary prop
JCQuintas Feb 3, 2025
491002e
fixes
JCQuintas Feb 3, 2025
c46e176
proper config
JCQuintas Feb 3, 2025
2c226c7
changes
JCQuintas Feb 3, 2025
27e034f
Merge commit '29d6148f66780c222f5bd829e869d38a6acc9ae8' into vitest-x…
JCQuintas Feb 3, 2025
ab99b4b
fix playwright version
JCQuintas Feb 3, 2025
d796f8b
1 concurrent
JCQuintas Feb 3, 2025
9c88ffc
fix lint
JCQuintas Feb 3, 2025
e7de8e5
run charts and treeview
JCQuintas Feb 3, 2025
8b9a9c9
tsconfig
JCQuintas Feb 3, 2025
26e1354
test without coverage
JCQuintas Feb 3, 2025
5d64485
fix date utils tests
JCQuintas Feb 4, 2025
2913400
fix datagrid scroll size
JCQuintas Feb 4, 2025
3dc36ee
date pickers
JCQuintas Feb 4, 2025
1a653db
packagelock
JCQuintas Feb 4, 2025
f0da929
add timeout
JCQuintas Feb 4, 2025
371d8e4
vitest options
JCQuintas Feb 4, 2025
82b4a8a
try hover
JCQuintas Feb 4, 2025
f1762c2
Merge branch 'master' into vitest-x-browser-working
JCQuintas Feb 4, 2025
3e885a8
Merge remote-tracking branch 'origin/master' into vitest-x-browser-wo…
JCQuintas Feb 13, 2025
8e37734
fix vers
JCQuintas Feb 13, 2025
169e333
test node 22
JCQuintas Feb 13, 2025
ad29b23
revert node change
JCQuintas Feb 13, 2025
3325f0b
use userevent
JCQuintas Feb 13, 2025
36ed5f5
fix flakyness
JCQuintas Feb 13, 2025
8ae56fa
fix pagesize change test
JCQuintas Feb 13, 2025
0263c16
try threads
JCQuintas Feb 13, 2025
3ebee86
fix options
JCQuintas Feb 13, 2025
a1dd2e7
matrix fun
JCQuintas Feb 13, 2025
3bfbb80
fix config
JCQuintas Feb 13, 2025
3834dda
default params
JCQuintas Feb 13, 2025
172c424
fix package names
JCQuintas Feb 13, 2025
7be271e
fix lint
JCQuintas Feb 13, 2025
32bcb6e
config
JCQuintas Feb 13, 2025
426819e
config
JCQuintas Feb 13, 2025
0bd6c3e
divide packages
JCQuintas Feb 14, 2025
78856fc
packages
JCQuintas Feb 14, 2025
f403c45
fix type error
JCQuintas Feb 14, 2025
3a4b451
Merge remote-tracking branch 'upstream/master' into vitest-x-browser-…
JCQuintas Feb 14, 2025
beeb6e6
try default hidden
JCQuintas Feb 17, 2025
6e643eb
dedupe
JCQuintas Feb 17, 2025
6df7b9d
Revert "try default hidden"
JCQuintas Feb 17, 2025
4033d6f
Merge commit 'e56a3812c1523791f7bbf859c485c2308cb7da09' into vitest-x…
JCQuintas Feb 19, 2025
c13114e
fixes
JCQuintas Feb 19, 2025
57ea710
fix config
JCQuintas Feb 19, 2025
588475a
divide datepickers tests
JCQuintas Feb 19, 2025
ecc2eca
dedupe
JCQuintas Feb 19, 2025
bd96dd3
return pool options
JCQuintas Feb 19, 2025
fab6556
try large containers
JCQuintas Feb 19, 2025
b8534f4
log heap usage
JCQuintas Feb 19, 2025
fe31823
log heap
JCQuintas Feb 19, 2025
e67608e
use fake timers
JCQuintas Feb 20, 2025
2afd4c9
revert regressions
JCQuintas Feb 20, 2025
7b794ff
m+
JCQuintas Feb 20, 2025
c3f4db9
medium
JCQuintas Feb 20, 2025
b567b88
max workers 2
JCQuintas Feb 20, 2025
6b38c59
m+
JCQuintas Feb 20, 2025
22f2cbf
large
JCQuintas Feb 20, 2025
8e22aaf
fix act warnings
JCQuintas Feb 20, 2025
a04cad1
divide tests
JCQuintas Feb 20, 2025
acb092f
Merge commit '50e5eedc0f8d6a18be01b1313efbdef6e6cc1479' into vitest-x…
JCQuintas Feb 20, 2025
8d657d0
retry flaky test
JCQuintas Feb 20, 2025
ca21a6e
fix types
JCQuintas Feb 20, 2025
1ae2dc3
remove gha
JCQuintas Feb 20, 2025
a1c3e41
increase timeout and retry
JCQuintas Feb 20, 2025
af8e372
separate files
JCQuintas Feb 20, 2025
23e55bd
createRenderer without profiling
JCQuintas Feb 20, 2025
e2ec21b
ci vars
JCQuintas Feb 20, 2025
661bf0b
Revert "createRenderer without profiling"
JCQuintas Feb 20, 2025
434e2d2
check no profile
JCQuintas Feb 20, 2025
d33772a
Merge commit 'f663e70a6ff1d6cc323f9e2002aaad0264830629' into vitest-x…
JCQuintas Feb 21, 2025
85cb1fe
try scrollTo
JCQuintas Feb 21, 2025
46bcb69
remove unnecessary override
JCQuintas Feb 25, 2025
c9fa5e1
skip test
JCQuintas Feb 25, 2025
6f9e916
skip tests
JCQuintas Feb 26, 2025
d1ac98d
skip test
JCQuintas Feb 26, 2025
642e4ef
skip all in browser
JCQuintas Feb 26, 2025
ca4eaba
ignore all in browser
JCQuintas Feb 26, 2025
0f8c8cf
remove parallelism
JCQuintas Feb 26, 2025
e9853e0
fix date pickers isolation issues
JCQuintas Feb 26, 2025
11fa02b
fix datagrid isolate
JCQuintas Feb 26, 2025
a352883
fix datepickers pro isolate
JCQuintas Feb 26, 2025
1f80763
datagrid test isolate
JCQuintas Feb 26, 2025
fe0b0d6
fix charts isolate
JCQuintas Feb 26, 2025
edd2907
turn on isolate ci
JCQuintas Feb 26, 2025
abcb953
Merge commit '3697464969746f746e17342bf97cff79657dfd71' into vitest-x…
JCQuintas Feb 26, 2025
da00ea5
update packages
JCQuintas Feb 26, 2025
001e933
fix ci
JCQuintas Feb 26, 2025
dda8ecd
fix test
JCQuintas Feb 26, 2025
e17895d
add telemetry tests
JCQuintas Feb 26, 2025
f87f521
try fixes
JCQuintas Feb 26, 2025
66dc80b
try closing dialog after test
JCQuintas Feb 26, 2025
36664df
Merge branch 'master' into vitest-x-browser-working
JCQuintas Feb 26, 2025
7b7c193
remove changes
JCQuintas Feb 26, 2025
45c6a1a
fix matchmedia
JCQuintas Feb 26, 2025
533665b
m+
JCQuintas Feb 26, 2025
701bd9c
increase timeout for tests
JCQuintas Feb 26, 2025
d34359c
increase worker
JCQuintas Feb 26, 2025
aaa574f
decrease workers
JCQuintas Feb 26, 2025
9038bed
revert
JCQuintas Feb 26, 2025
f6257e4
decrease timeout
JCQuintas Feb 26, 2025
6d30ab1
add act on focus
JCQuintas Feb 27, 2025
522819b
use vmthreads
JCQuintas Feb 27, 2025
2f04cd7
env stubbing and threads
JCQuintas Feb 27, 2025
bd37ddf
fix type
JCQuintas Feb 27, 2025
3d25a4b
large
JCQuintas Feb 27, 2025
3b7044a
back to forks
JCQuintas Feb 27, 2025
106cf06
try preventing issue in charts
JCQuintas Feb 27, 2025
5c1c485
Merge commit 'ca5f2a04ebba7b4a3a31358f8e656a8d833d41c6' into vitest-x…
JCQuintas Feb 27, 2025
7ba5dbd
run on medium with single thread
JCQuintas Feb 27, 2025
12a557f
add fail on console
JCQuintas Feb 27, 2025
44b7a0a
decrease to medium
JCQuintas Feb 27, 2025
bf5ff4b
mw2
JCQuintas Feb 27, 2025
3df9fb5
big test timetout
JCQuintas Feb 27, 2025
c47e28e
disable parallelism
JCQuintas Feb 27, 2025
c0ee4a5
move to ci
JCQuintas Feb 27, 2025
445a754
comment
JCQuintas Feb 27, 2025
4ffa9f1
Merge commit '519dad717f84c43d38b66d6c8fe67f2800246e2c' into vitest-x…
JCQuintas Feb 27, 2025
74d97ef
remove global vi
JCQuintas Feb 27, 2025
c6484db
remove matrix
JCQuintas Feb 27, 2025
332a58e
speedup by removing checkout requirement
JCQuintas Feb 27, 2025
c2a78ff
upgrade vitest
JCQuintas Feb 27, 2025
d24941b
enable coverage
JCQuintas Feb 27, 2025
f7af0bb
make retry global
JCQuintas Feb 27, 2025
bd28140
remove fake clock
JCQuintas Feb 27, 2025
b62b902
remove "createFakeClock"
JCQuintas Feb 27, 2025
1de5e03
Merge commit '7eb128d9c968ea9bf3a029f8b041d41d53f168c6' into vitest-x…
JCQuintas Feb 28, 2025
42de77d
fix fake clock tests
JCQuintas Feb 28, 2025
0d66e4e
render
JCQuintas Feb 28, 2025
67a8d5a
fix wrong date
JCQuintas Feb 28, 2025
db7ede4
fix missing fake clock
JCQuintas Feb 28, 2025
a3145c1
fix waitfor
JCQuintas Feb 28, 2025
2a7508a
Merge commit 'd8d707171cda79e168c89df3474587b9322a2695' into vitest-x…
JCQuintas Mar 4, 2025
657a5ea
act and vi timers
JCQuintas Mar 4, 2025
71729a9
fix datapickers
JCQuintas Mar 4, 2025
2acfb89
Merge commit 'e895436e50fa006e1ebe7e79cf99d9f48e7d0bb2' into vitest-x…
JCQuintas Mar 4, 2025
775a4cd
Merge commit '03c32eba5313d0c71acf438941411c7641f9b72f' into vitest-x…
JCQuintas Mar 6, 2025
288eb22
fix merge issues
JCQuintas Mar 6, 2025
00da37e
Merge commit '7c80083adc800324accee8288cb6c4a58c033f55' into vitest-x…
JCQuintas Mar 6, 2025
a28374e
revert unnecessary changes
JCQuintas Mar 6, 2025
eed8451
Merge commit '53bf0013401abf2e0fe11a48a1080783a42b94b0' into vitest-x…
JCQuintas Mar 11, 2025
cc32291
dedupe
JCQuintas Mar 11, 2025
b255641
upgrade vitest
JCQuintas Mar 11, 2025
34feadf
remove unnecessary async
JCQuintas Mar 11, 2025
d1e04a2
fix grid new column menu names
JCQuintas Mar 11, 2025
fab8abb
fix issues
JCQuintas Mar 11, 2025
3f9e03b
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 11, 2025
6d10490
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 12, 2025
950d9f0
Merge commit '06d8025ed7b5eb14b4d125924b4eeefea9af12a2' into vitest-x…
JCQuintas Mar 12, 2025
b27c461
remove clock usage
JCQuintas Mar 12, 2025
2e1a05a
Revert "remove unnecessary async"
JCQuintas Mar 12, 2025
c5fccba
try awaiting datagrid
JCQuintas Mar 13, 2025
67c8dd7
fix react 18 unit test
JCQuintas Mar 13, 2025
f951e15
Revert "Revert "remove unnecessary async""
JCQuintas Mar 13, 2025
6603ffc
split editing keyboard
JCQuintas Mar 13, 2025
0579e1a
fix isolate browser
JCQuintas Mar 13, 2025
c564086
Merge commit '586a1c21edac8e2fb10d39548e998df658907a71' into vitest-x…
JCQuintas Mar 13, 2025
fa52763
remove overrides
JCQuintas Mar 13, 2025
f766204
revert hijri changes
JCQuintas Mar 13, 2025
be3a31f
revert hijri changes
JCQuintas Mar 13, 2025
6484f59
fix removing keys
JCQuintas Mar 14, 2025
3aa733b
Merge commit '3d7e504636461c485c798a32d9c2a7be760f9fb8' into vitest-x…
JCQuintas Mar 20, 2025
0758884
vitest upgrade
JCQuintas Mar 20, 2025
cf9d282
fixes
JCQuintas Mar 20, 2025
472e323
fix interaction
JCQuintas Mar 20, 2025
90a37c6
fix date
JCQuintas Mar 20, 2025
06c8e47
fixes
JCQuintas Mar 20, 2025
a2f15b7
fix re-render issue on use series
JCQuintas Mar 20, 2025
088dbc8
fix act warnings
JCQuintas Mar 20, 2025
9782168
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 20, 2025
5f001e3
fix act warnings
JCQuintas Mar 20, 2025
4c71514
allow trigger none tooltip
JCQuintas Mar 20, 2025
6900304
fix grid test
JCQuintas Mar 20, 2025
f0465b5
fix heatmap tooltip issue on hooks
JCQuintas Mar 20, 2025
9cadb47
use v8 coverage
JCQuintas Mar 20, 2025
0f9a1e1
dedupe
JCQuintas Mar 20, 2025
0e5d7d4
remove istanbul
JCQuintas Mar 20, 2025
6881ecf
how fast goes fast
JCQuintas Mar 20, 2025
1014ffe
remove paralelism
JCQuintas Mar 20, 2025
bf2d395
fix workers
JCQuintas Mar 20, 2025
bf91c4d
min/max workers
JCQuintas Mar 20, 2025
66827f1
large runner
JCQuintas Mar 20, 2025
8b97b4f
large
JCQuintas Mar 20, 2025
4a94b0f
large
JCQuintas Mar 20, 2025
94f5179
medium
JCQuintas Mar 20, 2025
046d9a5
lcov only in ci
JCQuintas Mar 20, 2025
ff4839f
remove useless file
JCQuintas Mar 20, 2025
694ff3c
run coverage only on browser react-stable
JCQuintas Mar 20, 2025
cabde14
m+ browser
JCQuintas Mar 20, 2025
dbd7618
browser medium cov
JCQuintas Mar 20, 2025
655dc9c
try hanging reporters
JCQuintas Mar 20, 2025
2c2cffe
revert change
JCQuintas Mar 20, 2025
e6bf33d
Merge commit 'a95be3e3630038372947b1e0ce86f3bd076f64de' into vitest-x…
JCQuintas Mar 20, 2025
72469d5
hanging process
JCQuintas Mar 20, 2025
5798225
run again
JCQuintas Mar 21, 2025
d4f7602
Merge commit '4029bd44ddb20dd6d234ca653a3a1307ce899801' into vitest-x…
JCQuintas Mar 21, 2025
f2e674e
Merge commit '077fef10704956b8463e014816486712b95dfdea' into vitest-x…
JCQuintas Mar 21, 2025
818eb96
revert change
JCQuintas Mar 21, 2025
1c823e7
try debug
JCQuintas Mar 21, 2025
cf44d28
debug
JCQuintas Mar 21, 2025
60b754f
dot reporter
JCQuintas Mar 21, 2025
2bfe2fa
Merge commit '57e61921452fa97ee430580895da54bf4bd94e85' into vitest-x…
JCQuintas Mar 21, 2025
6651e15
config
JCQuintas Mar 21, 2025
cb69c03
Merge commit '8e9f30168042adb6dc979d74087c53e955cfed85' into vitest-x…
JCQuintas Mar 21, 2025
8b49daa
heatmap async
JCQuintas Mar 21, 2025
90d399d
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 21, 2025
c653d01
try newer node
JCQuintas Mar 21, 2025
7ccff0e
try vmthreads
JCQuintas Mar 21, 2025
21effe6
reverts
JCQuintas Mar 21, 2025
b118a0c
Merge commit '3d47060e773edb4a5dc86e13a97aa876638fd7fb' into vitest-x…
JCQuintas Mar 21, 2025
9442953
medium+ browser
JCQuintas Mar 21, 2025
63bebdf
codecov browser
JCQuintas Mar 21, 2025
e6a59b1
fixes
JCQuintas Mar 21, 2025
09d6c38
use v8 ignore instead of istambul
JCQuintas Mar 21, 2025
e16d6af
Merge commit '02b7334fb5b2169d666ad96c2b4fc796d2cebcf0' into vitest-x…
JCQuintas Mar 21, 2025
9a85e68
comment code again
JCQuintas Mar 22, 2025
c87bf05
Merge commit '14324de82af267a39626cb02575f624011bc59d9' into vitest-x…
JCQuintas Mar 23, 2025
013aa2f
revert changes
JCQuintas Mar 23, 2025
f95e878
Merge commit '128c20ff0d5ba05b05edaec69fbf8135c0d54c71' into vitest-x…
JCQuintas Mar 24, 2025
9e9a147
use esbuild keepnames
JCQuintas Mar 24, 2025
eace5e8
Merge commit '086e9549901463ab3e5838407e381722a47e5a86' into vitest-x…
JCQuintas Mar 24, 2025
32f8f68
fix quickfilter
JCQuintas Mar 24, 2025
20dc412
add waitfor
JCQuintas Mar 24, 2025
5b5923e
fix
JCQuintas Mar 24, 2025
c761c7e
stub
JCQuintas Mar 24, 2025
1e6e65b
stub matchmedia
JCQuintas Mar 24, 2025
bc599b7
change usage
JCQuintas Mar 24, 2025
91fb565
revert react18 changes
JCQuintas Mar 24, 2025
eae931a
proper v8 ignore
JCQuintas Mar 24, 2025
1611caa
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 24, 2025
ae3804a
fix codecov config for adapters
JCQuintas Mar 24, 2025
3011fe3
Merge branch 'master' into vitest-x-browser-working
JCQuintas Mar 25, 2025
31bb49e
Merge commit '8403fe1dc8c3f6e6f6ef0b424fb61da8a01d8c32' into vitest-x…
JCQuintas Mar 26, 2025
48f6df6
Merge commit '56a53a2126a1ea3496a748d514d2628936ca4366' into vitest-x…
JCQuintas Mar 26, 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
18 changes: 12 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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',
},
@@ -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', '*.spec.tsx', '**.test.tx', '**.test.tsx'],
rules: {
'no-restricted-imports': [
@@ -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: {
@@ -244,7 +244,7 @@ module.exports = {
},
},
{
files: ['packages/*/src/**/*{.ts,.tsx,.js}'],
files: ['packages/*/src/**/*.?(c|m)[jt]s?(x)'],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx'],
rules: {
'material-ui/mui-name-matches-component-name': [
@@ -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': [
@@ -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),
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

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
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/*"
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: [
@@ -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}',
'packages/**/*.jsdom.test.{js,ts,tsx,jsx}',
],
recursive: true,
timeout: (process.env.CIRCLECI === 'true' ? 5 : 2) * 1000, // Circle CI has low-performance CPUs.
8 changes: 4 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -106,17 +106,17 @@ module.exports = function getBabelConfig(api) {
plugins.push([
'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/babel-plugin-replace-imports@1.0.2.patch` 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/babel-plugin-replace-imports@1.0.2.patch` patch
filenameIncludes: 'src/AdapterDateFnsJalaliV3/',
},
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@
"release:publish:dry-run": "pnpm publish --recursive --tag latest --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",
@@ -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.8",
@@ -118,6 +119,8 @@
"@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",
"autoprefixer": "^10.4.20",
"axe-core": "4.10.0",
"babel-loader": "^9.2.1",
@@ -192,14 +195,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.16.10"
"@types/node": "^20.16.10",
"@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"
},
"packageManager": "pnpm@9.12.0",
"engines": {
33 changes: 24 additions & 9 deletions packages/x-charts/src/BarChart/checkClickEvent.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
}
});
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();
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,
}}
@@ -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,
}}
@@ -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,
}}
40 changes: 28 additions & 12 deletions packages/x-charts/src/ChartsTooltip/contentDisplayed.test.tsx
Original file line number Diff line number Diff line change
@@ -27,17 +27,30 @@ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
describe('ChartsTooltip', () => {
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';
}
});

describe('axis trigger', () => {
it('should show right values with vertical layout', function test() {
it('should show right values with vertical layout', 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();
}

render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
@@ -93,16 +106,17 @@ describe('ChartsTooltip', () => {
]);
});

it('should show right values with horizontal layout', function test() {
it('should show right values with horizontal layout', 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();
}

render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
@@ -161,16 +175,17 @@ describe('ChartsTooltip', () => {
});

describe('item trigger', () => {
it('should show right values with vertical layout', function test() {
it('should show right values with vertical layout', 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();
}

render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
@@ -204,16 +219,17 @@ describe('ChartsTooltip', () => {
expect([...cells].map((cell) => cell.textContent)).to.deep.equal(['', 'S2', '1']);
});

it('should show right values with horizontal layout', function test() {
it('should show right values with horizontal layout', 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();
}

render(
<div
style={{
margin: -8, // Removes the body default margins
width: 400,
height: 400,
}}
Loading