Skip to content

@xtandard/audit/testing

Testing utilities: an in-memory core, a collecting sink and assertions, so a host app (or this package’s own suite) can test its audit wiring without a database, timers or the network.

  • createTestAudit: an in-memory core, a collectingSink behind a not-started stream runner (drive it with flush()), an optional panel, and events() to read back everything recorded.
  • collectingSink: a sink that keeps every batch it receives — with programmable failures to exercise the stream retry path.
  • expectRecorded / expectNotRecorded: framework-agnostic assertions (they throw a descriptive Error) over what a core recorded.
import { … } from "@xtandard/audit/testing";
Name Summary
collectingSink Create a CollectingSink.
createTestAudit An in-memory audit core for tests, with a collecting sink streamed from the beginning of every tenant’s log. No timers run: call flush() to stream.
expectNotRecorded Assert that core recorded no event matching matcher.
expectRecorded Assert that core recorded an event matching matcher (deep subset). Resolves to the newest matching event; throws a descriptive Error (listing what was recorded instead) otherwise. Works with any test runner.
Name Summary
CollectingSink A sink that records every batch it is sent.
RecordedMatcher What expectRecorded matches: every given field must match (deep subset).
TestAudit Result of createTestAudit.
TestAuditOptions Options for createTestAudit.