Skip to content

Browser Mode: Vite warns Plugin "vitest:mocks:interceptor" defines Vite-specific hooks (configureServer) in a plugin returned from applyToEnvironment on every run #11276

Description

@martin-honzatko

Describe the bug

With test.browser.enabled: true, every vitest run prints once:

Plugin "vitest:mocks:interceptor" defines Vite-specific hooks (configureServer) in a plugin returned from applyToEnvironment. These hooks will be ignored.

Cause: @vitest/browser adds interceptorPlugin({ registerWebSocketEvents: false }) (from @vitest/mocker) to the browser contribution, which vitest:browser:loader.applyToEnvironment returns for the client environment. The mocker's interceptorPlugin always defines configureServer (its body returns early when registerWebSocketEvents === false), and Vite 8's resolveEnvironmentPlugins warns for any config / configEnvironment / configureServer / configResolved hook on a plugin returned from applyToEnvironment. Tests and mocking work; the warning is noise on every run.
Suggested fix: attach configureServer only when registerWebSocketEvents !== false (packages/mocker/src/node/interceptorPlugin.ts), or strip the hook in the browser contribution.

I do not plan to submit a PR. Used Claude Code to generate this report.

Reproduction

Link to the GitHub repository with the Reproduction — npm install && npm test.

Bare config: one chromium instance via @vitest/browser-playwright, one passing test, no plugins.
Actual: The warning above is printed once per run.
Expected: no warning. (The same happens in a 200-file production suite; the minimal repo is the stripped-down version.)

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 Intel(R) Core(TM) Ultra 7 265H
    Memory: 6.38 GB / 31.46 GB
Binaries:
    Node: 24.20.0 - C:\nvm4w\nodejs\node.EXE
    npm: 11.19.1 - C:\nvm4w\nodejs\npm.CMD
Browsers:
    Chrome: 152.0.7977.84
    Edge: Chromium (147.0.3912.72)
npmPackages:
    @vitejs/plugin-react: 6.1.1 => 6.1.1 
    @vitest/browser-playwright: 5.0.0 => 5.0.0 
    @vitest/coverage-v8: 5.0.0 => 5.0.0 
    @vitest/eslint-plugin: 1.6.27 => 1.6.27 
    @vitest/ui: 5.0.0 => 5.0.0 
    playwright: 1.63.0 => 1.63.0 
    vite: 8.3.0 => 8.3.0 
    vitest: 5.0.0 => 5.0.0 
    vitest-browser-react: 2.3.0 => 2.3.0

Used Package Manager

npm

Validations

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions