MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / platform_test_builder

Function platform_test_builder

sdks/rust/tests/test.rs:6–93  ·  view source on GitHub ↗
(client_project: &str, run_selector: Option<&str>)

Source from the content-addressed store, hash-verified

4use spacetimedb_testing::sdk::{Test, TestBuilder};
5
6fn platform_test_builder(client_project: &str, run_selector: Option<&str>) -> TestBuilder {
7 let builder = Test::builder();
8 let builder = builder.with_client(client_project);
9
10 // Note: `run_selector` is intentionally interpreted differently by mode:
11 // - Native mode uses it as a CLI subcommand (`cargo run -- <selector>`), with `None` => `cargo run`.
12 // - Web mode assembles the Node/wasm-bindgen commands directly in this test harness.
13 #[cfg(feature = "browser")]
14 {
15 let package_name = Path::new(client_project)
16 .file_name()
17 .and_then(|name| name.to_str())
18 .expect("client project path should end in a UTF-8 directory name")
19 .to_owned();
20 let artifact_name = package_name.replace('-', "_");
21 let target_dir = std::env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| {
22 // Cargo workspace members emit into the workspace target directory, not each crate's
23 // local `./target`. Use `CARGO_TARGET_DIR` when set, otherwise fall back to the
24 // workspace target.
25 Path::new(env!("CARGO_MANIFEST_DIR"))
26 .join("../../target")
27 .to_string_lossy()
28 .into_owned()
29 });
30 let bindgen_out_dir = format!("{client_project}/target/sdk-test-web-bindgen/{package_name}");
31 let wasm_path = format!("{target_dir}/wasm32-unknown-unknown/debug/deps/{artifact_name}.wasm");
32 let js_module = format!("{bindgen_out_dir}/{artifact_name}.js");
33 let js_module_cjs = format!("{bindgen_out_dir}/{artifact_name}.cjs");
34 let build_command = "cargo build --target wasm32-unknown-unknown --no-default-features --features browser";
35 let mkdir_command = shlex::try_join(["mkdir", "-p", bindgen_out_dir.as_str()])
36 .expect("bindgen output path should be shell-quotable");
37 let bindgen_command = shlex::try_join([
38 "wasm-bindgen",
39 "--target",
40 "nodejs",
41 "--out-dir",
42 bindgen_out_dir.as_str(),
43 wasm_path.as_str(),
44 ])
45 .expect("wasm-bindgen command should be shell-quotable");
46 let cp_command = shlex::try_join(["cp", js_module.as_str(), js_module_cjs.as_str()])
47 .expect("bindgen JS output paths should be shell-quotable");
48 let compile_command = format!(
49 "/bin/bash -lc \
50 \"{build_command} \
51 && {mkdir_command} \
52 && {bindgen_command} \
53 && {cp_command}\""
54 );
55 let js_module = format!("{bindgen_out_dir}/{artifact_name}.cjs");
56 let run_selector = run_selector.unwrap_or_default();
57 let node_script = format!(
58 "(async () => {{ \
59 const m = require({js_module:?}); \
60 if (m.default) {{ await m.default(); }} \
61 const run = m.run || m.main || m.start; \
62 if (!run) throw new Error(\"No exported run/main/start function from wasm module\"); \
63 const dbName = process.env.SPACETIME_SDK_TEST_DB_NAME; \

Callers 1

make_testFunction · 0.85

Calls 9

with_clientMethod · 0.80
replaceMethod · 0.80
into_ownedMethod · 0.80
joinMethod · 0.80
with_compile_commandMethod · 0.80
newFunction · 0.50
to_ownedMethod · 0.45
as_strMethod · 0.45
with_run_commandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…