Skip to content

Commit

Permalink
chore: revert webdriverio hack for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 23, 2024
1 parent 1eda66c commit 0b5c4a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
13 changes: 4 additions & 9 deletions packages/browser/src/client/tester/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { RunnerTask } from 'vitest'
import type {
BrowserPage,
Locator,
Platform,
UserEvent,
UserEventClickOptions,
UserEventDragAndDropOptions,
Expand All @@ -29,7 +30,7 @@ function triggerCommand<T>(command: string, ...args: any[]) {
return rpc().triggerCommand<T>(sessionId, command, filepath(), args)
}

export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent, options?: TestingLibraryOptions): UserEvent {
export function createUserEvent(platform: Platform, __tl_user_event_base__?: TestingLibraryUserEvent, options?: TestingLibraryOptions): UserEvent {
if (__tl_user_event_base__) {
return createPreviewUserEvent(__tl_user_event_base__, options ?? {})
}
Expand All @@ -38,17 +39,11 @@ export function createUserEvent(__tl_user_event_base__?: TestingLibraryUserEvent
unreleased: [] as string[],
}

// https://playwright.dev/docs/api/class-keyboard
// https://webdriver.io/docs/api/browser/keys/
const modifier = provider === `playwright`
? 'ControlOrMeta'
: provider === 'webdriverio'
? 'Ctrl'
: 'Control'
const modifier = platform === 'darwin' ? 'Meta' : 'Control'

const userEvent: UserEvent = {
setup() {
return createUserEvent()
return createUserEvent(platform)
},
async cleanup() {
return ensureAwaited(async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/node/commands/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ export async function keyboardImplementation(

for (const { releasePrevious, releaseSelf, repeat, keyDef } of actions) {
let key = keyDef.key!
const special = Key[key as 'Shift']
const code = 'location' in keyDef ? keyDef.key! : keyDef.code!
const special = Key[code as 'Shift']

if (special) {
key = special
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/plugins/pluginContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const server = {
config: __vitest_browser_runner__.config,
}
export const commands = server.commands
export const userEvent = createUserEvent(_userEventSetup)
export const userEvent = createUserEvent(server.platform, _userEventSetup)
export { page, cdp }
`
}
Expand Down
2 changes: 1 addition & 1 deletion test/browser/fixtures/user-event/keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('special keys', async () => {
expect(await testKeyboard('{Shift}')).toMatchInlineSnapshot(`"Shift|ShiftLeft|1"`);
expect(await testKeyboard('{ShiftLeft}')).toMatchInlineSnapshot(`"ERROR"`);
expect(await testKeyboard('{ShiftRight}')).toMatchInlineSnapshot(`"ERROR"`);
expect(await testKeyboard('[Shift]')).toMatchInlineSnapshot(`"ERROR"`);
expect(await testKeyboard('[Shift]')).toMatchInlineSnapshot(`"Shift|ShiftLeft|1"`);
expect(await testKeyboard('[ShiftLeft]')).toMatchInlineSnapshot(`"Shift|ShiftLeft|1"`);
expect(await testKeyboard('[ShiftRight]')).toMatchInlineSnapshot(`"Shift|ShiftLeft|1"`);
}
Expand Down

0 comments on commit 0b5c4a9

Please sign in to comment.