@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
95 lines (94 loc) • 2.98 kB
TypeScript
/**
* @module Lock
*/
import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest";
import { type ILockFactory } from "../../../lock/contracts/_module.js";
import { type ISerde } from "../../../serde/contracts/_module.js";
import { type ITimeSpan } from "../../../time-span/contracts/_module.js";
import { type Promisable } from "../../../utilities/_module.js";
/**
* IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"`
* @group Utilities
*/
export type LockFactoryTestSuiteSettings = {
expect: ExpectStatic;
test: TestAPI;
describe: SuiteAPI;
beforeEach: typeof beforeEach;
createLockFactory: () => Promisable<{
lockFactory: ILockFactory;
serde: ISerde;
}>;
/**
* @default true
*/
excludeSerdeTests?: boolean;
/**
* @default true
*/
excludeEventTests?: boolean;
/**
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromMilliseconds(10)
* ```
*/
delayBuffer?: ITimeSpan;
/**
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span";
*
* TimeSpan.fromMilliseconds(10)
* ```
*/
timeSpanEqualityBuffer?: ITimeSpan;
/**
* @default
* ```ts
* import { TimeSpan } from "@daiso-tech/core/time-span"
*
* TimeSpan.fromMilliseconds(10)
* ```
*/
eventDispatchWaitTime?: ITimeSpan;
};
/**
* The `lockFactoryTestSuite` function simplifies the process of testing your custom implementation of {@link ILock | `ILock`} with `vitest`.
*
* IMPORT_PATH: `"@daiso-tech/core/lock/test-utilities"`
* @group Utilities
* @example
* ```ts
* import { describe, expect, test, beforeEach } from "vitest";
* import { MemoryLockAdapter } from "@daiso-tech/core/lock/memory-lock-adapter";
* import { LockFactory } from "@daiso-tech/core/lock";
* import { EventBus } from "@daiso-tech/core/event-bus";
* import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/memory-event-bus-adapter";
* import { lockFactoryTestSuite } from "@daiso-tech/core/lock/test-utilities";
* import { Serde } from "@daiso-tech/core/serde";
* import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter";
* import type { ILockData } from "@daiso-tech/core/lock/contracts";
*
* describe("class: LockFactory", () => {
* lockFactoryTestSuite({
* createLockFactory: () => {
* const serde = new Serde(new SuperJsonSerdeAdapter());
* const lockFactory = new LockFactory({
* serde,
* adapter: new MemoryLockAdapter(),
* });
* return { lockFactory, serde };
* },
* beforeEach,
* describe,
* expect,
* test,
* serde,
* });
* });
* ```
*/
export declare function lockFactoryTestSuite(settings: LockFactoryTestSuiteSettings): void;