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,10 +5,11 @@
import { browser, expect } from '@wdio/globals';
import * as S from '../helpers/selectors.ts';
import { addTerminalTab } from '../helpers/actions.ts';
import { exec } from '../helpers/execute.ts';
describe('Terminal section', () => {
it('should show the terminal tab bar', async () => {
const exists = await browser.execute((sel: string) => {
const exists = await exec((sel: string) => {
return document.querySelector(sel) !== null;
}, S.TERMINAL_TABS);
if (exists) {
@ -26,20 +27,20 @@ describe('Terminal section', () => {
it('should create a new terminal tab on add click', async function () {
// Terminal may be collapsed by default — expand first
const hasAddBtn = await browser.execute(() => {
const hasAddBtn = await exec(() => {
const btn = document.querySelector('.tab-add-btn');
if (!btn) return false;
return getComputedStyle(btn).display !== 'none';
});
if (!hasAddBtn) { this.skip(); return; }
const countBefore = await browser.execute((sel: string) => {
const countBefore = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
await addTerminalTab();
const countAfter = await browser.execute((sel: string) => {
const countAfter = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
expect(countAfter).toBeGreaterThanOrEqual(countBefore + 1);
@ -62,7 +63,7 @@ describe('Terminal section', () => {
});
it('should highlight active tab', async () => {
const count = await browser.execute((sel: string) => {
const count = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB_ACTIVE);
if (count > 0) {
@ -71,18 +72,18 @@ describe('Terminal section', () => {
});
it('should switch tabs on click', async () => {
const tabCount = await browser.execute((sel: string) => {
const tabCount = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
if (tabCount >= 2) {
await browser.execute((sel: string) => {
await exec((sel: string) => {
const tabs = document.querySelectorAll(sel);
if (tabs[1]) (tabs[1] as HTMLElement).click();
}, S.TERMINAL_TAB);
await browser.pause(300);
const isActive = await browser.execute((sel: string) => {
const isActive = await exec((sel: string) => {
const tabs = document.querySelectorAll(sel);
return tabs[1]?.classList.contains('active') ?? false;
}, S.TERMINAL_TAB);
@ -104,7 +105,7 @@ describe('Terminal section', () => {
});
it('should close a tab on close button click', async () => {
const countBefore = await browser.execute((sel: string) => {
const countBefore = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
if (countBefore < 2) return;
@ -119,7 +120,7 @@ describe('Terminal section', () => {
await closeBtn.click();
await browser.pause(300);
const countAfter = await browser.execute((sel: string) => {
const countAfter = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
expect(countAfter).toBeLessThan(countBefore);
@ -133,7 +134,7 @@ describe('Terminal section', () => {
await collapseBtn.click();
await browser.pause(300);
const h1 = await browser.execute((sel: string) => {
const h1 = await exec((sel: string) => {
const el = document.querySelector(sel);
return el ? getComputedStyle(el).height : '';
}, S.TERMINAL_SECTION);
@ -141,7 +142,7 @@ describe('Terminal section', () => {
await collapseBtn.click();
await browser.pause(300);
const h2 = await browser.execute((sel: string) => {
const h2 = await exec((sel: string) => {
const el = document.querySelector(sel);
return el ? getComputedStyle(el).height : '';
}, S.TERMINAL_SECTION);
@ -151,7 +152,7 @@ describe('Terminal section', () => {
it('should handle multiple terminal tabs', async function () {
// Terminal may be collapsed by default — skip if add button not visible
const hasAddBtn = await browser.execute(() => {
const hasAddBtn = await exec(() => {
const btn = document.querySelector('.tab-add-btn');
if (!btn) return false;
return getComputedStyle(btn).display !== 'none';
@ -162,7 +163,7 @@ describe('Terminal section', () => {
await addTerminalTab();
await addTerminalTab();
const count = await browser.execute((sel: string) => {
const count = await exec((sel: string) => {
return document.querySelectorAll(sel).length;
}, S.TERMINAL_TAB);
expect(count).toBeGreaterThanOrEqual(2);
@ -170,7 +171,7 @@ describe('Terminal section', () => {
it('should handle PTY output display', async () => {
// Verify xterm rows container exists (for PTY output rendering)
const hasRows = await browser.execute(() => {
const hasRows = await exec(() => {
return document.querySelector('.xterm-rows') !== null;
});
if (hasRows) {
@ -179,7 +180,7 @@ describe('Terminal section', () => {
});
it('should have terminal container with correct dimensions', async () => {
const dims = await browser.execute((sel: string) => {
const dims = await exec((sel: string) => {
const el = document.querySelector(sel);
if (!el) return null;
const rect = el.getBoundingClientRect();
@ -192,7 +193,7 @@ describe('Terminal section', () => {
});
it('should have resize handle', async () => {
const hasHandle = await browser.execute(() => {
const hasHandle = await exec(() => {
return document.querySelector('.resize-handle')
?? document.querySelector('.terminal-resize') !== null;
});