-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[code-infra] vitest
browser & jsdom modes
#14508
base: master
Are you sure you want to change the base?
Changes from 35 commits
4497dd8
6539759
b20b1bb
840c4b6
6db68b8
9f6f828
a353cb6
1885222
f985554
b869545
739c2d4
8b38fd9
f5493b8
820bbd5
8342499
163ed7e
953059d
dac3923
ddc252d
8d28a7b
1d47d30
0e13811
88378a6
d32bfe5
dd40b0e
0bba870
f06ff48
5c57167
c264163
a1feb9b
3615198
8757aa4
9799824
ed6dbb8
7c62bfc
4f6b9c4
5442abd
aba0b63
5a930f1
8066b23
3bc1fa7
98013ae
f3b6d1f
7cf9c69
0098dbc
fa96d91
0085b9e
121bde4
dd2621b
fd39e32
a154440
10523ec
96d1d12
d86d6cf
9d486d6
3bfdce8
73b10fe
be83e61
1ff3ea1
1da790d
6a5056e
ee14aa5
9b4e396
1d38796
0bfd396
4788163
ff510c2
e5859c4
0ac9091
10d594d
ed4e45c
8143ff0
6145ec0
6137a65
2501941
0daad6b
ab3517c
399898f
ff30d99
9af685b
2750a58
9d49f6d
bc93279
b8d1d31
d3a6684
5058664
6a85d6f
dcb21c0
de5877b
c881448
20d745c
8edef9d
7e62e43
efd2e32
149bf34
69c594c
441b4ec
db141ec
3498128
d1bf2d4
9d8828a
f411f01
ebc3172
c9ad767
58681e0
4f9cc56
e040b42
25fafe2
71bf483
825d24f
43fea96
bdff27a
ff2846f
5a9c982
0b0a0c3
4797a30
d1c9d7e
dc988a6
608d851
d66936e
4438aa1
093f61e
8707b71
8302086
393db84
1b08251
5e2e9c0
73df0e5
ba2e15a
49010a8
70272b7
d265568
5cbc098
924da97
d0f94cd
f7fa812
c98fd74
f125aab
b8868bb
2364ccf
6f15cae
6408abe
c440d24
e38c84e
cdeda36
451c335
982e939
e1e0ea9
0c04687
d1984a5
15a057e
ed81020
e54ed0a
b2c73f5
56c8f7e
81a2390
5b86840
0030cf7
d796401
d742e1a
87bf972
73c5bb0
4440524
4ab09dc
6f4194b
fbe8f10
5a1bb97
4e628db
ece6211
fbb59e5
c1caef1
d7db870
ee7522c
eb4fa2d
ed68a3d
cc7def7
e431909
8783db0
4e0a70f
dba0d1a
4a217e9
e1222d0
c4590d2
e4e290a
5140d87
717884e
36397bb
c26eba7
51279df
2f5f809
944e2b1
7c42626
367629a
e803e18
ff58b72
1b05f5a
61919e2
f6ef256
d57a049
94c1fcd
314a9cc
f370f89
3fbb79d
406bf75
f05cd7f
f11f3df
85df890
b8fe822
8a06ca5
0ec2b5a
a857498
6c66bfe
1a8c3b1
cc788bf
0495a41
9708607
dd7d81f
a3340d9
d591723
a2123a0
12a33cc
8b70d36
ec169bb
0f417c8
b2ee3a1
dd9b531
28343a2
d51f71f
b89d56d
944a5f4
5ca3e01
de75e5f
491002e
c46e176
2c226c7
27e034f
ab99b4b
d796f8b
9c88ffc
e7de8e5
8b9a9c9
26e1354
5d64485
2913400
3dc36ee
1a653db
f0da929
371d8e4
82b4a8a
f1762c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Vitest | ||
|
||
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/*" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,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.10.1", | ||
|
@@ -100,6 +101,7 @@ | |
"@octokit/plugin-retry": "^7.1.1", | ||
"@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.19", | ||
|
@@ -117,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.1", | ||
"@vitest/browser": "^2.0.5", | ||
"autoprefixer": "^10.4.20", | ||
"axe-core": "4.10.0", | ||
"babel-loader": "^9.1.3", | ||
|
@@ -191,14 +195,18 @@ | |
"typescript": "^5.5.4", | ||
"unist-util-visit": "^5.0.0", | ||
"util": "^0.12.5", | ||
"vitest": "2.0.5", | ||
"webpack": "^5.94.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.5" | ||
"@types/node": "^20.16.5", | ||
"@playwright/test": "1.44.1", | ||
"playwright": "1.44.1", | ||
JCQuintas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@mui/internal-test-utils": "https://pkg.csb.dev/mui/material-ui/commit/ae23bac4/@mui/internal-test-utils" | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
|
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'; | ||
} | ||
}); | ||
Comment on lines
+30
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will see this pattern across multiple files, Without this mocha will fail because it waits for the This can then be migrated to just a .skip, but vitest offers many ways of skipping test. function test(t) {
if (isJSDOM) {
t.skip();
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a shim in The same couldn't be done for 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, | ||
}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CircleCI please: https://www.notion.so/mui-org/code-infra-Migrate-out-of-CircleCI-42350363b7344380a9961cf9731aae31 for the final version of this effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is just for ensuring the changes work while working on them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the GH workflow given that CircleCI is already setup? 🤔