If npm test runs Vitest and stops with Error: Playwright Test did not expect test() to be called here., check whether Vitest is collecting a file that imports test from @playwright/test. This is the runner collision reported in Playwright issue #31348: the maintainer identified a Playwright spec being run by Vitest, and the reporter confirmed that excluding it helped. [1]
For this case, separate the files each runner collects. Keep the Playwright suite running through Playwright; do not delete it just to get a green Vitest run. The example below reproduced this failure and fix with synthetic tests.
Confirm which runner is failing
Open package.json and inspect the command behind scripts.test. The report in issue #31348 used npm test to run vitest. If your script invokes a different command, this diagnosis is not yet established. [1]
Next, inspect the failing file's import. In our reproduction, the file was tests/e2e/runner.spec.ts:
import { test, expect } from '@playwright/test';
test('Playwright runner sentinel', async () => {
expect(1 + 1).toBe(2);
});Vitest's default include pattern matches both .test.ts and .spec.ts files. A Playwright import inside a matching file does not by itself exclude the file from Vitest, as the issue and our reproduction demonstrate. [1][2]
From the project directory, with its dependencies already installed, check the collected paths:
npx vitest list --filesOnlyIf the output includes your Playwright spec, you have evidence for this collision. In our unfixed example it listed both tests/unit/sum.test.ts and tests/e2e/runner.spec.ts. Running Vitest then failed on the Playwright file. Vitest documents list --filesOnly as the file-listing command. [3]
Give each runner its own files
This minimal example uses:
tests/
unit/
sum.test.ts
e2e/
runner.spec.ts
vitest.config.ts
playwright.config.tsAdapt the paths and extensions to your project. Before narrowing any include pattern, inventory your existing unit, integration and browser tests so none disappear from both runners.
In the configuration Vitest actually uses, merge these test settings into your existing configuration. For a standalone minimal project, vitest.config.ts is:
import { configDefaults, defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: ['tests/unit/**/*.test.ts'],
exclude: [...configDefaults.exclude, 'tests/e2e/**'],
},
});The include pattern selects the example's unit files. The exclusion explicitly keeps its end-to-end folder out of Vitest. These patterns are relative to Vitest's root. Keep any project-specific exclusions alongside the defaults and the new exclusion. [2][4]
Do not replace the defaults with only exclude: ['tests/e2e/**']. Vitest documents that a manually configured exclude replaces its default value, and recommends spreading configDefaults.exclude to extend it. Importing those defaults also avoids copying a default list from documentation for a different installed version. [4]
For Playwright, use playwright.config.ts:
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests/e2e',
testMatch: '**/*.spec.ts',
});Playwright documents testDir as the test directory and testMatch as the matching pattern. These are top-level runner settings. Preserve your existing projects, browser settings and server configuration when adding them. [5]
Give the runners distinct scripts in package.json, keeping unrelated scripts:
{
"scripts": {
"test": "vitest",
"test:unit": "vitest run",
"test:e2e": "playwright test"
}
}Vitest's run command performs a single run. The Playwright CLI runs its suite with playwright test. These are the scripts used in our reproduction. [3][6]
Check that neither suite disappeared
Run both listings from the same project directory:
npx vitest list --filesOnly
npx playwright test --listFor the example, Vitest should list tests/unit/sum.test.ts only. Playwright should list runner.spec.ts and its sentinel test. Compare your own output against the inventory you made before the change. An empty list, or a missing test you intended to keep, is not a completed fix. Playwright's --list collects and reports tests without running them. [3][6]
Then run both suites:
npm run test:unit
npm run test:e2eOur unit fixture imported test and expect from vitest and checked 1 + 1. After the configuration change, the unit run and the Playwright sentinel run each passed their single test. The Playwright fixture did not open a browser, visit an app or test login. It demonstrates that the runner still collects and executes the file.
Installed-version note: the current Vitest CLI documentation says that, since Vitest 5, vitest list parses files statically by default; --no-static-parse runs the files to collect tests instead. A successful listing is therefore not evidence that a test executed successfully. Check the documentation matching your installed Vitest version, and retain the actual suite runs above. [3]
If the error remains
This fix covers the confirmed wrong-runner collection case. It does not cover every occurrence of the same error.
If Vitest no longer lists the Playwright file but a run still fails, inspect the new stack trace rather than excluding more files blindly. If the error occurs when running Playwright itself, the Vitest collection diagnosis has not explained it. Our reproduced error also listed configuration-file imports and multiple Playwright Test versions among its possible causes; the message alone is insufficient to choose between them.
For broader pre-launch checks, use the app launch checklist.
Separate problem: the deployed domain has an SSL error
If you also have a certificate or DNS problem on a deployed domain you own, use the custom-domain SSL checker. It checks domain and certificate details. It does not inspect your repository, collect tests or diagnose this runner error. [7]
Need help deciding what to check before launch?
Request a free launch-safety check.
Sources
All sources read 1 November 2026. Vendor documentation publication dates are not stated on the pages read.
Issue #31348: Error: Playwright Test did not expect test() to be called here, Microsoft Playwright repository, 17 June 2024; comments 17–19 June 2024.
include, Vitest documentation.
Command Line Interface, Vitest documentation.
exclude, Vitest documentation.
Configuration, Microsoft Playwright documentation.
Command line, Microsoft Playwright documentation.
Custom-domain SSL checker, Enviera.
Is my AI-built app safe to launch?, Enviera; existing CTA destination.
