({ scriptsByUrl })
| 31 | } |
| 32 | |
| 33 | async function loadWrapper({ scriptsByUrl }) { |
| 34 | const source = await readFile(wrapperPath, "utf8"); |
| 35 | const registryCalls = []; |
| 36 | const fetchJsonCalls = []; |
| 37 | const authedFetchCalls = []; |
| 38 | |
| 39 | const realWindow = { |
| 40 | boundProbe() { |
| 41 | return this === realWindow ? "bound" : "unbound"; |
| 42 | }, |
| 43 | }; |
| 44 | |
| 45 | realWindow.__HERMES_PLUGIN_SDK__ = { |
| 46 | React: createReactStub(), |
| 47 | fetchJSON: (url, init) => { |
| 48 | fetchJsonCalls.push([url, init]); |
| 49 | return Promise.resolve({ ok: true }); |
| 50 | }, |
| 51 | authedFetch: (url, init) => { |
| 52 | authedFetchCalls.push([url, init]); |
| 53 | return Promise.resolve({ ok: true }); |
| 54 | }, |
| 55 | }; |
| 56 | |
| 57 | const registeredPlugins = new Map(); |
| 58 | realWindow.__HERMES_PLUGINS__ = { |
| 59 | register: (name, component) => { |
| 60 | registryCalls.push(name); |
| 61 | registeredPlugins.set(name, component); |
| 62 | }, |
| 63 | registerSlot: () => {}, |
| 64 | }; |
| 65 | |
| 66 | const fetchCalls = []; |
| 67 | const context = { |
| 68 | window: realWindow, |
| 69 | fetch: async (url) => { |
| 70 | const key = String(url); |
| 71 | fetchCalls.push(key); |
| 72 | if (!(key in scriptsByUrl)) { |
| 73 | return { |
| 74 | ok: false, |
| 75 | status: 404, |
| 76 | text: async () => "", |
| 77 | }; |
| 78 | } |
| 79 | return { |
| 80 | ok: true, |
| 81 | status: 200, |
| 82 | text: async () => scriptsByUrl[key], |
| 83 | }; |
| 84 | }, |
| 85 | Promise, |
| 86 | setTimeout, |
| 87 | clearTimeout, |
| 88 | }; |
| 89 | |
| 90 | vm.runInNewContext(source, context, { filename: "hermes-wrapper/src/entry.js" }); |
no test coverage detected