| 28 | } |
| 29 | |
| 30 | function withPlatform<T>(platform: NodeJS.Platform, run: () => T): T { |
| 31 | const host = globalThis as typeof globalThis & { |
| 32 | window?: { zen?: { platformSync?: () => NodeJS.Platform } } |
| 33 | } |
| 34 | const previousWindow = host.window |
| 35 | Object.defineProperty(host, 'window', { |
| 36 | value: { |
| 37 | ...(previousWindow ?? {}), |
| 38 | zen: { ...(previousWindow?.zen ?? {}), platformSync: () => platform } |
| 39 | }, |
| 40 | configurable: true |
| 41 | }) |
| 42 | |
| 43 | try { |
| 44 | return run() |
| 45 | } finally { |
| 46 | if (previousWindow === undefined) { |
| 47 | Reflect.deleteProperty(host, 'window') |
| 48 | } else { |
| 49 | Object.defineProperty(host, 'window', { |
| 50 | value: previousWindow, |
| 51 | configurable: true |
| 52 | }) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | describe('shortcutBindingFromEvent', () => { |
| 58 | it('uses the typed character on Colemak (Cmd+P fires on the key that types p)', () => { |