From 0b5c4a94f9de726e4b127dcb93359a8c98082b00 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Mon, 23 Dec 2024 15:14:52 +0900 Subject: [PATCH] chore: revert webdriverio hack for now --- packages/browser/src/client/tester/context.ts | 13 ++++--------- packages/browser/src/node/commands/keyboard.ts | 3 ++- packages/browser/src/node/plugins/pluginContext.ts | 2 +- test/browser/fixtures/user-event/keyboard.test.ts | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/browser/src/client/tester/context.ts b/packages/browser/src/client/tester/context.ts index d7b7acc864de..9c281c7164e6 100644 --- a/packages/browser/src/client/tester/context.ts +++ b/packages/browser/src/client/tester/context.ts @@ -4,6 +4,7 @@ import type { RunnerTask } from 'vitest' import type { BrowserPage, Locator, + Platform, UserEvent, UserEventClickOptions, UserEventDragAndDropOptions, @@ -29,7 +30,7 @@ function triggerCommand(command: string, ...args: any[]) { return rpc().triggerCommand(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 ?? {}) } @@ -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 () => { diff --git a/packages/browser/src/node/commands/keyboard.ts b/packages/browser/src/node/commands/keyboard.ts index b6927370dcce..7555e9c3f943 100644 --- a/packages/browser/src/node/commands/keyboard.ts +++ b/packages/browser/src/node/commands/keyboard.ts @@ -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 diff --git a/packages/browser/src/node/plugins/pluginContext.ts b/packages/browser/src/node/plugins/pluginContext.ts index 5929822ae557..fa364070323e 100644 --- a/packages/browser/src/node/plugins/pluginContext.ts +++ b/packages/browser/src/node/plugins/pluginContext.ts @@ -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 } ` } diff --git a/test/browser/fixtures/user-event/keyboard.test.ts b/test/browser/fixtures/user-event/keyboard.test.ts index e1314d03cc74..ec39620f3353 100644 --- a/test/browser/fixtures/user-event/keyboard.test.ts +++ b/test/browser/fixtures/user-event/keyboard.test.ts @@ -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"`); }