Building and Testing the Plugin
Relevant source files
The following files were used as context for generating this wiki page:
The tauri-plugin-centrifugo project utilizes a dual-language build system to support its Rust-based core logic and its JavaScript/TypeScript API. Building the plugin involves compiling the Rust backend into a library and bundling the JavaScript guest bindings for frontend consumption.
Testing is performed across multiple layers, ranging from standard Rust unit tests to a complete example Svelte application that demonstrates real-time communication with a Centrifugo server. This ensures platform compatibility across Linux, Windows, macOS, Android, and iOS.
Sources: README.md:12-20, README.md:43-50, src/lib.rs:7-15
Build System Architecture
The project is structured as a standard Tauri plugin. It requires building the guest-side JavaScript assets and the host-side Rust crate.
JavaScript API Bundling
The JavaScript API is located in the guest-js directory (referenced by the rollup configuration) and is bundled using Rollup. The process converts TypeScript source files into both ECMAScript Modules (ESM) and CommonJS (CJS) formats.
The bundling process is managed by rollup.config.js, which uses the @rollup/plugin-typescript to generate declarations.
Sources: rollup.config.js:1-32, package.json:11-20
Rust Backend Compilation
The backend is a Rust library managed by Cargo. It depends on tauri (v2.6.2) and tokio-centrifuge (v0.2.6) for core WebSocket communication logic.
| Build Command | Purpose |
|---|---|
cargo build | Compiles the Rust plugin crate |
pnpm build | Runs rollup to build JavaScript API |
pnpm release | Executes both JavaScript and Rust builds |
Sources: Cargo.toml:1-25, package.json:28-32, README.md:320-335
Testing Procedures
Testing ensures that the command handlers and event-driven architecture function correctly across the bridge between Rust and JavaScript.
Automated Testing
The project includes standard automated tests for the Rust logic.
- Rust Unit Tests: Invoked via
cargo testto verify internal logic and models. - Linting/Type Checking: Frontend code is validated using
tsc(TypeScript compiler).
Sources: README.md:337-345, examples/server/package.json:12
Integration Testing with Example App
The primary method for verifying end-to-end functionality is the provided example Svelte application located in examples/tauri-app. This app tests:
- Connection Logic: Establishing WebSocket connections with various configurations.
- Event Handling: Listening for
onConnected,onDisconnected, andonPublicationevents. - Command Invocation: Executing RPC calls and publishing messages.
Environment Setup for Development
To test the plugin in a live environment, a Centrifugo server must be running. The repository provides a server example using gRPC and WebSockets.
Running the Test Environment
- Start Centrifugo: Execute the server in debug mode.
cd examples/server npm run centrifugo:dev - Start Example App: Run the Tauri development environment.
cd examples/tauri-app pnpm install pnpm tauri dev
Sources: examples/server/README.md:5-15, README.md:310-318
Build and Test Dependencies
The following core dependencies are required for the build process:
- Rust Toolchain:
edition = "2021",rust-version = "1.77.2". - Node.js Environment:
pnpmornpm,rollup,typescript. - Tauri CLI: Used for running the dev server and building the application bundle.
Sources: Cargo.toml:6-7, package.json:34-40, examples/tauri-app/package.json:15-25
Summary
Building and testing the tauri-plugin-centrifugo requires a synchronized workflow between Rust and TypeScript. The use of Rollup for guest JS bundling and Cargo for the Rust backend ensures that both sides of the Tauri bridge are properly compiled. Testing is heavily reliant on the integrated Svelte example app, which validates the event-driven architecture and cross-platform compatibility.