Skip to content

Commit bfbeed3

Browse files
authored
chore: use vitest browser instead of jsdom (#4121)
1 parent 3613f81 commit bfbeed3

10 files changed

Lines changed: 75 additions & 73 deletions

File tree

.changeset/quiet-eagles-attack.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
run: pnpm build
2323
- name: Types
2424
run: pnpm types:react
25-
25+
- name: Install playwright and run Storybook tests
26+
run: pnpm test:storybook
2627
- name: Test
2728
run: pnpm test
2829
- name: 'Report Coverage'
@@ -43,8 +44,6 @@ jobs:
4344
- name: Test CLI (create tokens, then build the theme)
4445
run: pnpm test:cli
4546

46-
- name: Install playwright and run Storybook tests
47-
run: pnpm test:storybook
4847
- name: Replace relative paths in test report
4948
uses: jacobtomlinson/gha-find-replace@f1069b438f125e5395d84d1c6fd3b559a7880cb5 # v3.0.5
5049
if: success() || failure()

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ next-env.d.ts
4242

4343
# jest/vitest test reports
4444
test-report.xml
45+
__screenshots__
4546

4647
packages/cli/temp
4748

internal/react-18-tests/vitest.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default defineProject({
2828
...baseConfig.test,
2929
env: {
3030
...baseConfig.test.env,
31-
REACT_VERSION: '18',
31+
VITE_REACT_VERSION: '18',
3232
},
3333
root: reactRoot,
3434
},

packages/react/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@testing-library/user-event": "^14.6.1",
6767
"@types/react": "^19.1.15",
6868
"@types/react-dom": "^19.1.9",
69-
"jsdom": "^26.1.0",
7069
"react": "^19.1.1",
7170
"react-dom": "^19.1.1",
7271
"rimraf": "^6.0.1",

packages/react/src/components/Combobox/Combobox.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,6 @@ describe('Combobox', () => {
372372
});
373373
const combobox = screen.getByRole('combobox');
374374

375-
expect(combobox).toHaveAccessibleName('CSS (Cascading Style Sheets)');
375+
expect(combobox).toHaveAccessibleName('CSS(Cascading Style Sheets)');
376376
});
377377
});

packages/react/vitest.config.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ export default defineProject({
1616
},
1717
test: {
1818
env: {
19-
REACT_VERSION: '19',
19+
VITE_REACT_VERSION: '19',
2020
},
2121
typecheck: {
2222
tsconfig: resolve(import.meta.dirname, 'tsconfig.tests.json'),
2323
},
2424
globals: true,
25-
environment: 'jsdom',
2625
setupFiles: ['../../test/vitest.setup.ts', './vitest.setup.ts'].map(
2726
(path) => resolve(import.meta.dirname, path),
2827
),
28+
browser: {
29+
enabled: true,
30+
instances: [{ browser: 'chromium' }],
31+
provider: 'playwright',
32+
headless: true,
33+
},
2934
},
3035
});

packages/react/vitest.setup.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@ import { configure } from '@testing-library/react';
22
import { version as reactVersion } from 'react';
33
import { version as reactDomVersion } from 'react-dom';
44

5-
const expectedVersion = process.env.REACT_VERSION;
5+
interface ImportMetaEnv {
6+
VITE_REACT_VERSION?: string;
7+
}
8+
9+
declare global {
10+
interface ImportMeta {
11+
env: ImportMetaEnv;
12+
}
13+
}
14+
15+
const expectedVersion = import.meta.env.VITE_REACT_VERSION;
16+
617
if (expectedVersion) {
718
if (!reactVersion.startsWith(expectedVersion)) {
819
throw new Error(
@@ -14,6 +25,8 @@ if (expectedVersion) {
1425
`Expected react-dom v${expectedVersion}, but found v${reactDomVersion}`,
1526
);
1627
}
28+
} else {
29+
throw new Error('VITE_REACT_VERSION is not defined');
1730
}
1831

1932
configure({ reactStrictMode: true });

pnpm-lock.yaml

Lines changed: 46 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)