new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Tauri · Develop · all subjects

testing

22 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

tauri-driver installation command

Install or update tauri-driver by running: cargo install tauri-driver --locked

tauri-driver platform support for manual setup

When driving tauri-driver directly without the @wdio/tauri-service, only Windows and Linux are supported on desktop. macOS is not supported because there is no WKWebView driver tool available. iOS and Android work through Appium 2, but the process is not currently streamlined.

Windows Edge Driver version matching requirement

On Windows, the version of Microsoft Edge Driver must match the Windows Edge version that the application is being built and tested on. If the two versions do not match, the WebDriver testing suite may hang while trying to connect. This should almost always be the latest stable version on up-to-date Windows installs.

msedgedriver-tool for Windows Edge Driver

Use the msedgedriver-tool to download the appropriate Microsoft Edge Driver for Windows. Install it with: cargo install --git https://github.com/chippers/msedgedriver-tool. Run it with: & "$HOME/.cargo/bin/msedgedriver-tool.exe". The download contains msedgedriver.exe which tauri-driver looks for in $PATH or can be specified with the --native-driver option.

When to use manual tauri-driver setup

Use manual tauri-driver setup instead of @wdio/tauri-service if you are not using Node.js, prefer Selenium, or are integrating WebDriver into a custom test harness. For most projects the service is easier as it automates the manual steps and additionally supports macOS.

Linux WebDriver dependency

On Linux, tauri-driver uses WebKitWebDriver. Check if this binary exists by running 'which WebKitWebDriver'. Some distributions bundle it with the regular WebKit package. Other platforms may have a separate package such as webkit2gtk-driver on Debian-based distributions.

End-to-end testing with WebDriver protocol

Tauri provides support for end-to-end testing utilizing the WebDriver protocol. WebdriverIO Tauri testing supports Windows, Linux, and macOS. The WebDriver protocol can also be driven directly on Windows and Linux, but macOS provides no desktop WebDriver client.

GitHub Actions support for Tauri testing

Tauri offers tauri-action to help run GitHub actions. Any sort of CI/CD runner can be used with Tauri as long as each platform has the required libraries installed to compile against.

Unit and integration testing with mock runtime

Tauri offers support for both unit and integration testing utilizing a mock runtime. Under the mock runtime, native webview libraries are not executed.

Mock event system example with emit and listen

Example showing how to mock events: ```javascript import { mockIPC, clearMocks } from '@tauri-apps/api/mocks'; import { emit, listen } from '@tauri-apps/api/event'; import { afterEach, expect, test, vi } from 'vitest'; test('mocked event', () => { mockIPC(() => {}, { shouldMockEvents: true }); // enable event mocking const eventHandler = vi.fn(); listen('test-event', eventHandler); emit('test-event', { foo: 'bar' }); expect(eventHandler).toHaveBeenCalledWith({ event: 'test-event', payload: { foo: 'bar' }, }); }); ```

emitTo and emit_filter not supported in mocked events

The event mocking feature does not support emitTo and emit_filter yet.

mockWindows function for simulating multiple windows

The mockWindows() method creates fake window labels for testing window-specific code. The first string argument identifies the 'current' window (the window the JavaScript code believes it is in), and all other string arguments represent additional windows.

mockWindows only simulates window existence, not properties

The mockWindows() method only fakes the existence of windows but does not simulate window properties. To simulate window properties, you need to intercept the correct calls using mockIPC().

mockWindows example with getCurrent and getAll

Example showing how to mock multiple windows: ```javascript import { mockWindows } from '@tauri-apps/api/mocks'; import { getCurrent, getAll } from '@tauri-apps/api/webviewWindow'; test('invoke', async () => { mockWindows('main', 'second', 'third'); expect(getCurrent()).toHaveProperty('label', 'main'); expect(getAll().map((w) => w.label)).toEqual(['main', 'second', 'third']); }); ```

mockIPC function for intercepting IPC requests

The @tauri-apps/api/mocks module provides mockIPC() to intercept IPC requests in frontend tests. This function allows you to simulate backend responses and test that correct backend calls are made. The mockIPC function takes a callback with parameters (cmd, args) where cmd is the command name and args are the command arguments.

Clear mocks after each test to prevent state pollution

Remember to call clearMocks() after each test run to undo mock state changes between runs. This prevents mocked state from affecting subsequent test runs.

mockIPC example for command mocking with invoke

Example showing how to mock a simple Rust command called 'add' that adds two numbers: ```javascript import { mockIPC } from "@tauri-apps/api/mocks"; import { invoke } from "@tauri-apps/api/core"; test("invoke simple", async () => { mockIPC((cmd, args) => { if(cmd === "add") { return (args.a as number) + (args.b as number); } }); }); ```

Track IPC calls using Vitest spies with mockIPC

You can combine mockIPC() with Vitest's vi.spyOn() to track information about IPC calls, such as how many times a command was invoked. Spy on window.__TAURI_INTERNALS__.invoke to capture invocation details.

Mock sidecar or shell command events with event emitter ID

To mock IPC requests to sidecar or shell commands via spawn() or execute(), grab the event handler ID when the command is called and use it to emit events the backend would send back. The event callback ID follows the pattern `_${args.message.onEventFn}`. Emit 'Stdout' events (which can be called multiple times) and finish with a 'Terminated' event containing code and signal properties.

Mock sidecar events example code

Example showing how to mock execute() events: ```javascript mockIPC(async (cmd, args) => { if (args.message.cmd === 'execute') { const eventCallbackId = `_${args.message.onEventFn}`; const eventEmitter = window[eventCallbackId]; // 'Stdout' event can be called multiple times eventEmitter({ event: 'Stdout', payload: 'some data sent from the process', }); // 'Terminated' event must be called at the end to resolve the promise eventEmitter({ event: 'Terminated', payload: { code: 0, signal: 'kill', }, }); } }); ```

mockIPC does not run real webview or Rust backend

mockIPC fakes invoke under the mock runtime and does not run a real webview or Rust backend. For end-to-end tests against a running app or frontend in a browser, use @wdio/tauri-service which provides browser.tauri.mock().

Mock event system with shouldMockEvents option

The mockIPC function supports partial mocking of the Event System via the shouldMockEvents option (available since version 2.7.0). Pass { shouldMockEvents: true } as the second parameter to mockIPC to enable event mocking. This allows you to simulate events emitted by Rust code in tests.

Give your agent this brain