Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WebviewPreferences.test.ts

35 lines1.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { PREVIEW_WEBVIEW_PREFERENCES } from "./WebviewPreferences.ts";
4​
5function parseWebPreferences(input: string): Record<string, unknown> {
6 const out: Record<string, unknown> = {};
7 for (const pair of input.split(",")) {
8 if (pair !== pair.trim()) {
9 // Electron's parser doesn't trim; surface the bug as undefined-key.
10 out[pair] = pair.split("=")[1];
11 continue;
12 }
13 const [key, value] = pair.split("=");
14 if (!key) continue;
15 out[key] = value;
16 }
17 return out;
19​
20describe("PREVIEW_WEBVIEW_PREFERENCES", () => {
21 const parsed = parseWebPreferences(PREVIEW_WEBVIEW_PREFERENCES);
22​
23 it("uses canonical JS-boolean string literals (not yes/no, on/off, 1/0)", () => {
24 // `value="no"` is a TRUTHY string when assigned to webPreferences.X — so
25 // `contextIsolation="no"` would silently leave isolation ENABLED. Lock
26 // the values to `"true"` / `"false"` so the parser does the right thing.
27 for (const value of Object.values(parsed)) {
28 expect(value).toMatch(/^(true|false)$/);
29 }
30 });
31​
32 it("keeps the renderer sandbox enabled (so the page cannot reach Node APIs)", () => {
33 expect(parsed["sandbox"]).toBe("true");
34 });
35});