test(javascript): align semantic fixtures with runtime context

This commit is contained in:
morluto committed 2026-10-24 08:22:13 +08:00
1 parent c3ad8fc024
commit 59553c76be
4 files changed
+31 -12

No files matched your search

@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
import { analyzeCommonJsStaticFixture } from "../../../tests/fixtures/javascriptCommonJsAnalysis.js";
describe("JavaScript static analysis findings", () => {
it("does not infer a webpack push from a dynamic computed key", () => {
@@ -15,25 +16,28 @@ describe("JavaScript static analysis findings", () => {
it("retains every static reference and Electron property in large literals", () => {
const names = Array.from({ length: 10_001 }, (_, index) => `key${index}`);
const source = [
'const { BrowserWindow, contextBridge } = require("electron");',
'import { BrowserWindow, contextBridge } from "electron";',
...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_003);
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(
const commonJsSource = `const { ${names.join(", ")} } = require("./addon.node");`;
const commonJs = analyzeCommonJsStaticFixture(commonJsSource);
expect(commonJs.parse_status).toBe("complete");
expect(commonJs.references).toHaveLength(1);
expect(commonJs.electron.native_addon_bindings[0]?.members).toHaveLength(
10_001,
);
});