fix(e2e): cross-protocol browser.execute() — works with both WebDriver + CDP

Root cause: WebDriverIO devtools protocol wraps functions in a polyfill
that puts `return` inside eval() (not a function body) → "Illegal return".

Fix: exec() wrapper in helpers/execute.ts converts function args to IIFE
strings before passing to browser.execute(). Works identically on both
WebDriver (Tauri) and CDP/devtools (Electrobun CEF).

- 35 spec files updated (browser.execute → exec)
- 4 config files updated (string-form expressions)
- helpers/actions.ts + assertions.ts updated
- 560 vitest + 116 cargo passing
This commit is contained in:
Hibryda 2026-03-22 06:33:55 +01:00
parent 407e49cc32
commit 6a8181f33a
42 changed files with 630 additions and 541 deletions

View file

@ -5,12 +5,13 @@
import { browser, expect } from '@wdio/globals';
import * as S from '../helpers/selectors.ts';
import { openCommandPalette, closeCommandPalette } from '../helpers/actions.ts';
import { exec } from '../helpers/execute.ts';
describe('Command palette', () => {
it('should open via Ctrl+K', async () => {
await openCommandPalette();
const visible = await browser.execute((sel: string) => {
const visible = await exec((sel: string) => {
const el = document.querySelector(sel);
if (!el) return false;
return getComputedStyle(el).display !== 'none';
@ -33,7 +34,7 @@ describe('Command palette', () => {
});
it('should list commands (14+ expected)', async () => {
const count = await browser.execute((sel: string) => {
const count = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.PALETTE_ITEM);
// Command count varies: 14 base + up to 5 project focus + N group switches
@ -41,12 +42,12 @@ describe('Command palette', () => {
});
it('should show command labels and shortcuts', async () => {
const labelCount = await browser.execute((sel: string) => {
const labelCount = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.CMD_LABEL);
expect(labelCount).toBeGreaterThan(0);
const shortcutCount = await browser.execute((sel: string) => {
const shortcutCount = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.CMD_SHORTCUT);
expect(shortcutCount).toBeGreaterThan(0);
@ -59,7 +60,7 @@ describe('Command palette', () => {
await input.setValue('terminal');
await browser.pause(200);
const count = await browser.execute((sel: string) => {
const count = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.PALETTE_ITEM);
expect(count).toBeLessThan(18);
@ -67,7 +68,7 @@ describe('Command palette', () => {
});
it('should highlight first item', async () => {
const hasHighlight = await browser.execute(() => {
const hasHighlight = await exec(() => {
return (document.querySelector('.palette-item.active')
?? document.querySelector('.palette-item.highlighted')
?? document.querySelector('.palette-item:first-child')) !== null;
@ -98,20 +99,20 @@ describe('Command palette', () => {
await closeCommandPalette();
const hidden = await browser.execute((sel: string) => {
const hidden = await exec((sel: string) => {
const el = document.querySelector(sel);
if (!el) return true;
return getComputedStyle(el).display === 'none';
}, S.PALETTE_BACKDROP);
if (!hidden) {
// Fallback: click the backdrop to close
await browser.execute(() => {
await exec(() => {
const backdrop = document.querySelector('.palette-backdrop');
if (backdrop) (backdrop as HTMLElement).click();
});
await browser.pause(300);
}
const finalCheck = await browser.execute((sel: string) => {
const finalCheck = await exec((sel: string) => {
const el = document.querySelector(sel);
if (!el) return true;
return getComputedStyle(el).display === 'none';