Module unit testing - #5558
Open
jsdt wants to merge 37 commits into
Open
Module unit testing#5558jsdt wants to merge 37 commits into
jsdt wants to merge 37 commits into
Conversation
…tore # Conflicts: # Cargo.lock # Cargo.toml # crates/bindings-typescript/src/server/procedures.ts # crates/bindings-typescript/src/server/runtime.ts # crates/bindings-typescript/vitest.config.ts # crates/bindings/src/http.rs # crates/bindings/src/lib.rs # crates/bindings/src/rt.rs # crates/bindings/tests/ui/views.stderr # crates/datastore/src/locking_tx_datastore/committed_state.rs # crates/datastore/src/locking_tx_datastore/datastore.rs # crates/datastore/src/locking_tx_datastore/mut_tx.rs # tools/ci/src/main.rs
jsdt
force-pushed
the
jsdt/portable-datastore-2
branch
from
September 14, 2026 06:21
225987b to
72010c1
Compare
jsdt
marked this pull request as ready for review
September 16, 2026 15:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Adds unit testing support for SpacetimeDB module code in Rust and TypeScript.
The main work here is adding a test datastore API for use in these unit tests. There are some new feature gates added for this, which are described below.
Module Unit Test APIs
spacetimedb::test_utilsfor Rust module tests, includingTestContext,TestAuth, reducer transactions, procedure/view contexts, typed queries, test clock/RNG helpers, and HTTP/sleep hooks.spacetimedb/server/test-utils, with Vitest and WASM runtime helpers.Portable Datastore
spacetimedb-test-datastore, a native in-memory datastore wrapper for Rust module tests.spacetimedb-portable-datastore, a WASM-compatible in-memory datastore initialized from a module definition.spacetimedb-portable-datastore-wasm, a thinwasm-bindgenadapter used by the TypeScript test runtime.spacetimedb-datastorebehind feature gates so portable builds can avoid server-only dependencies:durability: commitlog, snapshot, durability, and path-dependent code.execution: execution-plan-aware transaction/query behavior.metrics: Prometheus/SpacetimeDB metrics plumbing.portable: minimal datastore surface needed by the portable test datastore.wasm32-unknown-unknownguards, including portable time handling wherestd::time::Instant::now()is unavailable.Test Datastore ABI
For Rust module tests, look at:
crates/bindings/src/test_utils.rscrates/test-datastore/src/lib.rscrates/bindings/src/table.rsFor TypeScript module tests, look at:
crates/portable-datastore-wasm/src/lib.rsfor thewasm-bindgenABI.crates/bindings-typescript/src/server/test-utils/wasm.tsfor the TypeScript-side ABI interface.crates/bindings-typescript/src/server/test-utils/backend.tsandcrates/bindings-typescript/src/server/backend.tsfor theDatastoreBackendbridge.Example Usage
Examples are included in the updated chat templates (though I need to either remove these or replace them with tests that are actually meaningful for the templates):
Rust:
templates/chat-console-rs/spacetimedb/src/lib.rsTestContext::new()with_reducer_txTestAuth::from_jwt_payloadprocedure_contextrun_queryTypeScript:
templates/chat-react-ts/spacetimedb/src/index.test.tscreateModuleTestHarness(spacetime, moduleExports)test.withReducerTxtest.procedureContexttest.viewContexttest.runQueryFor exhaustive coverage, see:
crates/bindings/tests/test_utils.rscrates/bindings-typescript/tests/server_test_utils_wasm.test.tsTesting
New test coverage added in this branch:
crates/bindings/tests/test_utils.rscrates/test-datastore/src/lib.rscrates/portable-datastore/src/lib.rscrates/bindings-typescript/tests/server_test_utils_wasm.test.tscrates/bindings-typescript/tests/server_test_utils_wasm_adapter.test.tstemplates/chat-console-rs/spacetimedb/src/lib.rstemplates/chat-react-ts/spacetimedb/src/index.test.tsAdds
cargo ci portable-datastore, wired into GitHub Actions as theportable_datastorejob. This checks that the portable datastore path stays buildable forwasm32-unknown-unknownwithout the normal server-only dependency stack, then runs native portable datastore tests.