Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viewport does not reset between test suite runs in headless browser mode #7649

Open
6 tasks done
kwojcik opened this issue Mar 10, 2025 · 0 comments
Open
6 tasks done
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@kwojcik
Copy link

kwojcik commented Mar 10, 2025

Describe the bug

Something about the viewport persists between test suite runs (using r to re-run), causing tests that depend on scrolling and IntersectionObserver to fail if the suite re-runs. Only fails in headless browser mode, it passes in headed mode.

Reproduction

The test in the repro uses IntersectionObserver to detect when something comes into the viewport. The test checks that the top element is visible and scrolled to, then scrolls to the bottom and checks that the bottom element is visible and scrolled to. When re-running the suite, however, the top element appears to be visible according to getBoundingClientRect but the IntersectionObserver does not fire. Scrolling to the first element at the start of the test "fixes" this.

repro branch: https://github.com/kwojcik/vitest/tree/viewportBug

cd examples/basic
npm install
npm run test test/suite.test.tsx

Test passes the first time, but hit r to run again and it fails.

System Info

System:
    OS: macOS 15.3.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 20.00 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/.asdf/installs/nodejs/20.18.1/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.5.0 - /opt/homebrew/bin/pnpm
    Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 134.0.6998.45
    Firefox Nightly: 127.0
    Safari: 18.3
  npmPackages:
    @vitest/browser: latest => 3.0.8
    @vitest/ui: latest => 3.0.8
    playwright: ^1.50.1 => 1.51.0
    vite: latest => 6.2.1
    vitest: latest => 3.0.8

Used Package Manager

npm

Validations

@sheremet-va sheremet-va added feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants