mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
|
|
|
describe("JavaScript static analysis findings", () => {
|
|
it("does not infer a webpack push from a dynamic computed key", () => {
|
|
const analysis = analyzeJavaScriptStaticSource(`
|
|
const push = "push";
|
|
const arr = {};
|
|
arr[push]([[1], { 1: function () {} }]);
|
|
`);
|
|
expect(analysis.bundler_registrations).toEqual([]);
|
|
});
|
|
|
|
it("retains every static reference and Electron property in large literals", () => {
|
|
const names = Array.from({ length: 10_001 }, (_, index) => `key${index}`);
|
|
const source = [
|
|
...names.map(
|
|
(name, index) => `import value${index} from "./${name}.js";`,
|
|
),
|
|
`new BrowserWindow({ webPreferences: { ${names.map((name) => `${name}: true`).join(", ")} } });`,
|
|
`contextBridge.exposeInMainWorld("api", { ${names.map((name) => `${name}: () => true`).join(", ")} });`,
|
|
`const { ${names.join(", ")} } = require("./addon.node");`,
|
|
].join("\n");
|
|
const analysis = analyzeJavaScriptStaticSource(source);
|
|
|
|
expect(analysis.parse_status).toBe("complete");
|
|
expect(analysis.references).toHaveLength(10_002);
|
|
expect(analysis.electron.browser_windows[0]?.web_preferences).toHaveLength(
|
|
10_001,
|
|
);
|
|
expect(analysis.electron.context_bridge_apis[0]?.members).toHaveLength(
|
|
10_001,
|
|
);
|
|
expect(analysis.electron.native_addon_bindings[0]?.members).toHaveLength(
|
|
10_001,
|
|
);
|
|
});
|
|
});
|