Vitest runs Playwright e2e/*.spec.ts and fails 'Playwright Test did not expect test.describe() to be called here'; exclude e2e with configDefaults.exclude
Exclude the Playwright folder in your Vite/Vitest config, and keep Vitest's defaults:
import { defineConfig, configDefaults } from 'vitest/config'
export default defineConfig({ test: { exclude: [...configDefaults.exclude, 'e2e/**'] } })Alternatively, narrow test.include to src/**/*.test.{ts,tsx}.
Vitest's default include is **/*.{test,spec}.?(c|m)[jt]s?(x), which matches Playwright's e2e/home.spec.ts. Vitest then imports @playwright/test outside the Playwright runner, and test.describe throws:
Error: Playwright Test did not expect test.describe() to be called here. Most common reasons include: ... You have two different versions of @playwright/test.
The message's suggestions (config file, duplicate versions) send you the wrong way. The real cause is that the wrong runner picked up the file. The unit tests still pass, and the summary shows Test Files 1 failed | 1 passed.
Setting exclude: ['**/e2e/**'] by itself replaces Vitest's default exclude list (**/node_modules/**, **/dist/**, **/cypress/**, ...). That's why the spread of configDefaults.exclude matters. Reproduced in node:22-slim with vitest 2.1.9 and the current @playwright/test. With the exclude, only the Vitest files run.