Skip to content
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

[WIP] Migrating to Electron 28 #1054

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

araujoarthur0
Copy link
Collaborator

Related issue

Closes #1037

Context / Background

The new electron 28 changes things by providing main electron imports through JS modules. That means we'll be able to use import syntax rather than node's require(), and no longer need the esm module to use both notations.
The require() notation will still be available, making it the best of both worlds for other imports that haven't migrated yet - date-holidays for example.

This patch follows #1050 in which I cleaned some things in preparation.

What change is being introduced by this PR?

  • Updating electron to 28
  • Changing to "type": "module" in package.json so we can start using es6 modules and node require in tandem without esm.
    • Changing all ES6 module files to .mjs extension, changing their imports and exports to the new format.
  • @jest-electron/electron stopped working, and jest does not play nice with either electron or es6 with require. So we will have to migrate to mocha with electron-mocha.
    • mocha doesn't have asserts, so we're switching from jest expect to node's built-in assert. Notations differ a bit, but the preferred way is to use assert.strictEqual(). assert.equal() seems to be legacy.
    • mocha doesn't have mocks, so we're switching from jest.mock() to sinon's spies and stubs, which help a lot and have some similar usages.
    • ES6 modules can no longer be easily stubbed because of the way they are imported. The benefit of them allowing imports to only included the imported content and not all the file leads to this. I tried A LOT of different libraries that promises ES6 mocking but they all fell apart quickly. So I devised a way based on comments around people's complaints to export a MockClass object that allows us to mock some files from within. The methods that have to be mocked are diverted before being exported into this class, and it allows us to switch the method to a stub directly from other pieces of code, which switches the method used in other files as well.
  • The mocha test we had relied on Spectron, which is long deprecated. I switched its implementation to use Playwright, which has an Electron module that does pretty much what Spectron did. It is quite flaky though, and the tests work randomly.

I am sending this PR as a call for help to finish migrating our tests. We have too much content to migrate and I'll probably take a long time to do it alone.

The way I'm running tests right now is for example npx electron-mocha .\__tests__\__main__\notification.mjs.
Later on we can change our package.json targets.

How will this be tested?

Hopefully soon by electron-mocha.

@araujoarthur0
Copy link
Collaborator Author

I will make a separate PR changing the tests to use node's assert rather than jest's expect to make reviewing better here.

@tupaschoal
Copy link
Collaborator

I'm converting this to draft, until the tests have been cleared and this can be rebased, ok @araujoarthur0 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update to electron 28 as soon as it releases - stop using esm
2 participants