To run tests for WebAssembly, install a Swift SDK for WebAssembly by following these instructions.
Because swift test
doesn't know what WebAssembly environment you'd like to use
to run your tests, building tests and running them are two separate steps. To
build tests for WebAssembly, use the following command:
swift build --swift-sdk wasm32-unknown-wasi --build-tests
After building tests, you can run them using a WASI-compliant
WebAssembly runtime such as Wasmtime or
WasmKit. For example, to run tests using
Wasmtime, use the following command (replace {YOURPACKAGE}
with your package's
name):
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm --testing-library swift-testing
Most WebAssembly runtimes forward trailing arguments to the WebAssembly program, so you can pass command-line options of the testing library. For example, to list all tests and filter them by name, use the following commands:
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm list --testing-library swift-testing
wasmtime .build/debug/{YOURPACKAGE}PackageTests.wasm --testing-library swift-testing --filter "FoodTruckTests.foodTruckExists"