-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ESM #180
Comments
It's not entirely clear yet how ESM is going to work in Electron, especially in the renderer process where there is a clash between Node's and Chromium's ESM loaders. I would prefer not to work on native ESM support in electron-mocha until the situation in Electron is clear. That said, it's absolutely no problem to test apps using ESM with electron mocha if you can use a custom loader in between. I haven't used the |
Hi, More or less I have figured out how to do this. Not sure if that's the most efficient way though. In then test file I have the following in the imports:
This way I am able to import a class that works in the main process for unit testing. This also works for renderer classes. Types won't work this way but at least I am able to run tests again. |
I upgraded my project to work as ESM. I use the
esm
module when running the main script, all my renderer classes are going through a custom protocol that load modules as defined in the ES spec. I am almost ready to release the app but apparently I can't perform tests because everything is crashes. So, similarly to mocha I tried to use--require esm
which fixes the problem (electron-mocha uses --require-main or --require). This, however, didn't work. Then I tried a different approach which creates a a common export file just for test, where the main file is a regular Common JS file, but it employsesm
module to load a ES file that has exports for the classes. this doesn't work as well. After that I don't really have more ideas how to proceed. Maybe you guys has a similar issue and can help here?To visualize what I am trying to do.
esm
: https://github.com/advanced-rest-client/arc-electron/blob/redesign2020/test/ElectronCookies/SessionManager.main.spec.js#L5The text was updated successfully, but these errors were encountered: