mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-25 02:23:22 +00:00
Close WebPeer runtimes after composition tests
This commit is contained in:
1 parent
96ad2737a7
commit
71edb93215
1 file changed
+27
-8
@@ -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<unknown> {
|
||||
const values = new Map<string, unknown>();
|
||||
@@ -23,11 +23,30 @@ function createMemoryStore(): SimpleStore<unknown> {
|
||||
}
|
||||
|
||||
describe("WebPeer runtime composition", () => {
|
||||
const runtimes = new Set<WebPeerRuntime>();
|
||||
|
||||
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",
|
||||
|
||||
Reference in new issue
Block a user