stateAdapterConformanceCases
VariableSignature
const stateAdapterConformanceCases: ConformanceTestCase<StateAdapterConformanceContext>[];core/src/conformance.state-adapter/state-adapter-cases.ts:49
The state adapter conformance cases every adapter must pass, to run one per test in your own
test file. An async adapter also runs asyncStateAdapterConformanceCases, and an adapter
that runs transactions in parallel, such as one over a connection pool, also runs
concurrentStateAdapterConformanceCases.
Each case creates its own adapter with the context's createStateAdapter and closes it when
the case ends, and runs in the adapter's mode: over a sync adapter (sync: true) every call
must return a plain value and throw rather than reject, and over an async one it must return a
promise. Works with any test runner.
Example
TypeScript
import { afterAll, test } from "vitest";
const db = openMyDatabase();
afterAll(async () => db.close());
const context: StateAdapterConformanceContext = {
createStateAdapter: async () => {
const adapter = createMyStateAdapter({ db });
await adapter.migrateToLatest();
await clearTables(db);
return adapter;
},
withNonTransactionContext: async (fn) => fn({ db }),
};
for (const conformanceCase of stateAdapterConformanceCases) {
test(conformanceCase.title, async () => {
await conformanceCase.run(context);
});
}