test: consolidate JavaScript and provider fixture coverage

This commit is contained in:
morluto committed 2026-11-10 16:32:53 -05:00
1 parent 439c197c3f
commit 3c4be703cd
16 files changed
+23 -223

No files matched your search

@@ -1178,15 +1178,7 @@ it("keeps distinct exposed renderer listener callsites distinct", () => {
result.electron.call_paths?.filter(({ channel }) => channel === "pong"),
).toHaveLength(2);
});
it("does not identify overwritten Electron namespaces or shadowed require", () => {
for (const source of [
`const e=require("electron");e.ipcMain={on(){}};e.ipcMain.on("bad",event=>event.sender.copy());`,
`function require(){return {ipcMain:{on(){}}}};const e=require("electron");e.ipcMain.on("bad",event=>event.sender.copy());`,
])
expect(
analyzeJavaScriptStaticSource(source).electron.call_paths ?? [],
).toEqual([]);
});
it("preserves guarded alternatives in direct exposed object literals", () => {
const result = analyzeJavaScriptStaticSource(`
const e=require("electron");
@@ -73,24 +73,4 @@ describe("JavaScript semantic analysis: logical assignment", () => {
"unknown",
);
});
it("reproduces the issue #2646 inputs without an exact literal", () => {
for (const operator of ["||=", "??="]) {
const { binding, returned } = observe(
`function read(x) { x ${operator} 2; return x; }`,
);
expect(binding).not.toEqual({ status: "literal", value: 2 });
expect(returned).not.toEqual({ status: "literal", value: 2 });
}
const readOr = (x: number) => {
x ||= 2;
return x;
};
const readNullish = (x: number) => {
x ??= 2;
return x;
};
expect(readOr(5)).toBe(5);
expect(readNullish(5)).toBe(5);
});
});
@@ -874,21 +874,6 @@ describe("property mutation collection on minified bundles", () => {
],
});
}, 30000);
it("indexes many returned object methods instead of rescanning the object", () => {
const methods = Array.from(
{ length: 2000 },
(_, index) => `m${index}() { return shared; }`,
).join(",");
const writes = Array.from(
{ length: 2000 },
(_, index) => `box.m${index}().p${index} = ${index};`,
).join(" ");
const value = resultValue(
`const shared = { token: "TOKEN" }; const box = { ${methods} }; ${writes} return shared.token;`,
);
expect(value?.status).toBe("unknown");
}, 30000);
});
describe("results of methods on an escaped receiver", () => {
@@ -8,9 +8,9 @@ import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
*
* Measured on Node 24.22.1: `"pipe"`, `"overlapped"`, `"inherit"` and `"ignore"` start a
* child, while `"ipc"`, `"PIPE"`, `"pipe "`, `"pipeline"`, `"stream"` and `"stdio"` throw
* `ERR_INVALID_ARG_VALUE`. The set is exact and case-sensitive. `fork` appends `"ipc"` to a
* string and splits it, so an empty string becomes the lone element `"ipc"`, which `fork`
* refuses — `spawn(..., {stdio: ""})` still starts a child.
* `ERR_INVALID_ARG_VALUE`. The set is exact and case-sensitive. `fork` refuses an empty string in its
* own stdio-string validation; it does not split the string or append `"ipc"`.
* `spawn(..., {stdio: ""})` still starts a child.
*/
const spawnsFor = (body: string) =>
analyzeJavaScriptSemantics(
@@ -78,30 +78,6 @@ it.each(cases)(
},
);
it.each(["call", "apply"] as const)(
"does not treat an owned local %s replacement as a loader invocation",
(method) => {
const args = method === "call" ? "null,'node:path'" : "null,['node:path']";
const analysis = analyzeJavaScriptStaticSource(
`${named}const load=make(import.meta.url);load.${method}=()=>({kind:'local'});load.${method}(${args});`,
);
expect(analysis.parse_error_count).toBe(0);
expect(
analysis.references.filter(({ kind }) => kind === "require"),
).toEqual([]);
},
);
it("keeps uncertainty for conditional call-member replacement", () => {
const analysis = analyzeJavaScriptStaticSource(
`${named}const load=make(import.meta.url);if(flag)load.call=()=>({kind:'local'});load.call(null,'node:path');`,
);
expect(analysis.parse_error_count).toBe(0);
expect(analysis.references.filter(({ kind }) => kind === "require")).toEqual([
expect.objectContaining({ kind: "require", specifier: null }),
]);
});
it("uses the restored call member after a local replacement", () => {
const source = `${named}const load=make(import.meta.url);load.call=()=>({kind:'local'});load.call=Function.prototype.call;load.call(null,'node:path');`;
const analysis = analyzeJavaScriptStaticSource(source);