From 662e8a3637725553b9466f768b22ec844e8d5ea6 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 8 Oct 2026 06:27:35 +0200 Subject: [PATCH] fix(browser): avoid extra scroll outside the iframe (#11523) --- packages/browser/src/client/orchestrator.html | 3 ++ test/browser/specs/viewport.test.ts | 44 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/browser/src/client/orchestrator.html b/packages/browser/src/client/orchestrator.html index e6ec1d742..82fe1dd22 100644 --- a/packages/browser/src/client/orchestrator.html +++ b/packages/browser/src/client/orchestrator.html @@ -22,6 +22,9 @@ width: 100%; height: 100%; } + iframe[data-vitest] { + display: block; + } {__VITEST_INJECTOR__} {__VITEST_ERROR_CATCHER__} {__VITEST_SCRIPTS__} diff --git a/test/browser/specs/viewport.test.ts b/test/browser/specs/viewport.test.ts index 1022c24c6..f1c49c55f 100644 --- a/test/browser/specs/viewport.test.ts +++ b/test/browser/specs/viewport.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'vitest' -import { runBrowserTests } from './utils' +import { instances, runBrowserTests, runInlineBrowserTests } from './utils' test('viewport', async () => { const { stderr, ctx } = await runBrowserTests({ @@ -14,3 +14,45 @@ test('viewport', async () => { } `) }) + +test('scrolling in a test file does not shift the next test file', async () => { + const testFile = ` +import { expect, test } from 'vitest' + +test('the first row is fully visible', async () => { + for (let i = 0; i < 100; i++) { + const row = document.createElement('div') + row.textContent = 'Row ' + i + document.body.append(row) + } + const entry = await new Promise((resolve) => { + const observer = new IntersectionObserver(([entry]) => { + observer.disconnect() + resolve(entry) + }, { threshold: 1 }) + observer.observe(document.body.firstElementChild!) + }) + expect(entry.intersectionRatio).toBe(1) + document.body.lastElementChild!.scrollIntoView() +}) +` + const result = await runInlineBrowserTests({ + 'first.test.ts': testFile, + 'second.test.ts': testFile, + }) + expect(result.stderr).toBe('') + + const tree = result.errorTree({ project: true }) + for (const { browser } of instances) { + expect.soft(tree[browser], browser).toMatchInlineSnapshot(` + { + "first.test.ts": { + "the first row is fully visible": "passed", + }, + "second.test.ts": { + "the first row is fully visible": "passed", + }, + } + `) + } +}) -- 2.51.2