MCPcopy Create free account
hub / github.com/EvoMap/evolver / installFakeAddon

Function installFakeAddon

test/workspaceKeychain.test.js:335–358  ·  view source on GitHub ↗
(getPasswordImpl)

Source from the content-addressed store, hash-verified

333 let savedCache;
334
335 function installFakeAddon(getPasswordImpl) {
336 const fake = {
337 Entry: function (service, account) {
338 this.service = service;
339 this.account = account;
340 },
341 };
342 fake.Entry.prototype.getPassword = getPasswordImpl;
343 fake.Entry.prototype.setPassword = function () { /* no-op */ };
344 // Hijack Module._cache so `require('@napi-rs/keyring')` resolves
345 // to our fake even when the real package isn't installed.
346 const Module = require('module');
347 const fakeId = '__fake_napi_keyring__';
348 require.cache[fakeId] = {
349 id: fakeId, filename: fakeId, loaded: true, exports: fake,
350 children: [], paths: [],
351 };
352 const orig = Module._resolveFilename;
353 savedCache = { orig, fakeId };
354 Module._resolveFilename = function (req, ...rest) {
355 if (req === ADDON_PATH) return fakeId;
356 return orig.call(this, req, ...rest);
357 };
358 }
359
360 function uninstallFakeAddon() {
361 if (savedCache) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected