### Build Project with npm Source: https://github.com/spinframework/spin-test/blob/main/examples/test-js/README.md Installs project dependencies and executes the build script using npm and Node.js. Requires Node.js and npm to be installed. ```shell npm install && node run build ``` -------------------------------- ### Install spin-test as Local Spin Plugin Source: https://github.com/spinframework/spin-test/blob/main/README.md Installs a locally built version of the spin-test plugin. This command requires the `pluginify` plugin to be installed as a prerequisite. ```bash spin pluginify -i ``` -------------------------------- ### Build Command Source: https://github.com/spinframework/spin-test/blob/main/examples/test-rs/README.md Builds the Rust test project using cargo-component in release mode. Requires cargo-component to be installed. ```shell cargo component build --release ``` -------------------------------- ### Install spin-test as Spin Plugin Source: https://github.com/spinframework/spin-test/blob/main/README.md Installs the canary version of the spin-test plugin from a provided URL. This allows invoking the test runner using the `spin test` command. Note that canary versions may contain breaking changes. ```bash spin plugin install -u https://github.com/spinframework/spin-test/releases/download/canary/spin-test.json ``` -------------------------------- ### Run spin test Command Source: https://github.com/spinframework/spin-test/blob/main/README.md Executes the installed spin-test plugin to run tests against the Spin application. This command should be run from the directory containing the Spin application's manifest. ```bash spin test ``` -------------------------------- ### Set WASI SDK Path Source: https://github.com/spinframework/spin-test/blob/main/CONTRIBUTING.md Sets the WASI_SDK_PATH environment variable to point to the installed WASI SDK. This is a prerequisite for building the project from source, as it's needed for the C compiler used for some dependencies. ```bash export WASI_SDK_PATH=~/.wasi-sdk-22.0 ``` -------------------------------- ### Build spin-test from Source Source: https://github.com/spinframework/spin-test/blob/main/CONTRIBUTING.md Builds the spin-test project in release mode using Cargo. This command should be run after ensuring the WASI_SDK_PATH environment variable is correctly set. ```rust cargo build --release ``` -------------------------------- ### Rust SDK for spin-test Source: https://github.com/spinframework/spin-test/blob/main/README.md Information about the Rust SDK provided by spin-test. This SDK facilitates writing WebAssembly tests in Rust that can be run against Spin applications using the spin-test framework. It targets the `fermyon:spin-test/test` world. ```rust # First-class support for Rust through the `spin-test` Rust SDK # Targets the `fermyon:spin-test/test` world # See definition in ./host-wit/world.wit ``` -------------------------------- ### Configure spin-test in spin.toml Source: https://github.com/spinframework/spin-test/blob/main/README.md Defines the configuration for the spin-test tool within the Spin application's `spin.toml` manifest. This includes specifying the path to the built test component, the command to build it, and the working directory for the build process. ```toml [component.my-component.tool.spin-test] # A relative path to where the built test component binary will live. source = "target/wasm32-wasip1/release/test.wasm" # A command for building the target component. build = "cargo component build --release" # The directory where the `build` command should be run. workdir = "../../test-rs" ``` -------------------------------- ### Interact with Key-Value Store in Rust Spin Tests Source: https://github.com/spinframework/spin-test/blob/main/crates/spin-test-sdk/README.md Illustrates how to access and manipulate the `key-value` store within a `spin-test` Rust test. This includes opening the store and setting key-value pairs before executing application logic. ```rust // Open the store let key_value = key_value::Store::open("default"); // Set state of the key-value store key_value.set("123", "abc"); // Now make our request to the Spin app... ``` -------------------------------- ### Define Spin Test with HTTP Request in Rust Source: https://github.com/spinframework/spin-test/blob/main/crates/spin-test-sdk/README.md Demonstrates how to define a test function using the `#[spin_test]` attribute in Rust. It shows how to make an HTTP request to a Spin application and assert the response status code. ```rust use spin_test_sdk::{bindings::wasi::http, spin_test}; #[spin_test] fn my_test() { // Make a request to the Spin application let request = http::types::OutgoingRequest::new(http::types::Headers::new()); request.set_path_with_query(Some("/?user_id=123")).unwrap(); let response = spin_test_sdk::perform_request(request); // Assert response status assert_eq!(response.status(), 200); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.