From c730de877ca3124b7bd20a7b09745a4ade78d026 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Thu, 20 Aug 2026 14:26:51 +1000 Subject: [PATCH] Use the platform modifier in the playground format tests (#473) Monaco binds `KeyMod.CtrlCmd` to Cmd on macOS and Ctrl everywhere else, so the two keyboard chords in playground-format.browser.test.tsx only ever worked on one platform. Both tests passed on CI's Linux runner and failed on a Mac: the undo never fired in the first test, and the save shortcut never reached the format action in the second. Resolve the modifier the way Monaco does and use it for both chords. The keybinding itself was already correct, so no product code changes. Closes #472 --- .../playground/playground-format.browser.test.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/docs/src/components/playground/playground-format.browser.test.tsx b/apps/docs/src/components/playground/playground-format.browser.test.tsx index 00ed71a8..04b5eae1 100644 --- a/apps/docs/src/components/playground/playground-format.browser.test.tsx +++ b/apps/docs/src/components/playground/playground-format.browser.test.tsx @@ -61,11 +61,11 @@ test('monaco fills the editor pane and format updates source through onChange', .toContain(formatted); await userEvent.click(monacoEditor()!); - await userEvent.keyboard('{Control>}z{/Control}'); + await userEvent.keyboard(ctrlCmd('z')); await expect.poll(() => viewText(), { timeout: 10_000 }).toContain('playgroundFormatTest=(x)=>x'); }, 60_000); -test('Ctrl+S formats through the Monaco provider and onChange', async () => { +test('the save shortcut formats through the Monaco provider and onChange', async () => { const onChangeCalls: Array = []; renderPlayground(badlyFormatted, (code) => onChangeCalls.push(code)); @@ -78,7 +78,7 @@ test('Ctrl+S formats through the Monaco provider and onChange', async () => { (document.querySelector('.view-lines')?.textContent ?? '').replace(/\u00a0/g, ' '); await userEvent.click(monacoEditor()!); - await userEvent.keyboard('{Control>}s{/Control}'); + await userEvent.keyboard(ctrlCmd('s')); await expect.poll(() => viewText(), { timeout: 10_000 }).toContain(formatted); await expect @@ -109,3 +109,10 @@ function Harness({ ); } + +// Monaco maps its CtrlCmd modifier to Cmd on macOS and Ctrl everywhere else, so +// a test that hardcodes one of them passes on a single platform. +function ctrlCmd(key: string): string { + const modifier = navigator.userAgent.includes('Macintosh') ? 'Meta' : 'Control'; + return `{${modifier}>}${key}{/${modifier}}`; +} -- 2.51.2