import { describe, test, beforeEach, expect, afterEach } from "vitest";
import type { StartedRedisContainer } from "@testcontainers/redis";
import { RedisContainer } from "@testcontainers/redis";
import Redis from "ioredis";
import { RedisPubSubEventBusAdapter } from "@daiso-tech/core/event-bus/adapters";
import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
import { eventBusTestSuite } from "@daiso-tech/core/event-bus/implementations/test-utilities";
const TIMEOUT = TimeSpan.fromMinutes(2);
describe("class: EventBus", () => {
let dispatcherClient: Redis;
let listenerClient: Redis;
let startedContainer: StartedRedisContainer;
const serde = new Serde(new SuperJsonSerdeAdapter());
beforeEach(async () => {
startedContainer = await new RedisContainer().start();
dispatcherClient = new Redis(startedContainer.getConnectionUrl());
listenerClient = new Redis(startedContainer.getConnectionUrl());
}, TIMEOUT.toMilliseconds());
afterEach(async () => {
await dispatcherClient.quit();
await listenerClient.quit();
await startedContainer.stop();
}, TIMEOUT.toMilliseconds());
eventBusTestSuite({
createEventBus: () =>
new EventBus(
new RedisPubSubEventBusAdapter({
dispatcherClient,
listenerClient,
serde,
rootGroup: "@global"
})
),
serde,
test,
beforeEach,
expect,
describe,
});
});
The eventBusTestSuite function simplifies the process of testing your custom implementation of IEventBus with vitest.
IMPORT_PATH:
"@daiso-tech/core/event-bus/implementations/test-utilities"