mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
SEQTA.ts runs on every website at document_start, and it statically imported the whole extension, so every page a user visited downloaded and parsed it even though it does nothing outside SEQTA. SEQTA.ts is now a small gate that does the same copyright/title check and dynamically imports seqta/boot (the old SEQTA.ts body) only when it passes. The 404 page boot moved to seqta/bootErrorPage and is loaded the same way. The 404 boot test now runs the entry and seqta/bootErrorPage together, and the contributing docs point at seqta/boot.ts for the startup code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
/** @jest-environment jsdom */
|
|
import { execFileSync } from "node:child_process";
|
|
import { runInNewContext } from "node:vm";
|
|
|
|
// Compile the actual Vite entry and the 404 boot it loads in Node (esbuild
|
|
// cannot run in jsdom's realm).
|
|
const [bootScript, errorPageScript]: string[] = JSON.parse(
|
|
execFileSync(
|
|
process.execPath,
|
|
[
|
|
"--input-type=module",
|
|
"-e",
|
|
`
|
|
import { readFileSync } from "node:fs";
|
|
import { transformSync } from "esbuild";
|
|
const compile = (file) => transformSync(readFileSync(file, "utf8"), {
|
|
loader: "ts", format: "cjs",
|
|
supported: { "dynamic-import": false },
|
|
define: { "import.meta.env.DEV": "false", "import.meta.hot": "undefined" },
|
|
}).code;
|
|
process.stdout.write(JSON.stringify(["src/SEQTA.ts", "src/seqta/bootErrorPage.ts"].map(compile)));
|
|
`,
|
|
],
|
|
{ encoding: "utf8" },
|
|
),
|
|
);
|
|
|
|
test.each([
|
|
{ onoff: false },
|
|
{ "plugin.error-page-kitten.settings": { enabled: false } },
|
|
])(
|
|
"disabled 404 customization preserves the native error message: %j",
|
|
async (stored) => {
|
|
document.head.innerHTML = "";
|
|
document.body.innerHTML = '<div class="message">Page not found</div>';
|
|
const mount = jest.fn();
|
|
const requireMock = (module: string): unknown => {
|
|
if (module === "@/seqta/bootErrorPage") {
|
|
const loaded = { exports: {} };
|
|
runInNewContext(errorPageScript, {
|
|
document,
|
|
window,
|
|
console,
|
|
module: loaded,
|
|
exports: loaded.exports,
|
|
require: requireMock,
|
|
});
|
|
return loaded.exports;
|
|
}
|
|
if (module === "webextension-polyfill") {
|
|
return { storage: { local: { get: async () => stored } } };
|
|
}
|
|
if (module.includes("errorPageKitten")) {
|
|
return { isSeqta404Page: () => true, mountErrorPageKitten: mount };
|
|
}
|
|
return {};
|
|
};
|
|
runInNewContext(bootScript, {
|
|
document,
|
|
window,
|
|
console,
|
|
require: requireMock,
|
|
});
|
|
for (let i = 0; i < 10; i++) await Promise.resolve();
|
|
|
|
expect(mount).not.toHaveBeenCalled();
|
|
expect(
|
|
window.getComputedStyle(document.querySelector(".message")!).display,
|
|
).not.toBe("none");
|
|
},
|
|
);
|