Skip to content

Commit 14da18d

Browse files
authored
Fix accessing the wrong user test configuration (#200)
1 parent 63373db commit 14da18d

File tree

7 files changed

+535
-42
lines changed

7 files changed

+535
-42
lines changed

.changeset/wise-taxis-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vite-plugin-solid': patch
3+
---
4+
5+
Fix accessing the wrong user test configuration

.github/workflows/vitest.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
vitest:
11+
name: 'Vitest'
12+
strategy:
13+
fail-fast: false
14+
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: '23'
22+
23+
- uses: pnpm/action-setup@v4
24+
with:
25+
version: 9.15.3
26+
27+
- name: Install project dependencies
28+
run: pnpm i
29+
30+
- name: Install playwright browser
31+
working-directory: examples/vite-6
32+
run: pnpm exec playwright install chromium
33+
34+
- name: Run tests
35+
working-directory: examples/vite-6
36+
run: pnpm run test

examples/vite-6/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
"dev": "vite",
77
"build": "vite build",
88
"preview": "vite preview",
9-
"test": "vitest"
9+
"test": "vitest --browser.headless --run",
10+
"test-dev": "vitest"
1011
},
1112
"devDependencies": {
1213
"@solidjs/testing-library": "^0.8.10",
1314
"@testing-library/jest-dom": "^6.6.3",
1415
"@testing-library/user-event": "^14.6.1",
15-
"jsdom": "^26.0.0",
16+
"@vitest/browser": "^3.0.7",
17+
"playwright": "^1.50.1",
1618
"vite": "^6.2.0",
1719
"vite-plugin-solid": "workspace:*",
1820
"vitest": "^3.0.7"

examples/vite-6/tests/App.test.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import { expect, test } from 'vitest';
1+
/// <reference types="@vitest/browser/providers/playwright" />
22
import { render } from '@solidjs/testing-library';
3-
import user from '@testing-library/user-event';
3+
import { page } from '@vitest/browser/context';
4+
import { expect, test } from 'vitest';
45

56
import App from '../src/App.jsx';
67

78
test('App', async () => {
8-
const { getByText } = render(() => <App />);
9-
10-
const counterTitle = getByText('Counter');
9+
const root = page.elementLocator(render(() => <App />).baseElement);
1110

12-
const count = counterTitle.nextElementSibling as HTMLElement;
13-
expect(count).instanceOf(HTMLElement);
14-
expect(count.innerHTML).toContain('Count: 0');
11+
const count = root.getByText('Count:');
12+
await expect.element(count).toHaveTextContent('Count: 0');
1513

16-
const incrementButton = getByText('Increment');
17-
await user.click(incrementButton);
18-
expect(count.innerHTML).toContain('Count: 1');
14+
const incrementButton = root.getByText('Increment');
15+
await incrementButton.click();
16+
await expect.element(count).toHaveTextContent('Count: 1');
1917

20-
const decrementButton = getByText('Decrement');
21-
await user.click(decrementButton);
22-
expect(count.innerHTML).toContain('Count: 0');
18+
const decrementButton = root.getByText('Decrement');
19+
await decrementButton.click();
20+
await expect.element(count).toHaveTextContent('Count: 0');
2321
});

examples/vite-6/vitest.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ export default defineConfig({
66
resolve: {
77
conditions: ['development', 'browser'],
88
},
9+
test: {
10+
environment: 'node',
11+
browser: {
12+
enabled: true,
13+
provider: 'playwright',
14+
instances: [{ browser: 'chromium' }],
15+
},
16+
},
917
});

0 commit comments

Comments
 (0)