Test
v1.3.7Server & Client — write tests anywhere with lib.test.add, then run them from the server console with dirktest. It is console-only: a connected player can never trigger a test run.
lib.test is a lightweight, Jest-style test runner. It's ideal for validating bridges (inventory / framework / …) and any server logic with a single console command — including bridge-compat suites that stay green across ox / qb / qs / devix / bp / etc.
lib.test.add
Register a test. The callback runs inside a coroutine, so it can lib.callback.await(...), call lib.inventory / lib.player, and Wait() freely.
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | true | Test name (also what the console filter matches) |
| fn | function | true | function(ctx) ... end — receives the test context |
| opts | table | false | { requiresPlayer, context, skip } (see below) |
opts
| Key | Type | Description |
|---|---|---|
| requiresPlayer | boolean | Passes a connected player src as ctx.player; the test is skipped if no player is online |
| context | string | 'server', 'client' or 'shared' (default) — the test only runs in a matching context |
| skip | boolean | Reported as skipped |
The test context (ctx)
| Field | Description |
|---|---|
ctx.expect(v) | Chainable matchers (below); each throws on failure |
ctx.player | Target player src (server + requiresPlayer) or the local server id (client) |
ctx.fail(msg) | Force-fail with a message |
Matchers
Running tests
From the server console only:
Arguments are [nameFilter] [playerId] [+c] in any order.
dirktest is console-only (guarded by source == 0) and registered as a restricted command — a player cannot run it whatever their permissions. requiresPlayer tests briefly mutate a player's inventory/data and restore afterwards, so run them on a test server, not a live one.
Example
Enabling it in your resource
The runner activates once lib.test is loaded. To guarantee it's available on both server and client (the client half powers the +c leg), declare it in your fxmanifest.lua:
Cross-context note: lib.test lazy-loads per context, so the server command and the client endpoint only register when lib.test is touched in each context. The dirk_lib 'test' manifest flag force-loads it in both — which is why it's the recommended setup rather than relying on a lazy touch.