Skip to content
Source
Sign inSign up

WebviewPreferences.test.ts

31 lines935 Bytes

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 out[pair] = pair.split("=")[1];
10 continue;
11 }
12 const [key, value] = pair.split("=");
13 if (!key) continue;
14 out[key] = value;
15 }
16 return out;
18​
19describe("PREVIEW_WEBVIEW_PREFERENCES", () => {
20 const parsed = parseWebPreferences(PREVIEW_WEBVIEW_PREFERENCES);
21​
22 it("uses canonical JS-boolean string literals (not yes/no, on/off, 1/0)", () => {
23 for (const value of Object.values(parsed)) {
24 expect(value).toMatch(/^(true|false)$/);
25 }
26 });
27​
28 it("keeps the renderer sandbox enabled (so the page cannot reach Node APIs)", () => {
29 expect(parsed["sandbox"]).toBe("true");
30 });
31});