Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/embed/widget-loader.test.ts
T

45 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { readFileSync, statSync } from "node:fs";
import { gzipSync } from "node:zlib";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const here = dirname(fileURLToPath(import.meta.url));
const widgetPath = join(here, "..", "public", "embed", "widget.js");
describe("widget.js bootstrap loader", () => {
it("is checked into apps/web/public/embed/widget.js", () => {
expect(statSync(widgetPath).isFile()).toBe(true);
});
it("stays under the 3KB gzipped budget", () => {
const raw = readFileSync(widgetPath);
const gz = gzipSync(raw);
// 3 KB = 3 * 1024 = 3072 bytes
expect(gz.byteLength).toBeLessThan(3072);
});
it("stays under the 5KB raw budget", () => {
const raw = readFileSync(widgetPath);
expect(raw.byteLength).toBeLessThan(5 * 1024);
});
it("references the embed forms route path", () => {
const text = readFileSync(widgetPath, "utf8");
expect(text).toContain("/embed/forms/");
});
it("uses a sandboxed iframe", () => {
const text = readFileSync(widgetPath, "utf8");
expect(text).toContain("sandbox");
expect(text).toContain("allow-scripts");
});
it("listens for postMessage resize / submitted / error events", () => {
const text = readFileSync(widgetPath, "utf8");
expect(text).toContain("tcform:resize");
expect(text).toContain("tcform:submitted");
expect(text).toContain("tcform:error");
});
});