Developer tools
Testing Rune
Write tests in the same language as your application. This suite covers health, validation failures, fresh memory, and a create → fetch → update workflow.
Setup, fixtures, and teardown
@TestSuite setup runs before every test. fixtures = [User] selects @TestFixture/User. Order: suite setup → named fixture setup → test setup → run. Teardown reverses that order. Fixture variables are available to the test.
#!RUNE
import "app.rune"
@TestSuite
setup:
expected = { defaultName: "Guest" }
@TestFixture/User
setup:
alice = { name: "Alice", role: "admin" }
teardown:
clear-memory
@Test/Health
run:
req = { method: "GET", path: "/health" }
res = test-request req
assert res.status == 200
assert res.text == "OK"
@Test/UserCreation
run:
req = { method: "POST", path: "/users", body: { name: "Alice", role: "admin" } }
res = test-request req
assert res.status == 201
assert res.body.name == "Alice"
assert res.body.role == "admin"
@Test/InvalidUser
run:
req = { method: "POST", path: "/users", body: { name: "Alice" } }
res = test-request req
assert res.status == 400
assert res.text contains "role"
@Test/UserLifecycle
fixtures = [User]
run:
req = { method: "POST", path: "/users", body: alice }
created = test-request req
assert created.status == 201
req = { path: "/users/current" }
fetched = test-request req
assert fetched.body.name == "Alice"
updatedUser = { name: "Alice", role: "developer" }
req = { method: "PUT", path: "/users/current", body: updatedUser }
updated = test-request req
assert updated.status == 200
assert updated.body.role == "developer"
@Test/MemoryIsFresh
run:
req = { path: "/users/current" }
res = test-request req
assert res.body.name == expected.defaultName
JavaScript logic tests · 0.3.4
Use type = logic and page = studio to test the real Rune-Web actions. invoke calls an action with optional JSON arguments; assert checks state, derived values or recorded mock effects. Native and logic tests run together by default. Each logic test gets a fresh JavaScript runtime, with optional setup and teardown.
vectrune test examples/rune-web/studio
vectrune test examples/rune-web/studio --type logic --json#!RUNE
# JavaScript logic tests: vectrune test examples/rune-web/studio (or --type logic)
import "rune_studio.rune"
@Test/StudioLogic/Tempo
type = logic
page = studio
run:
assert state.tempo == 136
invoke changeTempo 4
assert state.tempo == 140
assert state.status_message == "Tempo: 140 BPM"
assert mock.audio[0].operation == "music.tempo"
assert mock.audio[0].args[0] == 140
invoke changeTempo 1000
assert state.tempo == 240
invoke changeTempo -1000
assert state.tempo == 40
@Test/StudioLogic/SaveLoad
type = logic
page = studio
setup:
invoke selectSong "moonlight"
run:
invoke changeTempo 4
invoke saveToStorage
assert mock.storage.rune_studio_last_song == "moonlight"
assert mock.storage.rune_studio_moonlight.tempo == 112
invoke changeTempo 20
assert state.tempo == 132
invoke loadFromStorage
assert state.tempo == 112
assert state.status_message contains "Restored"
@Test/StudioLogic/Export
type = logic
page = studio
run:
invoke selectSong "moonlight"
invoke exportRune
assert mock.downloads[0].filename == "moonlight.rune"
assert mock.downloads[0].content contains "@Music/moonlight\ntype = 8bit\ntempo = 108"
assert mock.downloads[0].content contains "\nlead:\n "
invoke copyCode
assert mock.clipboard[0] == mock.downloads[0].content
@Test/StudioLogic/Isolation
type = logic
page = studio
run:
assert state.tempo == 136
assert state.selected_song == "vectworms"
assert state.song_title == "VectWorms"
assert state.lead_instrument == "pulse"
assert state.chords_instrument == "sine"
assert state.lead_track contains "C4:8 E4:8 G4:8"
assert mock.storage == {}
assert mock.downloads == []
assert mock.clipboard == []
@Test/StudioLogic/Playback
type = logic
page = studio
run:
invoke playTrack
assert state.is_playing == true
assert state.status_message contains "Playing: VectWorms"
invoke stopTrack
assert state.is_playing == false
assert state.is_paused == false
This first runner supports synchronous actions. DOM/layout, timers, asynchronous jobs, network mocks and shared logic fixtures remain future work. Use the Playwright companion for actual browser interactions. The examples below run from the Vectrune repository.
Keep test files out of live builds
Use .test.rune for tests, fixtures, and suite hooks. Application directory imports skip these files recursively, and explicit imports from application files are rejected. Test files can import application code and explicitly import other test helpers. Directory imports always skip tests; vectrune test discovers them separately. Lambda bundles omit test files too.
Isolation and failure behavior
Rune memory is reset and application startup reruns for each test. Assertion, setup, startup, and teardown failures fail the test. Cleanup runs after setup/assertion failure or timeout and has a separate bounded budget. Abrupt termination cannot guarantee cleanup. External files and databases are not rolled back.
Keep the feedback loop open
Watch mode reruns after Rune source, imports, or JSON/YAML/CSV fixture edits. It handles atomic saves, missing imports, and later repairs. Stop with Ctrl-C; the exit status reflects the last completed run while waiting.
vectrune test . --watch
vectrune test . --filter UserLifecycle --timeout 5