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

Migrating to Electron 28 #1054

Merged
merged 46 commits into from
Dec 31, 2024
Merged

Migrating to Electron 28 #1054

merged 46 commits into from
Dec 31, 2024

Conversation

araujoarthur0
Copy link
Collaborator

@araujoarthur0 araujoarthur0 commented Jan 13, 2024

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 include the imported content and not all the file leads to this. I tried A LOT of different libraries that promise 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.
  • Some tests had side effects into other tests as mocha seems to evaluate all non-mocha declarations at start-time. I had to move a lot of stuff so it only affects a single test.

How will this be tested?

By the migrated tests themselves passing.

@araujoarthur0 araujoarthur0 force-pushed the electron-28 branch 2 times, most recently from ace65ac to a990409 Compare January 25, 2024 02:13
@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 ?

@tupaschoal tupaschoal marked this pull request as draft January 28, 2024 10:51
@araujoarthur0 araujoarthur0 force-pushed the electron-28 branch 2 times, most recently from 51e3aea to 3892d4f Compare March 17, 2024 23:57
@araujoarthur0 araujoarthur0 force-pushed the electron-28 branch 2 times, most recently from 4466f98 to 0b92f84 Compare December 27, 2024 15:30
@araujoarthur0 araujoarthur0 changed the title [WIP] Migrating to Electron 28 Migrating to Electron 28 Dec 27, 2024
@araujoarthur0 araujoarthur0 marked this pull request as ready for review December 27, 2024 16:44
Copy link
Collaborator

@tupaschoal tupaschoal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything seems to be working just fine, both apps & tests. Great work!

@tupaschoal tupaschoal merged commit 7e24ca6 into TTLApp:main Dec 31, 2024
7 checks passed
@araujoarthur0 araujoarthur0 deleted the electron-28 branch January 6, 2025 00:11
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