Something went wrong. Try again.
this post sux
Something went wrong. Try again.
1.4 kB · 34 lines
JavaScript
at main
1234567891011121314151617181920212223242526272829303132333435import test from "node:test";import assert from "node:assert/strict";import { readFileSync } from "node:fs";import { fileURLToPath } from "node:url";import { dirname, join } from "node:path";import vm from "node:vm";import { build } from "../build.mjs";
const here = dirname(fileURLToPath(import.meta.url));const built = readFileSync(join(here, "..", "sux.user.js"), "utf8");
test("sux.user.js is up to date with its sources", () => { assert.equal(built, build(), "stale — run: node userscript/build.mjs");});
test("sux.user.js parses", () => { assert.doesNotThrow(() => new vm.Script(built, { filename: "sux.user.js" }));});
test("metadata block comes first and declares what the script uses", () => { assert.match(built, /^\/\/ ==UserScript==\n/); const meta = built.slice(0, built.indexOf("// ==/UserScript==")); for (const g of ["GM_xmlhttpRequest", "GM_getValue", "GM_setValue", "GM_addValueChangeListener", "GM_registerMenuCommand", "unsafeWindow"]) { assert.match(meta, new RegExp("@grant\\s+" + g + "\\n"), g); assert.ok(built.slice(meta.length).includes(g), g + " granted but unused"); } assert.match(meta, /@connect\s+api\.typesafe\.ai/); assert.match(meta, /@run-at\s+document-start/);});
test("no placeholders or leaked extension APIs remain", () => { assert.doesNotMatch(built, /__SUX_PANEL_(CSS|HTML)__/); assert.doesNotMatch(built, /\bbrowser\.(runtime|storage|permissions|theme)\b/);});