Skip to content

Commit 1b6b4be

Browse files
committed
refactor(tauri): correct script wrapping in execute function
- Updated the `execute` function to properly wrap string scripts in an IIFE with braces, ensuring correct syntax for execution. - Adjusted related test cases to reflect the updated script format, enhancing the accuracy of expectations for script execution.
1 parent 4d80fcb commit 1b6b4be

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

packages/tauri-service/src/service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export default class TauriWorkerService {
323323
// - embedded: pass as-is (WebDriver handles execution)
324324
// - non-embedded: wrap in async IIFE to make statement expressions callable
325325
const scriptString =
326-
typeof script === 'function' ? script.toString() : isEmbedded ? script : `(async () => ${script})()`;
326+
typeof script === 'function' ? script.toString() : isEmbedded ? script : `(async () => { ${script} })()`;
327327

328328
if (isEmbedded) {
329329
// For embedded WebDriver: skip console wrapper as console forwarding

packages/tauri-service/test/service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('TauriWorkerService', () => {
100100
(service as any).patchBrowserExecute(mockBrowser);
101101
mockBrowser.execute('return document.title');
102102

103-
expect(mockExecute).toHaveBeenCalledWith(expect.stringContaining('(async () => return document.title)()'));
103+
expect(mockExecute).toHaveBeenCalledWith(expect.stringContaining('(async () => { return document.title })()'));
104104
});
105105

106106
it('should pass function scripts as-is for non-embedded providers', () => {

0 commit comments

Comments
 (0)