import { describe, expect, it, vi } from "vitest" ;
import { emitSessionLifecycleEvent, onSessionLifecycleEvent } from "./session-lifecycle-events.js" ;
describe("session lifecycle events" , () => {
it("delivers events to active listeners and stops after unsubscribe" , () => {
const listener = vi.fn();
const unsubscribe = onSessionLifecycleEvent(listener);
emitSessionLifecycleEvent({
sessionKey: "agent:main:main" ,
reason: "created" ,
label: "Main" ,
});
expect(listener).toHaveBeenCalledTimes(1 );
expect(listener).toHaveBeenCalledWith({
sessionKey: "agent:main:main" ,
reason: "created" ,
label: "Main" ,
});
unsubscribe();
emitSessionLifecycleEvent({
sessionKey: "agent:main:main" ,
reason: "updated" ,
});
expect(listener).toHaveBeenCalledTimes(1 );
});
it("keeps notifying other listeners when one throws" , () => {
const noisy = vi.fn(() => {
throw new Error("boom" );
});
const healthy = vi.fn();
const unsubscribeNoisy = onSessionLifecycleEvent(noisy);
const unsubscribeHealthy = onSessionLifecycleEvent(healthy);
expect(() =>
emitSessionLifecycleEvent({
sessionKey: "agent:main:main" ,
reason: "resumed" ,
}),
).not.toThrow();
expect(noisy).toHaveBeenCalledTimes(1 );
expect(healthy).toHaveBeenCalledTimes(1 );
unsubscribeNoisy();
unsubscribeHealthy();
});
});
Messung V0.5 in Prozent C=98 H=96 G=96
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-05-26)
¤
*© Formatika GbR, Deutschland