You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
The project I'm currently working on needs to mock some remote.require we do on the angular side for some native modules we use.
import{remote}from'electron';/** * This mocks out main process modules that are incompatible with unit tests. */constoriginalRequire=remote.require;remote.require=jest.fn((moduleName)=>{switch(moduleName){// mock native module functionscase'./nativeModule':
return()=>true;// for all other modules, do not mock and return regular moduledefault:
returnoriginalRequire(moduleName);}});
Since the context in which Jest runs didn't include the needed enableRemoteModule: true web preference, as it's the default since Electron v10. Since we upgraded to v11, and still needed the remote module, our tests started failing.
I ended up doing a manual override in the postinstall script of our project to manually replace the JestWorkerRPC.js file with a copy of it in which I added enableRemoteModule: true.
Now our tests run and all is good. But I don't like to override a whole file within node_modules like this, so it would be nice to be able to configure certain aspects like the webPreferences of the BrowserWindow of the Jest Runner to avoid this kind of workaround.
I know the remote module is deprecated and it could be a security concern, but until we refactor our codebase, this is the solution we came up with.
Let me know if this is viable or anyone stumbled upon this case so that I can provide anything needed.
Thank you!
The text was updated successfully, but these errors were encountered:
Hi!
The project I'm currently working on needs to mock some
remote.require
we do on the angular side for some native modules we use.Since the context in which Jest runs didn't include the needed
enableRemoteModule: true
web preference, as it's the default since Electron v10. Since we upgraded to v11, and still needed theremote
module, our tests started failing.I ended up doing a manual override in the
postinstall
script of our project to manually replace theJestWorkerRPC.js
file with a copy of it in which I addedenableRemoteModule: true
.Now our tests run and all is good. But I don't like to override a whole file within
node_modules
like this, so it would be nice to be able to configure certain aspects like thewebPreferences
of theBrowserWindow
of the Jest Runner to avoid this kind of workaround.I know the
remote
module is deprecated and it could be a security concern, but until we refactor our codebase, this is the solution we came up with.Let me know if this is viable or anyone stumbled upon this case so that I can provide anything needed.
Thank you!
The text was updated successfully, but these errors were encountered: