mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Abhay Padamani <141122205+ktx-abhay@users.noreply.github.com> Co-authored-by: ktx-abhay <abhay.padamani@kiara.tech>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
// Copyright 2026 OpenObserve Inc.
|
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { onBeforeAppReload, runBeforeAppReloadHooks } from "./beforeAppReload";
|
|
|
|
describe("beforeAppReload", () => {
|
|
it("runs every registered hook and waits for async ones", async () => {
|
|
const order: string[] = [];
|
|
const stopA = onBeforeAppReload(() => {
|
|
order.push("a");
|
|
});
|
|
const stopB = onBeforeAppReload(async () => {
|
|
await Promise.resolve();
|
|
order.push("b");
|
|
});
|
|
|
|
await runBeforeAppReloadHooks();
|
|
expect(order.sort()).toEqual(["a", "b"]);
|
|
stopA();
|
|
stopB();
|
|
});
|
|
|
|
it("does not run a hook after its unregister function is called", async () => {
|
|
const hook = vi.fn();
|
|
const stop = onBeforeAppReload(hook);
|
|
stop();
|
|
|
|
await runBeforeAppReloadHooks();
|
|
expect(hook).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("resolves even when a hook throws or rejects", async () => {
|
|
const stopThrow = onBeforeAppReload(() => {
|
|
throw new Error("boom");
|
|
});
|
|
const stopReject = onBeforeAppReload(() => Promise.reject(new Error("later")));
|
|
const survivor = vi.fn();
|
|
const stopSurvivor = onBeforeAppReload(survivor);
|
|
|
|
await expect(runBeforeAppReloadHooks()).resolves.toBeUndefined();
|
|
expect(survivor).toHaveBeenCalledTimes(1);
|
|
stopThrow();
|
|
stopReject();
|
|
stopSurvivor();
|
|
});
|
|
});
|