Skip to content

@xtandard/kit/storage/testing

@xtandard/kit/storage/testing — the shared storage conformance suite. The test API is injected ({ describe, test, expect } from vitest, bun:test, …), so products run the same cases against their wrapped drivers and register extra suites with runConformanceCases.

import { … } from "@xtandard/kit/storage/testing";
Name Summary
asRedisClient Cast a fake to the client option type of the redis driver factories.
fakeRedis An in-memory node-redis look-alike: string and RedisJSON values, the driver’s two Lua scripts emulated, a SCAN that yields every key twice (Redis may repeat keys), and PSUBSCRIBE with real glob matching (so an unescaped prefix would miss events).
requireCompareAndSwap Narrow to CompareAndSwapKvStorage or throw a clear error.
requireWatchable Narrow to WatchableKvStorage or throw a clear error.
runConformanceCases Register describe(title, …) with one test per case. Each test gets a fresh storage from make. This is how products register their own extra suites next to runStorageConformance.
runStorageConformance Register the full conformance suite for one driver: the base contract, plus the compare-and-swap and watch cases when capabilities says the driver has them.
settle Resolve after ms milliseconds.
Name Summary
ConformanceCapabilities The optional capabilities the driver under test implements. Declare each one: a capability case checks the declaration against the storage itself, so a driver that implements compareAndSwap or watch without declaring it (or declares one it lacks) fails instead of silently skipping cases. Pass false for a capability the driver doesn’t have.
ConformanceCase One named case. Products register extra suites as lists of these.
ConformanceContext What a ConformanceCase receives.
ConformanceMatchers The matchers the suite uses. vitest’s and bun:test’s expect both satisfy it.
ConformanceOptions Options for runStorageConformance.
ConformanceTestApi The injected test API: pass { describe, test, expect } from your runner.
FakeRedisOptions Options for fakeRedis.
Name Summary
FakeRedis The fake’s state, exposed for assertions.
MakeStorage A factory producing a fresh, empty storage (or an empty namespace of one) for each test.
SeedLegacy Write a value in a legacy, non-canonical stored form, bypassing the driver (e.g. a raw SQL INSERT of json text with unsorted keys, a Mongo document with fields in insertion order). Enables the legacy-value CAS case (ADR 0005).
Name Summary
capabilitiesCase The declared capabilities match the storage: an undeclared compareAndSwap or watch would skip those cases silently, and a declared one the storage lacks would fail them obscurely.
compareAndSwapCases The compare-and-swap cases (capabilities.compareAndSwap).
contractCases The base-contract cases every driver must pass.
watchCases The watch cases (capabilities.watch).