Skip to content

vitest Browser Mode doesn't cooperate with local server configured for HTTPS #4844

@zmullett

Description

@zmullett

Describe the bug

There are cases where the local server needs to be configured for HTTPS; mixed content is a problem and certain browser APIs require HTTPS.

When vite is configured with a SSL certificate (e.g. via @vitejs/plugin-basic-ssl or mkcert), the protocol used to access localhost switches to HTTPS. When vitest in Browser Mode runs tests, it fails to connect to the in-browser runner because it attempts to navigate to http://localhost rather than https://localhost.

Reproduction

https://github.com/zmullett/vitest-https-repro

  1. ni
  2. nr test
  3. Observe Error: page.goto: net::ERR_EMPTY_RESPONSE at http://localhost:5173/?path=demo.test.js&id=demo.test.js

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M2
    Memory: 880.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.0.0 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.0 - /opt/homebrew/bin/npm
    pnpm: 8.9.2 - ~/Library/pnpm/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 120.0.6099.129
    Safari: 17.2.1
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.0.2 => 1.0.2 
    @vitest/browser: ^1.1.1 => 1.1.1 
    vitest: ^1.1.1 => 1.1.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserIssues and PRs related to the browser runner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions