UNPKG

@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) 3.13 kB
/** * @module Semaphore */ import { type TestAPI, type SuiteAPI, type ExpectStatic, type beforeEach } from "vitest"; import { type ISemaphoreFactory } from "../../../semaphore/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/semaphore/test-utilities"` * @group Utilities */ export type SemaphoreFactoryTestSuiteSettings = { expect: ExpectStatic; test: TestAPI; describe: SuiteAPI; beforeEach: typeof beforeEach; createSemaphoreFactory: () => Promisable<{ semaphoreFactory: ISemaphoreFactory; serde: ISerde; }>; /** * @default true */ includeSerdeTests?: boolean; /** * @default true */ includeEventTests?: 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 `semaphoreFactoryTestSuite` function simplifies the process of testing your custom implementation of {@link ISemaphore | `ISemaphore`} with `vitest`. * * IMPORT_PATH: `"@daiso-tech/core/semaphore/test-utilities"` * @group Utilities * @example * ```ts * import { describe, expect, test, beforeEach } from "vitest"; * import { MemorySemaphoreAdapter } from "@daiso-tech/core/semaphore/memory-semaphore-adapter"; * import { SemaphoreFactory } from "@daiso-tech/core/semaphore"; * import { EventBus } from "@daiso-tech/core/event-bus"; * import { MemoryEventBusAdapter } from "@daiso-tech/core/event-bus/memory-event-bus-adapter"; * import { semaphoreFactoryTestSuite } from "@daiso-tech/core/semaphore/test-utilities"; * import { Serde } from "@daiso-tech/core/serde"; * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter"; * import type { ISemaphoreData } from "@daiso-tech/core/semaphore/contracts"; * * describe("class: SemaphoreFactory", () => { * semaphoreFactoryTestSuite({ * createSemaphoreFactory: () => { * const serde = new Serde(new SuperJsonSerdeAdapter()); * const semaphoreFactory = new SemaphoreFactory({ * serde, * adapter: new MemorySemaphoreAdapter(), * }); * return { semaphoreFactory, serde }; * }, * beforeEach, * describe, * expect, * test, * serde, * }); * }); * ``` */ export declare function semaphoreFactoryTestSuite(settings: SemaphoreFactoryTestSuiteSettings): void;