open-design/apps/desktop/tests/main/preload-host-boundary.test.ts
pftom 6a5975d508 feat(web): implement embedded browser module in Design Files workspace
- Added a `+` icon to the Design Files tab for opening a new Browser module.
- The Browser module supports navigation features including back, forward, refresh, and address input.
- Integrated a curated list of design reference URLs for user convenience.
- Implemented browser data clearing functionality via IPC.
- Enhanced desktop runtime to support embedded browser with appropriate security measures.
- Added tests for browser functionality and URL handling.

This commit establishes a new workspace for browsing and referencing design resources directly within the application, improving user experience and accessibility to design tools.
2026-05-31 16:03:50 +08:00

46 lines
2.3 KiB
TypeScript

import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
describe("desktop preload host boundary", () => {
it("exposes the canonical Open Design host global and diagnostics bridge", () => {
const here = dirname(fileURLToPath(import.meta.url));
const source = readFileSync(join(here, "../../src/main/preload.cts"), "utf8");
const exposedGlobals = Array.from(source.matchAll(/contextBridge\.exposeInMainWorld\(([^,\n]+)/g))
.map((match) => match[1]?.trim());
const runtimeRequires = Array.from(source.matchAll(/require\((['"][^'"]+['"])\)/g))
.map((match) => match[1]);
expect(exposedGlobals).toEqual(["OPEN_DESIGN_HOST_GLOBAL", "'openDesignDesktop'"]);
expect(runtimeRequires).toEqual(["'electron'"]);
expect(source).toContain("OPEN_DESIGN_HOST_GLOBAL");
expect(source).toContain("exportDiagnostics");
expect(source).toContain("satisfies OpenDesignHostBridge");
expect(source).toContain("browser");
expect(source).toContain("browser:clear-data");
expect(source).toContain("updater");
// OS locale forwarded from main via webPreferences.additionalArguments
// is mirrored onto __od__.client.osLocale. Pin the literal prefix
// here so it can't drift away from `applyOsLocaleSwitch`/runtime's
// additionalArguments without the test going red.
expect(source).toContain("'--od-os-locale='");
expect(source).toContain("osLocale");
expect(source).toContain("invokeUpdater('install'");
expect(source).toContain("od:update:quit");
expect(source).toContain("od:update:status-changed");
expect(source).not.toContain("@open-design/contracts");
expect(source).not.toContain("exposeInMainWorld('electronAPI'");
expect(source).not.toContain('exposeInMainWorld("__odDesktop"');
expect(source).not.toContain("exposeInMainWorld('__odDesktop'");
});
it("mirrors the host import contract by accepting a null entryFile", () => {
const here = dirname(fileURLToPath(import.meta.url));
const source = readFileSync(join(here, "../../src/main/preload.cts"), "utf8");
expect(source).toContain("response.entryFile === null");
expect(source).toContain("entryFile === undefined");
});
});