vitest-dev / vitest-dev/vitest

Vitest is stuck in a loop when using browser mode and calling `location.reload()` in `afterAll` callback

Open
#6,439 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-edge-case
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

As the title describes, i'm using Vitest in browser mode and i'm calling location.reload() in afterAll callback:

afterAll(async () => {
  await myUnloadMethod()
  location.reload()
})

The reason of calling location.reload() is to ensure that after all tests in the file ran, the next tests will execute in a clean environment as if we just loaded the page

Reproduction

Can't seem to get StackBlitz work with Vitest in browser mode

System Info
System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 171.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.2/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
    pnpm: 8.9.2 - ~/.nvm/versions/node/v18.18.2/bin/pnpm
  Browsers:
    Brave Browser: 128.1.69.153
    Chrome: 128.0.6613.114
    Edge: 128.0.2739.54
    Firefox Nightly: 130.0a1
    Safari: 17.5
    Safari Technology Preview: 18.0
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.1.0 => 1.1.0 
    @vitest/browser: ^2.0.5 => 2.0.5 
    @vitest/coverage-istanbul: ^2.0.5 => 2.0.5 
    vite: ^5.4.2 => 5.4.2 
    vitest: ^2.0.5 => 2.0.5
Used Package Manager

npm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the browser-mode case with an afterAll callback that calls location.reload(), since the issue has no runnable reproduction or named files. Trace the browser-mode test lifecycle around afterAll and page reload handling. Done means the callback no longer causes a loop and subsequent tests still run in a clean environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.