Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
d69264c
Make createRenderer compliant with vitest
JCQuintas Sep 4, 2024
31326f9
Make describeConformance compliant with vitest
JCQuintas Sep 4, 2024
4db459c
Warning becomes too verbose
JCQuintas Sep 4, 2024
456df29
global this
JCQuintas Sep 5, 2024
76edd75
Fix chai matchers
JCQuintas Sep 5, 2024
5bea067
Merge commit '2ad38e3044063e60bdad98618997233b27383001' into vitest-c…
JCQuintas Sep 5, 2024
2a7343c
fix lint
JCQuintas Sep 5, 2024
c60515e
Fix mocha done
JCQuintas Sep 5, 2024
63115f5
add mocha types
JCQuintas Sep 5, 2024
e7e755b
Replace tobeundefined with tobenull
JCQuintas Sep 5, 2024
917dd25
separately export chai plugins
JCQuintas Sep 10, 2024
41cbeea
Revert "Fix chai matchers"
JCQuintas Sep 10, 2024
5fd0830
Merge commit 'dbc95b46cb0eff128872927aa3efcb9410fc46c6' into vitest-c…
JCQuintas Sep 10, 2024
8157404
Use vitest internal fake timers
JCQuintas Sep 11, 2024
0e74f56
only run useRealTimers if config
JCQuintas Sep 11, 2024
ae23bac
Invert running timers
JCQuintas Sep 11, 2024
bbd6fdd
Merge commit '94cc3d0a66456713e6e25edf9a1ba35ad8df88bc' into vitest-c…
JCQuintas Sep 11, 2024
ed66a3e
JCQuintas Sep 11, 2024
2284ad6
Merge commit 'e513ea36330c5222855130c8e3e6827901837f31' into vitest-c…
JCQuintas Sep 13, 2024
0648e94
Merge commit 'be68b0913c61eae68175c0b8d79c1b032fa383e4' into vitest-c…
JCQuintas Oct 4, 2024
e9f9582
Some updates
Janpot Oct 4, 2024
442770a
updates
Janpot Oct 5, 2024
4e4cf78
tweaks
Janpot Oct 5, 2024
ba7fd91
Update ButtonBase.test.js
Janpot Oct 5, 2024
9e8711c
fwfwr
Janpot Oct 5, 2024
e019f1a
Merge remote-tracking branch 'upstream/master' into pr/43625
Janpot Oct 7, 2024
d2b3f7f
tweaks
Janpot Oct 8, 2024
ccb3dd5
Update pnpm-lock.yaml
Janpot Oct 8, 2024
9e3c284
remove troublesome deprecated queries
JCQuintas Oct 8, 2024
a105b2a
Browser tests
Janpot Oct 9, 2024
39dc4f6
Update pnpm-lock.yaml
Janpot Oct 9, 2024
7db34a1
Merge remote-tracking branch 'upstream/master' into pr/43625
Janpot Oct 9, 2024
199bbef
Add describeSkipIf shim to test-utils
Janpot Oct 9, 2024
73c5415
Fix sequence
Janpot Oct 9, 2024
110d779
Update createRenderer.tsx
Janpot Oct 9, 2024
b67121a
Update setupVitest.ts
Janpot Oct 9, 2024
92c2399
Merge commit 'e802a736705e54e337f6f4ac165022465c61cc8c' into vitest-c…
JCQuintas Oct 14, 2024
6afd7c4
Expand tests
Janpot Oct 17, 2024
6224e16
Create vitest.config.ts
Janpot Oct 17, 2024
6e1c0a5
initMatchers
Janpot Oct 17, 2024
e512880
Update vitest.workspace.ts
Janpot Oct 17, 2024
d503f30
builder fixes
Janpot Oct 17, 2024
d4e0b02
wef
Janpot Oct 17, 2024
6baab86
Update builder.test.mjs
Janpot Oct 17, 2024
b6ab66d
Merge remote-tracking branch 'upstream/master' into pr/43625
Janpot Oct 17, 2024
7682b52
Update builder.test.mjs
Janpot Oct 17, 2024
eca4283
tests
Janpot Oct 17, 2024
f30b9a1
more tests
Janpot Oct 17, 2024
370470d
fix typescript
Janpot Oct 18, 2024
4eef12a
Merge remote-tracking branch 'upstream/master' into pr/43625
Janpot Oct 18, 2024
b955b6f
Merge commit '0ceedb8bc1f2f3bad9c6adf5a9d8f97a45a3c8b3' into vitest-c…
JCQuintas Nov 5, 2024
9aafe1d
add vitestSetup export
JCQuintas Nov 5, 2024
ef00405
Revert test changes
JCQuintas Nov 5, 2024
6c3ffa1
Revert "Revert test changes"
JCQuintas Nov 5, 2024
dc0210a
deduped
JCQuintas Nov 5, 2024
390881a
Merge commit '8a34771a34f6e029caa73cc055d14a125123dc3b' into vitest-t…
JCQuintas Nov 7, 2024
239006e
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 9, 2025
397be54
continue
Janpot May 12, 2025
bacc0b3
some fixes
Janpot May 13, 2025
5b2cd94
dwerfw
Janpot May 13, 2025
5db6b85
describeScipIf
Janpot May 13, 2025
062d040
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 13, 2025
2f3b275
WIP
Janpot May 14, 2025
e4baaf5
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 16, 2025
1fc88e0
fixes for @mui/material
Janpot May 16, 2025
976a0d2
fix not stopping
Janpot May 16, 2025
b706a63
reset async clock
Janpot May 16, 2025
4602685
dew
Janpot May 16, 2025
0196452
Update vitest.config.mts
Janpot May 16, 2025
06c1f19
Update pnpm-lock.yaml
Janpot May 16, 2025
2c67fd8
remove unnecessary changes
Janpot May 16, 2025
64414f6
fixes
Janpot May 16, 2025
38995d4
more
Janpot May 16, 2025
b99854d
prettier
Janpot May 17, 2025
db6d5c3
eslint
Janpot May 17, 2025
ecf6892
fixes
Janpot May 17, 2025
2edf2c0
fixes joy
Janpot May 17, 2025
df4ec10
Update createRenderer.tsx
Janpot May 18, 2025
ac40006
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 23, 2025
a090a2d
config
Janpot May 23, 2025
f940778
linters
Janpot May 23, 2025
dafad74
siplify
Janpot May 23, 2025
cda23a8
fix some tests
Janpot May 23, 2025
59aa946
node tests
Janpot May 23, 2025
4b7c440
Fix test
Janpot May 23, 2025
30d4a55
last fixes
Janpot May 28, 2025
1f9c60e
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 28, 2025
92a16fd
Update pnpm-lock.yaml
Janpot May 28, 2025
2fa4ac8
fix proptype tests
Janpot May 28, 2025
1aef91f
lockfile fix
Janpot May 28, 2025
0beef64
align versions
Janpot May 29, 2025
e1868fd
Add skipLibChecks
Janpot May 30, 2025
6bf5630
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot May 30, 2025
6901d7c
Update chai-augmentation.d.ts
Janpot May 30, 2025
17b9223
updates to include docs
Janpot May 30, 2025
b8a34f3
Create vitest.config.browser.mts
Janpot Jun 2, 2025
7f40b0d
Finishing up
Janpot Jun 2, 2025
569e7d8
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Jun 2, 2025
19898d9
remove weird rewrite
Janpot Jun 2, 2025
75c153a
stylelint
Janpot Jun 2, 2025
3912077
tests
Janpot Jun 2, 2025
81934e6
Update scritps
Janpot Jun 2, 2025
0217a90
Update top-level-imports.js
Janpot Jun 2, 2025
aa6a7d7
Update Tooltip.test.js
Janpot Jun 2, 2025
acf89a0
sme fix
Janpot Jun 2, 2025
1eb9f82
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Jun 2, 2025
360694b
Update pnpm-lock.yaml
Janpot Jun 2, 2025
c813781
async act
Janpot Jun 2, 2025
edcf699
Update Tooltip.test.js
Janpot Jun 2, 2025
8a57b86
revert
Janpot Jun 2, 2025
c823729
Update Tooltip.test.js
Janpot Jun 2, 2025
98974cc
Update Tooltip.test.js
Janpot Jun 2, 2025
057d5f1
Update Tooltip.test.js
Janpot Jun 2, 2025
f6be63d
Update typescript-to-proptypes.test.ts
Janpot Jun 2, 2025
1a01b60
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Jun 3, 2025
1528267
v5 in codemod tests
Janpot Jun 3, 2025
34735a3
Update pnpm-lock.yaml
Janpot Jun 3, 2025
5ab122b
Update top-level-imports.js
Janpot Jun 3, 2025
a27478c
update
Janpot Jun 3, 2025
9dd3c3a
Update top-level-imports.js
Janpot Jun 3, 2025
33029ee
Update config.yml
Janpot Jun 3, 2025
e3a2e58
Update config.yml
Janpot Jun 3, 2025
70ba8e1
Update Tooltip.test.js
Janpot Jun 3, 2025
dd65138
remove resolve nonsense
Janpot Jun 3, 2025
e4a005c
Update top-level-imports.test.js
Janpot Jun 3, 2025
0f327f9
fixes with act
Janpot Jun 3, 2025
4dfbf84
dewf
Janpot Jun 3, 2025
0885c39
Update config.yml
Janpot Jun 3, 2025
d593227
Update config.yml
Janpot Jun 3, 2025
59c0896
fixes
Janpot Jun 3, 2025
7af070b
Update config.yml
Janpot Jun 3, 2025
d140487
work on coverage
Janpot Jun 3, 2025
2a1e7d5
tweaking coverage
Janpot Jun 4, 2025
998a630
Update vitest.config.mts
Janpot Jun 4, 2025
bb0b3ca
Update vitest.config.mts
Janpot Jun 4, 2025
cfadcab
remove jsdom suffix
Janpot Jun 4, 2025
da52891
Update vitest.config.mts
Janpot Jun 4, 2025
7486bbc
Update MenuItem.test.js
Janpot Jun 4, 2025
996653e
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Jun 17, 2025
30dc6bd
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Jun 19, 2025
7363750
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Aug 6, 2025
0d1e699
Update pnpm-lock.yaml
Janpot Aug 6, 2025
140c0f8
Update
Janpot Aug 6, 2025
47ede64
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Aug 6, 2025
1fa4028
Update Select.test.js
Janpot Aug 6, 2025
35b53cc
lint/dedupe
Janpot Aug 6, 2025
380649d
test results for cci
Janpot Aug 6, 2025
b74ddc6
Update MenuItem.test.js
Janpot Aug 6, 2025
f983cdd
Update vitest.config.mts
Janpot Aug 6, 2025
f50bb39
Update vitest.shared.mts
Janpot Aug 6, 2025
f5db05c
Update vitest.shared.mts
Janpot Aug 6, 2025
8de9cdb
remove lodash
Janpot Aug 6, 2025
7d42864
Update chaiPlugin.ts
Janpot Aug 6, 2025
98a06b7
Update setupVitest.ts
Janpot Aug 6, 2025
f2ef6a1
Try and bump resource class
Janpot Aug 6, 2025
4b61528
Update config.yml
Janpot Aug 6, 2025
f261b56
Update config.yml
Janpot Aug 6, 2025
5b8f46e
Update MenuItem.test.js
Janpot Aug 6, 2025
c91323a
Update config.yml
Janpot Aug 6, 2025
23e5fea
Optimizing prepare more
Janpot Aug 6, 2025
66e2bec
Update vitest.shared.mts
Janpot Aug 6, 2025
a682961
fix
Janpot Aug 6, 2025
7c66619
update
Janpot Aug 7, 2025
e06eaab
screen
Janpot Aug 7, 2025
f118213
Update config.yml
Janpot Aug 8, 2025
a6c6a96
Update config.yml
Janpot Aug 8, 2025
718ee03
fix lint/dedupe
Janpot Aug 8, 2025
7884b69
fix no isloate
Janpot Aug 8, 2025
4d05233
Update config.yml
Janpot Aug 8, 2025
3be0c80
Update vitest.shared.mts
Janpot Aug 8, 2025
450187d
fix coverage
Janpot Aug 8, 2025
edc0a55
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Aug 21, 2025
6ec5b15
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Aug 25, 2025
5ebf6f6
remove screen export
Janpot Aug 25, 2025
eea61cc
Update Autocomplete.test.js
Janpot Aug 25, 2025
e3e29f6
Merge remote-tracking branch 'upstream/master' into pr/44325
Janpot Sep 10, 2025
7c6e874
Update createRenderer.tsx
Janpot Sep 10, 2025
6a2bcaa
kwdj
Janpot Sep 10, 2025
b19024b
defineProject
Janpot Sep 10, 2025
7962c9a
Update vitest.config.mts
Janpot Sep 10, 2025
290e2a3
Update createRenderer.tsx
Janpot Sep 10, 2025
b335fa3
fix jsdom env
Janpot Sep 10, 2025
1fbae7b
bring back screen
Janpot Sep 10, 2025
63bf417
remove accidentally committed
Janpot Sep 10, 2025
20e17d6
Merge branch 'master' into vitest-test-only-changes
Janpot Sep 10, 2025
f9c9749
Merge branch 'master' into vitest-test-only-changes
Janpot Sep 11, 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
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
- install_js
- run:
name: Tests fake browser
command: pnpm test:coverage:ci
command: pnpm test:node --no-isolate --no-file-parallelism --coverage
- run:
name: Check coverage generated
command: |
Expand Down Expand Up @@ -151,6 +151,8 @@ jobs:
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -Z -F "$REACT_VERSION-jsdom"
- store_test_results:
path: test-results
test_lint:
<<: *default-job
steps:
Expand Down Expand Up @@ -277,7 +279,7 @@ jobs:
browsers: true
- run:
name: Tests real browsers
command: pnpm test:karma
command: pnpm test:browser --coverage --no-file-parallelism
- run:
name: Check coverage generated
command: |
Expand All @@ -295,6 +297,8 @@ jobs:
# hardcoded in karma-webpack
path: /tmp/_karma_webpack_
destination: artifact-file
- store_test_results:
path: test-results
test_e2e:
<<: *default-job
docker:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ docs/public/static/blog/feed/*
.nx/workspace-data
screenshots
packed
test-results
2 changes: 1 addition & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
],
recursive: true,
timeout: (process.env.CIRCLECI === 'true' ? 5 : 2) * 1000, // Circle CI has low-performance CPUs.
reporter: 'dot',
reporter: 'spec',
require: ['@mui/internal-test-utils/setupBabel', '@mui/internal-test-utils/setupJSDOM'],
'watch-ignore': [
// default
Expand Down
4 changes: 2 additions & 2 deletions docs/src/theming.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, screen, fireEvent } from '@mui/internal-test-utils';
import { createRenderer, fireEvent } from '@mui/internal-test-utils';
import { ThemeProvider, createTheme, useColorScheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import { THEME_ID as JOY_THEME_ID, extendTheme } from '@mui/joy/styles';
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('docs demo theming', () => {
const { render } = createRenderer();

it('should inherit the theme.palette.mode from upper theme', () => {
render(
const screen = render(
<UpperProvider>
<DemoInstanceThemeProvider runtimeTheme={undefined}>
<Box
Expand Down
4 changes: 4 additions & 0 deletions docs/vitest.config.browser.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-relative-packages
import sharedConfig from '../vitest.shared.mts';

export default sharedConfig(import.meta.url);
4 changes: 4 additions & 0 deletions docs/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-relative-packages
import sharedConfig from '../vitest.shared.mts';

export default sharedConfig(import.meta.url, { jsdom: true });
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
"size:snapshot": "pnpm -F ./test/bundle-size check",
"size:why": "pnpm size:snapshot --analyze",
"start": "pnpm install && pnpm docs:dev",
"test": "node scripts/test.mjs",
"tc": "nx run nx_test_tc",
"test:attw": "pnpm run --parallel -r attw",
"test:extended": "pnpm eslint && pnpm typescript && pnpm test:coverage",
"test:coverage": "nx run nx_test_coverage",
"vitest": "vitest",
"test:coverage:ci": "nx run nx_test_coverage_ci",
"test:coverage:html": "nx run nx_test_coverage_html",
"test:e2e": "cross-env NODE_ENV=production pnpm test:e2e:build && concurrently --success first --kill-others \"pnpm test:e2e:run\" \"pnpm test:e2e:server\"",
Expand All @@ -76,7 +76,10 @@
"test:regressions-pigment-css:dev": "concurrently \"pnpm test:regressions-pigment-css:build --watch\" \"pnpm test:regressions-pigment-css:server\"",
"test:regressions-pigment-css:run": "nx run nx_test_regressions_pigment_css_run",
"test:regressions-pigment-css:server": "pnpm --filter @app/pigment-css-vite-app run preview --port 5001",
"test:unit": "nx run nx_test_unit",
"test": "pnpm test:node",
"test:unit": "cross-env TZ=UTC vitest",
"test:node": "cross-env TEST_SCOPE=node pnpm test:unit",
"test:browser": "cross-env TEST_SCOPE=browser pnpm test:unit",
"test:argos": "code-infra argos-push --folder test/regressions/screenshots/chrome",
"typescript": "lerna run --no-bail typescript",
"typescript:ci": "lerna run --concurrency 1 --no-bail typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages-internal/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build": "tsc -b tsconfig.json",
"release:publish": "pnpm build && pnpm publish --tag latest",
"release:publish:dry-run": "pnpm build && pnpm publish --tag latest --registry=\"http://localhost:4873/\"",
"test": "cd ../../ && cross-env NODE_ENV=test mocha --config packages-internal/scripts/typescript-to-proptypes/test/.mocharc.js 'packages-internal/scripts/typescript-to-proptypes/**/*.test.?(c|m)[jt]s?(x)' 'packages-internal/scripts/generate-llms-txt/**/*.test.?(c|m)[jt]s?(x)'",
"test": "pnpm --workspace-root test:unit --project \"*:@mui/internal-scripts\"",
"typescript": "tsc -b tsconfig.typecheck.json"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages-internal/scripts/tsconfig.typecheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"noEmit": true
},
"include": ["./**/*.ts"],
"exclude": ["./build", "./node_modules"],
"exclude": ["./build", "./node_modules", "vitest.config.ts"],
"references": [{ "path": "../../packages-internal/docs-utils/tsconfig.build.json" }]
}
4 changes: 4 additions & 0 deletions packages-internal/scripts/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-relative-packages
import sharedConfig from '../../vitest.shared.mts';

export default sharedConfig(import.meta.url);
1 change: 1 addition & 0 deletions packages-internal/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@types/chai": "^4.3.20",
"@types/chai-dom": "^1.11.3",
"@types/format-util": "^1.0.4",
"@types/jsdom": "^21.1.7",
"@types/prop-types": "^15.7.15",
"@types/react": "^19.1.11",
"@types/react-dom": "^19.1.7",
Expand Down
50 changes: 44 additions & 6 deletions packages-internal/test-utils/src/createRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { userEvent } from '@testing-library/user-event';
import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import { useFakeTimers } from 'sinon';
import { VitestUtils } from 'vitest';
import reactMajor from './reactMajor';

interface Interaction {
Expand Down Expand Up @@ -348,11 +349,28 @@ function createVitestClock(
defaultMode: 'fake' | 'real',
config: ClockConfig,
options: Exclude<Parameters<typeof useFakeTimers>[0], number | Date>,
vi: any,
vi: import('vitest').VitestUtils,
): Clock {
if (defaultMode === 'fake') {
beforeEach(() => {
vi.useFakeTimers(options);
vi.useFakeTimers({
now: config,
// useIsFocusVisible schedules a global timer that needs to persist regardless of whether components are mounted or not.
// Technically we'd want to reset all modules between tests but we don't have that technology.
// In the meantime just continue to clear native timers like with did for the past years when using `sinon` < 8.
shouldClearNativeTimers: true,
toFake: [
'setTimeout',
'setInterval',
'clearTimeout',
'clearInterval',
'requestAnimationFrame',
'cancelAnimationFrame',
'performance',
'Date',
],
...options,
});
if (config) {
vi.setSystemTime(config);
}
Expand All @@ -374,7 +392,27 @@ function createVitestClock(
return {
withFakeTimers: () => {
beforeEach(() => {
vi.useFakeTimers(options);
vi.useFakeTimers({
now: config,
// useIsFocusVisible schedules a global timer that needs to persist regardless of whether components are mounted or not.
// Technically we'd want to reset all modules between tests but we don't have that technology.
// In the meantime just continue to clear native timers like with did for the past years when using `sinon` < 8.
shouldClearNativeTimers: true,
toFake: [
'setTimeout',
'setInterval',
'clearTimeout',
'clearInterval',
'requestAnimationFrame',
'cancelAnimationFrame',
'performance',
'Date',
],
...options,
});
if (config) {
vi.setSystemTime(config);
}
});
afterEach(() => {
vi.useRealTimers();
Expand Down Expand Up @@ -511,7 +549,7 @@ export interface CreateRendererOptions extends Pick<RenderOptions, 'strict' | 's
* Vitest needs to be injected because this file is transpiled to commonjs and vitest is an esm module.
* @default {}
*/
vi?: any;
vi?: VitestUtils;
}

export function createRenderer(globalOptions: CreateRendererOptions = {}): Renderer {
Expand All @@ -520,7 +558,7 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
clockConfig,
strict: globalStrict = true,
strictEffects: globalStrictEffects = globalStrict,
vi = (globalThis as any).vi || {},
vi = (globalThis as any).vi as typeof import('vitest').vi | undefined,
clockOptions,
} = globalOptions;
// save stack to re-use in test-hooks
Expand Down Expand Up @@ -804,6 +842,6 @@ function act<T>(callback: () => void | T | Promise<T>) {

const bodyBoundQueries = within(document.body, { ...queries, ...customQueries });

export * from '@testing-library/react/pure';
export { renderHook, waitFor, within } from '@testing-library/react/pure';
export { act, fireEvent };
export const screen: Screen & typeof bodyBoundQueries = { ...rtlScreen, ...bodyBoundQueries };
59 changes: 4 additions & 55 deletions packages-internal/test-utils/src/setupVitest.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
import { beforeAll, afterAll, it } from 'vitest';
import * as testingLibrary from '@testing-library/dom';
import failOnConsole from 'vitest-fail-on-console';
import './initMatchers';
import * as chai from 'chai';
import './chai.types';
import chaiPlugin from './chaiPlugin';

// checking if an element is hidden is quite expensive
// this is only done in CI as a fail safe. It can still explicitly be checked
// in the test files which helps documenting what is part of the DOM but hidden
// from assistive technology
const defaultHidden = !process.env.CI;

// adds verbosity for something that might be confusing
console.warn(`${defaultHidden ? 'including' : 'excluding'} inaccessible elements by default`);

testingLibrary.configure({
// JSDOM logs errors otherwise on `getComputedStyle(element, pseudoElement)` calls.
computedStyleSupportsPseudoElements: false,
defaultHidden,
});

// Enable missing act warnings: https://github.com/reactwg/react-18/discussions/102
(globalThis as any).jest = null;
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
chai.use(chaiPlugin);

failOnConsole({
silenceMessage: (message) => {
Expand Down Expand Up @@ -80,38 +64,3 @@ if (!globalThis.after) {
if (!globalThis.specify) {
(globalThis as any).specify = wrappedIt;
}

const isJsdom = typeof window !== 'undefined' && window.navigator.userAgent.includes('jsdom');

// Only necessary when not in browser mode.
if (isJsdom) {
class Touch {
instance: any;

constructor(instance: any) {
this.instance = instance;
}

get identifier() {
return this.instance.identifier;
}

get pageX() {
return this.instance.pageX;
}

get pageY() {
return this.instance.pageY;
}

get clientX() {
return this.instance.clientX;
}

get clientY() {
return this.instance.clientY;
}
}
// @ts-expect-error
globalThis.window.Touch = Touch;
}
8 changes: 8 additions & 0 deletions packages-internal/test-utils/src/setupVitestBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as chai from 'chai';
import chaiDom from 'chai-dom';

chai.use(chaiDom);

// Enable missing act warnings: https://github.com/reactwg/react-18/discussions/102
(globalThis as any).jest = null;
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
81 changes: 81 additions & 0 deletions packages-internal/test-utils/src/setupVitestJsdom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { configure } from '@testing-library/dom';
import { JSDOM } from 'jsdom';

// We can use jsdom-global at some point if maintaining these lists is a burden.
const whitelist = [
// used by React's experimental cache API
// Always including it to reduce churn when switching between React builds
'AbortController',
// required for fake getComputedStyle
'CSSStyleDeclaration',
'Element',
'Event',
'TouchEvent',
'Image',
'HTMLElement',
'HTMLInputElement',
'Node',
'Performance',
'document',
'DocumentFragment',
];
const blacklist = new Set(['sessionStorage', 'localStorage']);

function initDom() {
if (globalThis.window) {
return;
}

const dom = new JSDOM('', {
pretendToBeVisual: true,
url: 'http://localhost',
});

(globalThis as any).window = dom.window;

// Not yet supported: https://github.com/jsdom/jsdom/issues/2152
class Touch {
instance: any;

constructor(instance: any) {
this.instance = instance;
}

get identifier() {
return this.instance.identifier;
}

get pageX() {
return this.instance.pageX;
}

get pageY() {
return this.instance.pageY;
}

get clientX() {
return this.instance.clientX;
}

get clientY() {
return this.instance.clientY;
}
}
(globalThis as any).window.Touch = Touch;

Object.keys(dom.window)
.filter((key) => !blacklist.has(key))
.concat(whitelist)
.forEach((key) => {
if (typeof (globalThis as any)[key] === 'undefined') {
(globalThis as any)[key] = dom.window[key];
}
});
}

initDom();

configure({
// JSDOM logs errors otherwise on `getComputedStyle(element, pseudoElement)` calls.
computedStyleSupportsPseudoElements: false,
});
4 changes: 4 additions & 0 deletions packages-internal/test-utils/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line import/no-relative-packages
import sharedConfig from '../../vitest.shared.mts';

export default sharedConfig(import.meta.url, { jsdom: true });
Loading
Loading