Skip to main content

Module testing

Module testing 

Source
Expand description

In-process testing: dispatch requests through the full protection / router / middleware / handler path without binding a socket. This is the foundation of nitr test and of Rust-level integration tests.

Also here, because they need crate-private types: the request options nitr.test.request understands (TestRequest), the fake request and the in-state application nitr test unit tests use (fake_request, load_app), the server-sent-events parser behind resp:sse() (parse_sse), and the watcher behind nitr test --watch.

Structs§

HandlerFailure
Why a request answered with the error path: the classified failure the handler raised, and whether the application’s on_error produced the response.
SseEvent
One dispatched server-sent event.
TestClient
An in-process client for a built Server; obtained via Server::test_client().
TestRequest
One test request: what TestClient::send dispatches.
TestResponse
A fully collected response from TestClient::request.
TestWatch
Keeps the nitr test --watch watcher alive; dropping it stops the watcher thread.

Functions§

fake_request
Builds a request userdata for a unit test (t.fake_request(spec)): the same type a handler receives, so req.*, req:json(), nitr.session(req, ...), nitr.csrf.token(req) and nitr.auth.* behave as in production.
fixture_path
Resolves a fixture file a test names (t.db.seed("fixtures/x.sql")) under root, the tests directory: the static server’s lexical rule (no .., no absolute path, no NUL), then canonical containment, and it must be a regular file.
load_app
Compiles the application into this state and returns the object t.app() hands a test.
parse_sse
Parses a whole event-stream body into its events, in order.
watch_tests
Watches what nitr dev watches (the handler’s directory, the configuration script, the templates) plus extra (the tests directory), sending on changed after each debounced burst of changes to a Lua source or a template. None when there is nothing to watch or the platform watcher is unavailable.