From 71edb93215231892e9f88d977ae0c7cfdf8fba95 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Fri, 23 Oct 2026 14:40:01 +0000 Subject: [PATCH] Close WebPeer runtimes after composition tests --- test/apps/webpeer/WebPeerRuntime.unit.spec.ts | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/test/apps/webpeer/WebPeerRuntime.unit.spec.ts b/test/apps/webpeer/WebPeerRuntime.unit.spec.ts index 693b1e3d..73362b39 100644 --- a/test/apps/webpeer/WebPeerRuntime.unit.spec.ts +++ b/test/apps/webpeer/WebPeerRuntime.unit.spec.ts @@ -3,9 +3,9 @@ import { createServiceContext } from "@vrtmrz/livesync-commonlib/context"; import { DEFAULT_SETTINGS, SETTING_KEY_P2P_DEVICE_NAME } from "@vrtmrz/livesync-commonlib/compat/common/types"; import type { SimpleStore } from "octagonal-wheels/databases/SimpleStoreBase"; import { EVENT_LAYOUT_READY } from "@vrtmrz/livesync-commonlib/compat/events/coreEvents"; -import { describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; -import { WebPeerRuntime } from "@/apps/webpeer/src/WebPeerRuntime"; +import { WebPeerRuntime, type WebPeerRuntimeOptions } from "@/apps/webpeer/src/WebPeerRuntime"; function createMemoryStore(): SimpleStore { const values = new Map(); @@ -23,11 +23,30 @@ function createMemoryStore(): SimpleStore { } describe("WebPeer runtime composition", () => { + const runtimes = new Set(); + + function createRuntime(options: WebPeerRuntimeOptions): WebPeerRuntime { + const runtime = new WebPeerRuntime(options); + runtimes.add(runtime); + return runtime; + } + + afterEach(async () => { + try { + for (const runtime of runtimes) { + await runtime.shutdown(); + } + } finally { + runtimes.clear(); + vi.restoreAllMocks(); + } + }); + it("preserves one context and live P2P result across the service graph and pane host", () => { const context = createServiceContext({ translate: (key) => `webpeer:${key}`, }); - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), context, store: createMemoryStore(), @@ -44,7 +63,7 @@ describe("WebPeer runtime composition", () => { }); it("loads settings and opens the local database before announcing layout readiness", async () => { - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), store: createMemoryStore(), }); @@ -70,7 +89,7 @@ describe("WebPeer runtime composition", () => { it("delegates automatic P2P startup to the resumed lifecycle handler", async () => { vi.useFakeTimers(); try { - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), store: createMemoryStore(), }); @@ -95,7 +114,7 @@ describe("WebPeer runtime composition", () => { }); it("rejects start when the browser-local database cannot be opened", async () => { - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), store: createMemoryStore(), }); @@ -107,7 +126,7 @@ describe("WebPeer runtime composition", () => { }); it("isolates a specialised runtime and applies its device name before opening the database", async () => { - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), store: createMemoryStore(), deviceName: " p2p-check-browser-desktop-abc ", @@ -142,7 +161,7 @@ describe("WebPeer runtime composition", () => { }); it("reads the current device name after the pane updates the store", async () => { - const runtime = new WebPeerRuntime({ + const runtime = createRuntime({ deviceValues: new MemoryValueStore(), store: createMemoryStore(), systemVaultName: "webpeer-vault",