Resolve stable lexical and URL targets using shared effects, and preserve unresolved request expressions as partial facts. Carry their uncertainty through workers, artifact graphs, and the CLI. Scope partial endpoint identity to the source site. Refs: #3451, #3534 Co-authored-by: Hemang Varshney <[email protected]>
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
|
|
|
const endpoints = (source: string) =>
|
|
analyzeJavaScriptStaticSource(source).endpoints.map(
|
|
({ kind, value, mechanism }) => ({ kind, value, mechanism }),
|
|
);
|
|
|
|
describe("beacon endpoints", () => {
|
|
it("reports navigator.sendBeacon URLs", () => {
|
|
expect(
|
|
endpoints(`
|
|
navigator.sendBeacon("/api/telemetry", payload);
|
|
window.navigator.sendBeacon("https://metrics.example/collect");
|
|
`),
|
|
).toEqual([
|
|
{
|
|
kind: "network",
|
|
value: "/api/telemetry",
|
|
mechanism: "call:navigator.sendBeacon",
|
|
},
|
|
{
|
|
kind: "network",
|
|
value: "https://metrics.example/collect",
|
|
mechanism: "call:window.navigator.sendBeacon",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("retains a dynamic beacon target as partial source evidence", () => {
|
|
expect(
|
|
analyzeJavaScriptStaticSource("navigator.sendBeacon(url, payload);")
|
|
.endpoints,
|
|
).toEqual([
|
|
expect.objectContaining({
|
|
value: "url",
|
|
mechanism: "call:navigator.sendBeacon",
|
|
resolution: "partial",
|
|
}),
|
|
]);
|
|
});
|
|
});
|