openpencil/tests/helpers/tauri/invoke.ts
Danila Poyarkov f2485d6926
fix(desktop): allow reading recent .fig files for thumbnails (#872)
* fix(desktop): allow reading recent .fig files for thumbnails

The recent-files thumbnail loader stats a .fig file, opens it, and seeks
and reads its thumbnail entry, but the desktop capability granted none of
those fs commands, so the WebView rejected the first call ("fs.stat not
allowed") and no thumbnail ever loaded. Grant stat and open with the same
path scope as read-file, plus the handle commands they lead to.

A native spec runs the loader's command sequence on a real .fig file.

* test(desktop): check the bytes the recent-file thumbnail read returns

The native spec discarded the read result, so a read returning nothing would pass. Assert the zip signature and the byte count the fs plugin appends, through a bytes variant of the native invoke helper.
2026-10-04 13:03:20 +00:00

34 lines
1.1 KiB
TypeScript

import type { invoke } from '@tauri-apps/api/core'
type InvokeArguments = Parameters<typeof invoke>[1]
/** Invoke inside the built WebView; package imports cannot execute in serialized callbacks. */
export async function invokeNative<T>(command: string, args?: InvokeArguments): Promise<T> {
return browser.execute(
async (command, args) => {
const core = window.__TAURI__?.core
if (!core) throw new Error('Native test requires app.withGlobalTauri')
return core.invoke<T>(command, args)
},
command,
args
)
}
/** Invoke a command that returns raw bytes; WebDriver cannot serialize an ArrayBuffer. */
export async function invokeNativeBytes(
command: string,
args?: InvokeArguments
): Promise<number[]> {
return browser.execute(
async (command, args) => {
const core = window.__TAURI__?.core
if (!core) throw new Error('Native test requires app.withGlobalTauri')
const data = await core.invoke<ArrayBuffer | number[]>(command, args)
return Array.from(data instanceof ArrayBuffer ? new Uint8Array(data) : data)
},
command,
args
)
}