@reintersect/sdk/effect/testing runs your app against an in-memory Reintersect host, the same host
as the Promise testing kit, as an Effect. Deliveries go through your app’s real router
inside the test fiber, so your services, TestClock and typed failures work as in any
@effect/vitest test.
Set up a host
makeTestHost(app, options) returns an Effect that builds the host. Run it inside it.scoped:
src/app.test.ts
now: the test clock starts where TestClock is.
To share one host across a suite, provide it as a service with ReintersectTestHost.layer:
src/checklist.test.ts
The host
The Effect host has the same methods as the Promise host, and each returns anEffect: render, insert, act, press, vote, tallies, voters, view, visible,
block, reopen, search, resolveReference, searchReferences, runCommand,
runMessageAction, emit, pushesOf, expectPushed and expectTree. host.as(viewer) returns a
host acting as another member.
A few differ in shape:
Fake a service
Build the host from the app beforeprovide, and give the test its own layer. Here TaskBlock’s
move action is the one from Errors, which calls a
Tracker service. The test swaps in a Tracker that always reports a locked task:
src/moveTask.test.ts
makeTestHost(tasksApp) and ReintersectTestHost.layer(tasksApp) require whatever services the app
hasn’t been given, so the test doesn’t compile until it provides them.
Time
The host reads the time fromClock, so TestClock drives everything that depends on it, such as
staleAfter refreshes on view, signature timestamps and token expiry:
Typed failures
Every host method fails with a tagged error, so you can assert on a failure as a value:Trees
textOf, findNodes, buttonsOf, buttonOf, treeFor, checkTree and TREE_LIMITS work as on
the Promise kit. expectTree(treeOrResult, options?) returns an Effect that
fails with ReintersectTestTreeInvalidError when the tree is invalid.