-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): cleanup keyboard state (#6731)
- Loading branch information
Showing
11 changed files
with
164 additions
and
8 deletions.
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
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