-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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): cleanup keyboard state #6731
Merged
sheremet-va
merged 15 commits into
vitest-dev:main
from
hi-ogawa:fix-browser-keyboard-up-cleanup
Oct 21, 2024
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
45b40b3
fix(browser): cleanup keybaord release state
hi-ogawa f31dffa
chore: lint
hi-ogawa 84bc854
test: add test
hi-ogawa 37aa0af
chore: comment
hi-ogawa 4a75432
test: add test
hi-ogawa 423b2ec
refactor: use symbol
hi-ogawa bfbba25
Merge branch 'main' into fix-browser-keyboard-up-cleanup
hi-ogawa 616ca65
chore: cleanup in onAfterRunTask
hi-ogawa 231877d
test: per-test cleanup
hi-ogawa 983ea44
fix: fix preview mode cleanup
hi-ogawa cf0ce91
fix: fix webdriverio/firefox
hi-ogawa 5941743
fix: fresh setup
hi-ogawa f97ee5c
fix: error for unsupported provider
hi-ogawa f9f95c9
Merge branch 'main' into fix-browser-keyboard-up-cleanup
hi-ogawa b23c8ae
docs: jsdoc and context.md
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
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
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,55 @@ | ||
import { expect, onTestFinished, test } from 'vitest' | ||
import { userEvent } from '@vitest/browser/context' | ||
|
||
test('cleanup1', async () => { | ||
let logs: any[] = []; | ||
function handler(e: KeyboardEvent) { | ||
logs.push([e.key, e.altKey]); | ||
}; | ||
document.addEventListener('keydown', handler) | ||
onTestFinished(() => { | ||
document.removeEventListener('keydown', handler); | ||
}) | ||
|
||
await userEvent.keyboard('{Tab}') | ||
await userEvent.keyboard("{Alt>}") | ||
expect(logs).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"Tab", | ||
false, | ||
], | ||
[ | ||
"Alt", | ||
true, | ||
], | ||
] | ||
`) | ||
}) | ||
|
||
// test per-test cleanup | ||
test('cleanup1.2', async () => { | ||
let logs: any[] = []; | ||
function handler(e: KeyboardEvent) { | ||
logs.push([e.key, e.altKey]); | ||
}; | ||
document.addEventListener('keydown', handler) | ||
onTestFinished(() => { | ||
document.removeEventListener('keydown', handler); | ||
}) | ||
|
||
await userEvent.keyboard('{Tab}') | ||
await userEvent.keyboard("{Alt>}") | ||
expect(logs).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"Tab", | ||
false, | ||
], | ||
[ | ||
"Alt", | ||
true, | ||
], | ||
] | ||
`) | ||
}) |
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,30 @@ | ||
import { expect, onTestFinished, test } from 'vitest' | ||
import { userEvent } from '@vitest/browser/context' | ||
|
||
// test per-test-file cleanup just in case | ||
|
||
test('cleanup2', async () => { | ||
let logs: any[] = []; | ||
function handler(e: KeyboardEvent) { | ||
logs.push([e.key, e.altKey]); | ||
}; | ||
document.addEventListener('keydown', handler) | ||
onTestFinished(() => { | ||
document.removeEventListener('keydown', handler); | ||
}) | ||
|
||
await userEvent.keyboard('{Tab}') | ||
await userEvent.keyboard("{Alt>}") | ||
expect(logs).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
"Tab", | ||
false, | ||
], | ||
[ | ||
"Alt", | ||
true, | ||
], | ||
] | ||
`) | ||
}) |
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,17 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { defineConfig } from 'vitest/config' | ||
|
||
const provider = process.env.PROVIDER || 'playwright' | ||
const name = | ||
process.env.BROWSER || (provider === 'playwright' ? 'chromium' : 'chrome') | ||
|
||
export default defineConfig({ | ||
cacheDir: fileURLToPath(new URL("./node_modules/.vite", import.meta.url)), | ||
test: { | ||
browser: { | ||
enabled: true, | ||
provider, | ||
name, | ||
}, | ||
}, | ||
}) |
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
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.
We need documentation for every public API - in jsdoc and vitest.dev