Fetching documentation…
How we test Morph itself, and how you can test apps built with it.
The JS/TS → C++ translator is covered by fixture tests in tests/translate/:
# Full suite (translates each .ts, compiles with g++-14, runs, diffs vs Node)
python3 -m pytest tests/translate -vHow each fixture works (tests/translate/test_rust_translate.py):
morph <fixture>.ts --to cpp generates <fixture>.cpp"../../runtime/cpp/..." includes to absolute pathsg++-14 -std=c++23 <gen>.cpp runtime/cpp/net/net.cpp runtime/cpp/reactivity/task.cpp -I runtime/cppnpx tsx <fixture>.ts (numeric tolerance, case-insensitive bools)Fixtures (tests/translate/fixtures/):
| Fixture | Covers |
|---|---|
01_variables |
let/const/var, primitives, inference |
02_functions |
functions, arrows, defaults, recursion, generics |
03_classes |
classes, ctors, this, static, new |
04_arrays |
literals, .length, index, push, spread, nesting |
05_objects |
literals, shorthand, computed, nesting |
06_control_flow |
if/switch/for/while/do-while, break/continue |
07_operators |
arithmetic, comparison, ===/!==, ??, += |
08_template_literals |
`Hi ${x}`, nesting, expressions |
09_try_catch |
throw, try/catch/finally, nesting |
10_console_log |
multi-type/multi-arg console.log |
11_complex |
classes + arrays + templates together |
12_string_methods |
length, toUpperCase, split, slice, ... |
13_number_methods |
arithmetic, toString(), templates |
14_inheritance |
extends, super, interfaces, enums |
15_chaining |
s.split().length, method chains |
16_loops |
loop variants, break/continue, while(true) |
17_async |
async/await, fetch, async arrows/methods |
18_promises |
Promise<T>, new Promise, Promise<void>, generics |
19_fetch |
top-level await fetch, loops, dynamic URLs |
20_cpp_types |
int/int32/uint/float/char/size_t, std::vector, std::optional |
Extra regression checks:
JsNumber + println uses <print> but no explicit <format>`a${x},b${y}`) require <format> + std::format<format> nor <print> extras# All Rust unit tests
cargo test --workspace
# Single crate
cargo test -p morph-ir
cargo test -p morpher
cargo test -p morph-parsermorph check
morph check src/App.mxCatches unsupported elements, props, events, CSS, and JS before compiling.
morph devconsole.log outputfetch() trafficKeep pure logic in functions that don't touch JSX, then test the generated C++ directly:
// src/App.mx
export function add(a: number, b: number): number {
return a + b;
}morph logic.ts --to cpp # extract logic to a file, or copy the function
g++-14 -std=c++23 -I runtime/cpp test_main.cpp runtime/cpp/net/net.cpp -o test_app
./test_appOr test the TypeScript directly with Node before compiling:
npx tsx src/logic.tsSame pattern the translator suite uses — compare app output vs expected:
morph build --output bin/
./bin/my-app --headless --dump-state > actual.txt
diff expected.txt actual.txt# .github/workflows/test.yml
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: sudo apt update && sudo apt install -y g++-14 cmake libglfw3-dev libfreetype-dev libharfbuzz-dev
- run: cargo test --workspace
- run: python3 -m pytest tests/translate -x -q
- run: cargo install --path crates/morphc
- run: morph check
- run: morph build| Symptom | What To Check |
|---|---|
| Fixture output differs by whitespace | Tests compare line-by-line; check trailing spaces, println vs print |
g++-14: command not found |
Install GCC 14 (apt install g++-14) or set build.cxx |
npx tsx fails |
npm i -D tsx, Node 18+ required |
.cpp has wrong includes |
Check Ctx::need() / headers_for() in type_resolver.rs |
| Async test hangs | Missing process_tasks() loop, un-awaited Result |
tests/translate/fixtures/21_my_feature.ts (must run clean under npx tsx)python3 -m pytest tests/translate -k 21_my_feature -v.cpp is gitignored (tests/translate/fixtures/*.cpp) — only commit the .ts