vitest-dev / vitest-dev/vitest
Vitest is stuck in a loop when using browser mode and calling `location.reload()` in `afterAll` callback
Nobody has claimed this yet.
- 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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