|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js"; |
| 4 | + |
| 5 | +const project = (source: string) => { |
| 6 | + const analysis = analyzeJavaScriptStaticSource(source); |
| 7 | + return { |
| 8 | + status: analysis.parse_status, |
| 9 | + roles: analysis.role_paths.map(({ role, path, mechanism }) => ({ |
| 10 | + role, |
| 11 | + path, |
| 12 | + mechanism, |
| 13 | + })), |
| 14 | + references: analysis.references.map(({ kind, specifier }) => ({ |
| 15 | + kind, |
| 16 | + specifier, |
| 17 | + })), |
| 18 | + endpoints: analysis.endpoints.map(({ kind, value, mechanism }) => ({ |
| 19 | + kind, |
| 20 | + value, |
| 21 | + mechanism, |
| 22 | + })), |
| 23 | + }; |
| 24 | +}; |
| 25 | + |
| 26 | +describe("Electron callee member boundaries", () => { |
| 27 | + it("keeps exact and dotted loadFile, loadURL, and serviceWorker.register calls", () => { |
| 28 | + expect( |
| 29 | + project(` |
| 30 | + loadFile("./bare.html"); |
| 31 | + win.loadFile("./renderer/index.html"); |
| 32 | + app.win.loadFile("./nested.html"); |
| 33 | + loadURL("https://bare.example.test/"); |
| 34 | + BrowserWindow.loadURL("https://app.example.test/page"); |
| 35 | + win?.loadURL("https://optional.example.test/"); |
| 36 | + serviceWorker.register("./bare-sw.js"); |
| 37 | + navigator.serviceWorker.register("./sw.js"); |
| 38 | + `), |
| 39 | + ).toEqual({ |
| 40 | + status: "complete", |
| 41 | + roles: [ |
| 42 | + { |
| 43 | + role: "renderer", |
| 44 | + path: "./bare.html", |
| 45 | + mechanism: "call:loadFile", |
| 46 | + }, |
| 47 | + { |
| 48 | + role: "renderer", |
| 49 | + path: "./renderer/index.html", |
| 50 | + mechanism: "call:win.loadFile", |
| 51 | + }, |
| 52 | + { |
| 53 | + role: "renderer", |
| 54 | + path: "./nested.html", |
| 55 | + mechanism: "call:app.win.loadFile", |
| 56 | + }, |
| 57 | + { |
| 58 | + role: "renderer", |
| 59 | + path: "https://bare.example.test/", |
| 60 | + mechanism: "call:loadURL", |
| 61 | + }, |
| 62 | + { |
| 63 | + role: "renderer", |
| 64 | + path: "https://app.example.test/page", |
| 65 | + mechanism: "call:BrowserWindow.loadURL", |
| 66 | + }, |
| 67 | + { |
| 68 | + role: "renderer", |
| 69 | + path: "https://optional.example.test/", |
| 70 | + mechanism: "call:win.loadURL", |
| 71 | + }, |
| 72 | + ], |
| 73 | + references: [ |
| 74 | + { kind: "service-worker", specifier: "./bare-sw.js" }, |
| 75 | + { kind: "service-worker", specifier: "./sw.js" }, |
| 76 | + ], |
| 77 | + endpoints: [ |
| 78 | + { |
| 79 | + kind: "network", |
| 80 | + value: "https://bare.example.test/", |
| 81 | + mechanism: "call:loadURL", |
| 82 | + }, |
| 83 | + { |
| 84 | + kind: "network", |
| 85 | + value: "https://app.example.test/page", |
| 86 | + mechanism: "call:BrowserWindow.loadURL", |
| 87 | + }, |
| 88 | + { |
| 89 | + kind: "network", |
| 90 | + value: "https://optional.example.test/", |
| 91 | + mechanism: "call:win.loadURL", |
| 92 | + }, |
| 93 | + ], |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it("does not treat a shared identifier suffix as an Electron callee", () => { |
| 98 | + expect( |
| 99 | + project(` |
| 100 | + uploadFile("./secret.html"); |
| 101 | + preloadFile("./also.html"); |
| 102 | + loadFileBackup("./nope.html"); |
| 103 | + downloadURL("https://cdn.example.test/app"); |
| 104 | + reloadURL("https://cdn.example.test/other"); |
| 105 | + notloadURL("https://cdn.example.test/nope"); |
| 106 | + myserviceWorker.register("./nope.js"); |
| 107 | + serviceWorker.registerExtra("./nope.js"); |
| 108 | + `), |
| 109 | + ).toEqual({ |
| 110 | + status: "complete", |
| 111 | + roles: [], |
| 112 | + references: [], |
| 113 | + endpoints: [], |
| 114 | + }); |
| 115 | + }); |
| 116 | +}); |
0 commit comments