Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import { assertTrue } from "@effect/vitest/utils";
3import { Effect, Option } from "effect";
4
5import { ServerLifecycleEvents, ServerLifecycleEventsLive } from "./serverLifecycleEvents.ts";
6
7it.effect(
8 "publishes lifecycle events without subscribers and snapshots the latest welcome/ready",
9 () =>
10 Effect.gen(function* () {
11 const lifecycleEvents = yield* ServerLifecycleEvents;
12
13 const welcome = yield* lifecycleEvents
14 .publish({
15 version: 1,
16 type: "welcome",
17 payload: {
18 cwd: "/tmp/project",
19 projectName: "project",
20 },
21 })
22 .pipe(Effect.timeoutOption("50 millis"));
23 assertTrue(Option.isSome(welcome));
24 assert.equal(welcome.value.sequence, 1);
25
26 const ready = yield* lifecycleEvents
27 .publish({
28 version: 1,
29 type: "ready",
30 payload: {
31 at: new Date().toISOString(),
32 },
33 })
34 .pipe(Effect.timeoutOption("50 millis"));
35 assertTrue(Option.isSome(ready));
36 assert.equal(ready.value.sequence, 2);
37
38 const snapshot = yield* lifecycleEvents.snapshot;
39 assert.equal(snapshot.sequence, 2);
40 assert.deepEqual(snapshot.events.map((event) => event.type).toSorted(), ["ready", "welcome"]);
41 }).pipe(Effect.provide(ServerLifecycleEventsLive)),
42);