From d0e47f165d8019cb8db402986e8e81fcf3f1bfc2 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Mon, 19 Oct 2026 07:25:23 +0000 Subject: [PATCH] fix: keep the Vitest test config when solid-js is already external --- .../keep-test-config-with-external-solid.md | 5 +++ .github/workflows/vitest.yml | 3 ++ package.json | 6 ++- pnpm-lock.yaml | 37 ++++++++++++++++++- src/index.ts | 2 +- src/test-config.test.ts | 26 +++++++++++++ tsconfig.json | 2 +- vitest.config.ts | 10 +++++ 8 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 .changeset/keep-test-config-with-external-solid.md create mode 100644 src/test-config.test.ts create mode 100644 vitest.config.ts diff --git a/.changeset/keep-test-config-with-external-solid.md b/.changeset/keep-test-config-with-external-solid.md new file mode 100644 index 00000000..ad73b1fd --- /dev/null +++ b/.changeset/keep-test-config-with-external-solid.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-solid': patch +--- + +Vitest runs keep the `jsdom` environment and the `@testing-library/jest-dom` setup file when `test.server.deps.external` already lists `solid-js`. The plugin used to drop its whole `test` config in that case. diff --git a/.github/workflows/vitest.yml b/.github/workflows/vitest.yml index fc062d92..aad075ac 100644 --- a/.github/workflows/vitest.yml +++ b/.github/workflows/vitest.yml @@ -27,6 +27,9 @@ jobs: - name: Install project dependencies run: pnpm i + - name: Run unit tests + run: pnpm run test:unit + - name: Install playwright browser working-directory: examples/vite-6 run: pnpm exec playwright install chromium diff --git a/package.json b/package.json index a2662f89..cba7d046 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "prepublishOnly": "pnpm build", "release": "pnpm build && changeset publish", "check": "package-check", - "test": "node scripts/test-examples.ts" + "test": "node scripts/test-examples.ts", + "test:unit": "vitest run" }, "repository": { "type": "git", @@ -68,7 +69,8 @@ "rollup-plugin-cleaner": "^1.0.0", "solid-js": "^1.9.3", "typescript": "^5.2.2", - "vite": "^6.0.0" + "vite": "^6.0.0", + "vitest": "^3.0.7" }, "peerDependencies": { "@testing-library/jest-dom": "^5.16.6 || ^5.17.0 || ^6.0.0 || ^7.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eed12c18..23823a84 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -90,6 +90,9 @@ importers: vite: specifier: ^6.0.0 version: 6.0.9(@types/node@18.19.66)(lightningcss@1.32.0) + vitest: + specifier: ^3.0.7 + version: 3.0.7(@types/node@18.19.66)(@vitest/browser@3.0.7)(jsdom@26.0.0(supports-color@8.1.1))(lightningcss@1.32.0)(msw@2.7.3(@types/node@18.19.66)(typescript@5.7.2))(supports-color@8.1.1) examples/vite-3: dependencies: @@ -5968,6 +5971,28 @@ snapshots: '@types/node': 18.19.66 optional: true + '@vitest/browser@3.0.7(@types/node@18.19.66)(playwright@1.50.1)(typescript@5.7.2)(vite@6.0.9(@types/node@18.19.66)(lightningcss@1.32.0))(vitest@3.0.7)': + dependencies: + '@testing-library/dom': 10.4.0 + '@testing-library/user-event': 14.6.1(@testing-library/dom@10.4.0) + '@vitest/mocker': 3.0.7(msw@2.7.3(@types/node@18.19.66)(typescript@5.7.2))(vite@6.0.9(@types/node@18.19.66)(lightningcss@1.32.0)) + '@vitest/utils': 3.0.7 + magic-string: 0.30.17 + msw: 2.7.3(@types/node@18.19.66)(typescript@5.7.2) + sirv: 3.0.1 + tinyrainbow: 2.0.0 + vitest: 3.0.7(@types/node@18.19.66)(@vitest/browser@3.0.7)(jsdom@26.0.0(supports-color@8.1.1))(lightningcss@1.32.0)(msw@2.7.3(@types/node@18.19.66)(typescript@5.7.2))(supports-color@8.1.1) + ws: 8.18.1 + optionalDependencies: + playwright: 1.50.1 + transitivePeerDependencies: + - '@types/node' + - bufferutil + - typescript + - utf-8-validate + - vite + optional: true + '@vitest/browser@3.0.7(@types/node@18.19.66)(playwright@1.50.1)(typescript@5.7.2)(vite@6.2.0(@types/node@18.19.66)(lightningcss@1.32.0))(vitest@3.0.7)': dependencies: '@testing-library/dom': 10.4.0 @@ -6038,6 +6063,16 @@ snapshots: chai: 5.2.0 tinyrainbow: 2.0.0 + '@vitest/mocker@3.0.7(msw@2.7.3(@types/node@18.19.66)(typescript@5.7.2))(vite@6.0.9(@types/node@18.19.66)(lightningcss@1.32.0))': + dependencies: + '@vitest/spy': 3.0.7 + estree-walker: 3.0.3 + magic-string: 0.30.17 + optionalDependencies: + msw: 2.7.3(@types/node@18.19.66)(typescript@5.7.2) + vite: 6.0.9(@types/node@18.19.66)(lightningcss@1.32.0) + optional: true + '@vitest/mocker@3.0.7(msw@2.7.3(@types/node@18.19.66)(typescript@5.7.2))(vite@6.2.0(@types/node@18.19.66)(lightningcss@1.32.0))': dependencies: '@vitest/spy': 3.0.7 @@ -8040,7 +8075,7 @@ snapshots: why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 18.19.66 - '@vitest/browser': 3.0.7(@types/node@18.19.66)(playwright@1.50.1)(typescript@5.7.2)(vite@6.2.0(@types/node@18.19.66)(lightningcss@1.32.0))(vitest@3.0.7) + '@vitest/browser': 3.0.7(@types/node@18.19.66)(playwright@1.50.1)(typescript@5.7.2)(vite@6.0.9(@types/node@18.19.66)(lightningcss@1.32.0))(vitest@3.0.7) jsdom: 26.0.0(supports-color@8.1.1) transitivePeerDependencies: - jiti diff --git a/src/index.ts b/src/index.ts index 82770246..c4ac379e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -301,7 +301,7 @@ export default function solidPlugin(options: Partial = {}): Plugin { : {}), }, ...(!isVite6OrNewer ? { ssr: solidPkgsConfig.ssr } : {}), - ...(test.server ? { test } : {}), + ...(Object.keys(test).length ? { test } : {}), }; }, diff --git a/src/test-config.test.ts b/src/test-config.test.ts new file mode 100644 index 00000000..ae927798 --- /dev/null +++ b/src/test-config.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from 'vitest'; +import solidPlugin from './index.js'; + +async function resolveTestConfig(userTest: Record) { + const plugin = solidPlugin(); + const config = plugin.config as (...args: any[]) => Promise; + const result = await config.call( + {}, + { root: process.cwd(), mode: 'test', test: userTest }, + { command: 'serve', mode: 'test' }, + ); + return result.test; +} + +describe('test config', () => { + it('sets the jsdom environment', async () => { + const test = await resolveTestConfig({}); + expect(test?.environment).toBe('jsdom'); + }); + + it('sets the jsdom environment when solid-js is already external', async () => { + const test = await resolveTestConfig({ server: { deps: { external: [/solid-js/] } } }); + expect(test?.environment).toBe('jsdom'); + expect(test?.server).toBeUndefined(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 70191cbf..9c12304d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "src", "cypress" ], "exclude": [ - "**/*.spec.ts" + "**/*.spec.ts", "**/*.test.ts" ], "compilerOptions": { "target": "ESNext", diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000..2f1a903a --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +// The plugin's own unit tests (`pnpm test:unit`). The example apps under +// examples/* carry their own vitest configs and run through `pnpm test`. +export default defineConfig({ + test: { + include: ['src/**/*.test.ts'], + environment: 'node', + }, +});