-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(browser): scale iframe for non ui case #6512
Draft
hi-ogawa
wants to merge
16
commits into
vitest-dev:main
Choose a base branch
from
hi-ogawa:fix-browser-non-ui-viewport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−11
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c13849c
fix(browser): fix viewport for non ui case
hi-ogawa 8df9e9c
test: tweak
hi-ogawa 2cdab66
test: playwright only
hi-ogawa e2d9d09
Merge branch 'main' into fix-browser-non-ui-viewport
hi-ogawa ad7f47e
fix: scale iframe wrapper
hi-ogawa fd69f0c
fix: set data-scale
hi-ogawa 43459ea
Merge branch 'main' into fix-browser-non-ui-viewport
hi-ogawa ecac5ad
fix: scale userEvent
hi-ogawa 8fe8f35
wip: tweak
hi-ogawa 402b571
wip: how about ubuntu
hi-ogawa 3196a22
Revert "wip: tweak"
hi-ogawa 8d49953
Revert "wip: how about ubuntu"
hi-ogawa 2c36ca9
chore: revert this too
hi-ogawa 5f76302
test: non exact click position
hi-ogawa 3db24eb
wip: give up webdriverio
hi-ogawa 24bbb16
Merge branch 'main' into fix-browser-non-ui-viewport
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { page, userEvent } from "@vitest/browser/context"; | ||
import { expect, test } from "vitest"; | ||
|
||
test("drag and drop over large viewport", async () => { | ||
// put boxes horizontally [1] [2] ... [30] | ||
// then drag-and-drop from [1] to [30] | ||
|
||
const wrapper = document.createElement("div"); | ||
wrapper.style.cssText = "display: flex; width: 3000px;"; | ||
document.body.appendChild(wrapper); | ||
|
||
const events: { i: number; type: string }[] = []; | ||
|
||
for (let i = 1; i <= 30; i++) { | ||
const el = document.createElement("div"); | ||
el.textContent = `[${i}]`; | ||
el.style.cssText = ` | ||
flex: none; | ||
width: 100px; | ||
height: 100px; | ||
border: 1px solid black; | ||
box-sizing: border-box; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
el.draggable = true; | ||
wrapper.append(el); | ||
|
||
el.addEventListener("dragstart", (ev) => { | ||
ev.dataTransfer.effectAllowed = "move"; | ||
events.push({ type: "dragstart", i }); | ||
}); | ||
el.addEventListener("dragover", (ev) => { | ||
ev.preventDefault(); | ||
ev.dataTransfer.dropEffect = "move"; | ||
events.push({ type: "dragover", i }); | ||
}); | ||
el.addEventListener("drop", (ev) => { | ||
ev.preventDefault(); | ||
events.push({ type: "drop", i }); | ||
}); | ||
} | ||
|
||
await userEvent.dragAndDrop(page.getByText("[1]"), page.getByText("[30]")); | ||
|
||
expect(events).toMatchObject( | ||
expect.arrayContaining([ | ||
{ type: "dragstart", i: 1 }, | ||
{ type: "drop", i: 30 }, | ||
]), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { defineConfig } from 'vitest/config' | ||
|
||
// pnpm -C test/browser test-fixtures --root fixtures/viewport --browser.ui=false | ||
// pnpm -C test/browser test-fixtures --root fixtures/viewport --browser.headless=true | ||
|
||
const provider = process.env.PROVIDER || 'playwright' | ||
const name = | ||
process.env.BROWSER || (provider === 'playwright' ? 'chromium' : 'chrome') | ||
|
||
export default defineConfig({ | ||
test: { | ||
browser: { | ||
enabled: true, | ||
name, | ||
provider, | ||
viewport: { width: 3000, height: 400 } | ||
}, | ||
}, | ||
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { expect, test } from 'vitest' | ||
import { provider, runBrowserTests } from './utils' | ||
|
||
test.runIf(provider === 'playwright')('viewport', async () => { | ||
const { stderr, stdout } = await runBrowserTests({ | ||
root: './fixtures/viewport', | ||
reporters: [['verbose', { isTTY: false }]], | ||
}) | ||
|
||
expect(stderr).toBe('') | ||
expect(stdout).toContain('✓ basic.test.ts') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,9 +135,10 @@ describe('userEvent.click', () => { | |
}, | ||
}) | ||
|
||
// not exact due to scaling and rounding | ||
expect(spy).toHaveBeenCalledWith({ | ||
x: 200, | ||
y: 150, | ||
x: expect.closeTo(200, -1), | ||
y: expect.closeTo(150, -1), | ||
Comment on lines
+138
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scaling round issue seems to already exist for UI case. For example, I can reproduce it on main branch with firefox. $ PROVIDER=playwright BROWSER=firefox pnpm -C test/browser test-fixtures /userEvent. -t 'x/y'
FAIL test/userEvent.test.ts > userEvent.click > clicks with x/y coords
AssertionError: expected "spy" to be called with arguments: [ { x: 200, y: 150 } ]
Received:
1st spy call:
Array [
Object {
- "x": 200,
+ "x": 199,
"y": 150,
},
] I'm not sure if there's a way to fix this, so I loosened the assertion. |
||
}) | ||
}) | ||
}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out what's wrong with webdriverio, so I added scaling only for
playwright
and CI seems mostly happy.