mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-25 10:33:21 +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 { DEFAULT_SETTINGS, SETTING_KEY_P2P_DEVICE_NAME } from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||||
import type { SimpleStore } from "octagonal-wheels/databases/SimpleStoreBase";
|
import type { SimpleStore } from "octagonal-wheels/databases/SimpleStoreBase";
|
||||||
import { EVENT_LAYOUT_READY } from "@vrtmrz/livesync-commonlib/compat/events/coreEvents";
|
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> {
|
function createMemoryStore(): SimpleStore<unknown> {
|
||||||
const values = new Map<string, unknown>();
|
const values = new Map<string, unknown>();
|
||||||
@@ -23,11 +23,30 @@ function createMemoryStore(): SimpleStore<unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("WebPeer runtime composition", () => {
|
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", () => {
|
it("preserves one context and live P2P result across the service graph and pane host", () => {
|
||||||
const context = createServiceContext({
|
const context = createServiceContext({
|
||||||
translate: (key) => `webpeer:${key}`,
|
translate: (key) => `webpeer:${key}`,
|
||||||
});
|
});
|
||||||
const runtime = new WebPeerRuntime({
|
const runtime = createRuntime({
|
||||||
deviceValues: new MemoryValueStore(),
|
deviceValues: new MemoryValueStore(),
|
||||||
context,
|
context,
|
||||||
store: createMemoryStore(),
|
store: createMemoryStore(),
|
||||||
@@ -44,7 +63,7 @@ describe("WebPeer runtime composition", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("loads settings and opens the local database before announcing layout readiness", async () => {
|
it("loads settings and opens the local database before announcing layout readiness", async () => {
|
||||||
const runtime = new WebPeerRuntime({
|
const runtime = createRuntime({
|
||||||
deviceValues: new MemoryValueStore(),
|
deviceValues: new MemoryValueStore(),
|
||||||
store: createMemoryStore(),
|
store: createMemoryStore(),
|
||||||
});
|
});
|
||||||
@@ -70,7 +89,7 @@ describe("WebPeer runtime composition", () => {
|
|||||||
it("delegates automatic P2P startup to the resumed lifecycle handler", async () => {
|
it("delegates automatic P2P startup to the resumed lifecycle handler", async () => {
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
try {
|
try {
|
||||||
const runtime = new WebPeerRuntime({
|
const runtime = createRuntime({
|
||||||
deviceValues: new MemoryValueStore(),
|
deviceValues: new MemoryValueStore(),
|
||||||
store: createMemoryStore(),
|
store: createMemoryStore(),
|
||||||
});
|
});
|
||||||
@@ -95,7 +114,7 @@ describe("WebPeer runtime composition", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects start when the browser-local database cannot be opened", async () => {
|
it("rejects start when the browser-local database cannot be opened", async () => {
|
||||||
const runtime = new WebPeerRuntime({
|
const runtime = createRuntime({
|
||||||
deviceValues: new MemoryValueStore(),
|
deviceValues: new MemoryValueStore(),
|
||||||
store: createMemoryStore(),
|
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 () => {
|
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(),
|
deviceValues: new MemoryValueStore(),
|
||||||
store: createMemoryStore(),
|
store: createMemoryStore(),
|
||||||
deviceName: " p2p-check-browser-desktop-abc ",
|
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 () => {
|
it("reads the current device name after the pane updates the store", async () => {
|
||||||
const runtime = new WebPeerRuntime({
|
const runtime = createRuntime({
|
||||||
deviceValues: new MemoryValueStore(),
|
deviceValues: new MemoryValueStore(),
|
||||||
store: createMemoryStore(),
|
store: createMemoryStore(),
|
||||||
systemVaultName: "webpeer-vault",
|
systemVaultName: "webpeer-vault",
|
||||||
|
|||||||
Reference in new issue
Block a user