11# Electron-React-TypeScript-Webpack (ERTW) Boilerplate
2- ![ badge-ver] ![ badge-license]
2+ ![ badge-ver] ![ badge-node-ver] ![ badge-license]
3+
4+ [ badge-ver ] : https://img.shields.io/github/package-json/v/devtography/electron-react-typescript-webpack-boilerplate
5+ [ badge-license ] : https://img.shields.io/github/license/Devtography/electron-react-typescript-webpack-boilerplate
6+ [ badge-node-ver ] : https://img.shields.io/badge/node--lts-%3E%3D16-orange
37
48A boilerplate that let you instantly start working on your next [ Electron] app
59project in [ TypeScript] with no time wasted messing with the config files.
@@ -34,6 +38,8 @@ implemented, please [file an issue], or consider make a [new pull request].
3438- [ ] Integrate another end-to-end testing framework to replace [ Spectron]
3539- [ ] Migrate to Webpack 5 ` Asset Modules ` __ * (pending for ` v4.2.0 ` )* __
3640- [ ] Integrate HMR & Webpack dev server
41+ - [x] Monitor the status of ESM support on [ Jest] & [ ts-jest]
42+ __ * (Check [ Known issues] ( #known-issues ) for details)* __
3743
3844---
3945
@@ -57,6 +63,11 @@ implemented, please [file an issue], or consider make a [new pull request].
5763 to support ES module for its' config file. __ Converting the config file to
5864 ES module will result in ESLint not working.__
5965
66+ - As of [ ` v4.1.2 ` ] , [ Jest] & [ ts-jest] are __ NOT__ configured to run the test
67+ files as ES modules, despite all other sections of this boilerplate are
68+ configured to support native ES modules. Please check
69+ [ Known issues] ( #known-issues ) for details.
70+
6071---
6172
6273## Getting started
@@ -134,6 +145,42 @@ To package your Electron app, run `npm run prod` to get your code compiled in
134145 uses Webpack to minify your code in `production` builds, so there shouldn't
135146 be any significant performance difference with `asar` archiving disabled.
136147
148+ - __IMPORTANT!!!__
149+
150+ As of [`v4.1.2`], the `jest.mock()` function is broken if [Jest] and [ts-jest]
151+ are configured with [ESM Support]. The following code will result in a
152+ `SyntaxError` being thrown when trying to execute the test with Jest.
153+
154+ ```ts
155+ import { jest } from '@jest/globals';
156+ import { BrowserWindow } from 'electron';
157+
158+ jest.mock('electron', () => {
159+ BrowserWindow: jest.fn().mockImplementation(() => {
160+ loadFile: jest.fn(() => Promise.resolve()),
161+ on: jest.fn(),
162+ }),
163+ });
164+ ```
165+
166+ ```
167+ SyntaxError: The requested module 'electron' does not provide an export named 'BrowserWindow'
168+ ```
169+
170+ The current solution is to keep using the non ESM supported version of
171+ ` jest.config.js ` , but with ` NODE_OPTIONS=--experimental-vm-modules ` set when
172+ running Jest (already set in [ ` v4.1.2 ` ] ). The drawback of this is you won't
173+ be able to use ` import.meta ` APIs in your code. It could be a deal breaker for
174+ some of you.
175+
176+ I'm closely monitoring the situation atm, and I'll consider rollback the ESM
177+ related setting introduced in [ ` v4.1.0 ` ] if there's no progress made solving
178+ this issue by the time I prepare the release of ` v4.2.0 ` . You can track the
179+ progress on a related issue [ facebook/jest #10025 ] if you want.
180+
181+ [ ESM Support ] : https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
182+ [ facebook/jest #10025 ] : https://github.com/facebook/jest/issues/10025
183+
137184## Project folders & files
138185- ` dist/ ` - [ Webpack] output location
139186
@@ -163,8 +210,8 @@ To package your Electron app, run `npm run prod` to get your code compiled in
163210 many APIs for IPC. See example as below:
164211 ``` ts
165212 // ipc-api/index.ts
166- import submoduleA from './submodule-a';
167- import submoduleB from './submodule-b';
213+ import submoduleA from ' ./submodule-a.js ' ;
214+ import submoduleB from ' ./submodule-b.js ' ;
168215
169216 export default { ... submoduleA , ... submoduleB };
170217
@@ -217,6 +264,7 @@ To package your Electron app, run `npm run prod` to get your code compiled in
217264 you ' d use TypeScript if you' re using this boilerplate .
218265
219266 - ` main/main.spec.ts ` - Sample test file for ` src/main/main `
267+ - ` utils/node-env.spec.ts ` - Unit test for ` src/utils/node-env `
220268 - ` tsconfig.json ` - TypeScript config file for ` tests ` module
221269- ` .eslintignore ` - [ESLint ] ignore file
222270- ` .eslintrc.cjs ` - [ESLint ] config file
@@ -263,9 +311,6 @@ great roasters I know 😉 ☕️️
263311Electron React TypeScript Webpack Boilerplate is open source software
264312[licensed as MIT ](LICENSE ).
265313
266- [badge-ver ]: https://img.shields.io/github/package-json/v/devtography/electron-react-typescript-webpack-boilerplate
267- [badge-license ]: https://img.shields.io/github/license/Devtography/electron-react-typescript-webpack-boilerplate
268-
269314[Electron ]: https :// www.electronjs.org
270315[React ]: https :// reactjs.org
271316[Webpack ]: https :// webpack.js.org
@@ -276,6 +321,7 @@ Electron React TypeScript Webpack Boilerplate is open source software
276321[file an issue ]: https :// www.electronjs.org
277322[new pull request ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare
278323[Spectron ]: https :// github.com/electron-userland/spectron
324+ [ts - jest ]: https :// github.com/kulshekhar/ts-jest
279325[Playwright ]: https :// playwright.dev
280326[WebdriverIO ]: https :// webdriver.io
281327[Spectron Deprecation Notice ]: https :// www.electronjs.org/blog/spectron-deprecation-notice
@@ -291,3 +337,4 @@ Electron React TypeScript Webpack Boilerplate is open source software
291337[` v3.0.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v3.0.0
292338[` v4.0.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.0.0
293339[` v4.1.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.1.0
340+ [` v4.1.2 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.1.2
0 commit comments