@@ -34,6 +34,8 @@ implemented, please [file an issue], or consider make a [new pull request].
34
34
- [ ] Integrate another end-to-end testing framework to replace [ Spectron]
35
35
- [ ] Migrate to Webpack 5 ` Asset Modules ` __ * (pending for ` v4.2.0 ` )* __
36
36
- [ ] Integrate HMR & Webpack dev server
37
+ - [x] Monitor the status of ESM support on [ Jest] & [ ts-jest]
38
+ __ * (Check [ Known issues] ( #known-issues ) for details)* __
37
39
38
40
---
39
41
@@ -57,6 +59,11 @@ implemented, please [file an issue], or consider make a [new pull request].
57
59
to support ES module for its' config file. __ Converting the config file to
58
60
ES module will result in ESLint not working.__
59
61
62
+ - As of [ ` v4.1.2 ` ] , [ Jest] & [ ts-jest] are __ NOT__ configured to run the test
63
+ files as ES modules, despite all other sections of this boilerplate are
64
+ configured to support native ES modules. Please check
65
+ [ Known issues] ( #known-issues ) for details.
66
+
60
67
---
61
68
62
69
## Getting started
@@ -134,6 +141,42 @@ To package your Electron app, run `npm run prod` to get your code compiled in
134
141
uses Webpack to minify your code in `production` builds, so there shouldn't
135
142
be any significant performance difference with `asar` archiving disabled.
136
143
144
+ - __IMPORTANT!!!__
145
+
146
+ As of [`v4.1.2`], the `jest.mock()` function is broken if [Jest] and [ts-jest]
147
+ are configured with [ESM Support]. The following code will result in a
148
+ `SyntaxError` being thrown when trying to execute the test with Jest.
149
+
150
+ ```ts
151
+ import { jest } from '@jest/globals';
152
+ import { BrowserWindow } from 'electron';
153
+
154
+ jest.mock('electron', () => {
155
+ BrowserWindow: jest.fn().mockImplementation(() => {
156
+ loadFile: jest.fn(() => Promise.resolve()),
157
+ on: jest.fn(),
158
+ }),
159
+ });
160
+ ```
161
+
162
+ ```
163
+ SyntaxError: The requested module 'electron' does not provide an export named 'BrowserWindow'
164
+ ```
165
+
166
+ The current solution is to keep using the non ESM supported version of
167
+ ` jest.config.js ` , but with ` NODE_OPTIONS=--experimental-vm-modules ` set when
168
+ running Jest (already set in [ ` v4.1.2 ` ] ). The drawback of this is you won't
169
+ be able to use ` import.meta ` APIs in your code. It could be a deal breaker for
170
+ some of you.
171
+
172
+ I'm closely monitoring the situation atm, and I'll consider rollback the ESM
173
+ related setting introduced in [ ` v4.1.0 ` ] if there's no progress made solving
174
+ this issue by the time I prepare the release of ` v4.2.0 ` . You can track the
175
+ progress on a related issue [ facebook/jest #10025 ] if you want.
176
+
177
+ [ ESM Support ] : https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
178
+ [ facebook/jest #10025 ] : https://github.com/facebook/jest/issues/10025
179
+
137
180
## Project folders & files
138
181
- ` dist/ ` - [ Webpack] output location
139
182
@@ -163,8 +206,8 @@ To package your Electron app, run `npm run prod` to get your code compiled in
163
206
many APIs for IPC. See example as below:
164
207
``` ts
165
208
// ipc-api/index.ts
166
- import submoduleA from './submodule-a';
167
- import submoduleB from './submodule-b';
209
+ import submoduleA from ' ./submodule-a.js ' ;
210
+ import submoduleB from ' ./submodule-b.js ' ;
168
211
169
212
export default { ... submoduleA , ... submoduleB };
170
213
@@ -217,6 +260,7 @@ To package your Electron app, run `npm run prod` to get your code compiled in
217
260
you ' d use TypeScript if you' re using this boilerplate .
218
261
219
262
- ` main/main.spec.ts ` - Sample test file for ` src/main/main `
263
+ - ` utils/node-env.spec.ts ` - Unit test for ` src/utils/node-env `
220
264
- ` tsconfig.json ` - TypeScript config file for ` tests ` module
221
265
- ` .eslintignore ` - [ESLint ] ignore file
222
266
- ` .eslintrc.cjs ` - [ESLint ] config file
@@ -276,6 +320,7 @@ Electron React TypeScript Webpack Boilerplate is open source software
276
320
[file an issue ]: https :// www.electronjs.org
277
321
[new pull request ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare
278
322
[Spectron ]: https :// github.com/electron-userland/spectron
323
+ [ts - jest ]: https :// github.com/kulshekhar/ts-jest
279
324
[Playwright ]: https :// playwright.dev
280
325
[WebdriverIO ]: https :// webdriver.io
281
326
[Spectron Deprecation Notice ]: https :// www.electronjs.org/blog/spectron-deprecation-notice
@@ -291,3 +336,4 @@ Electron React TypeScript Webpack Boilerplate is open source software
291
336
[` v3.0.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v3.0.0
292
337
[` v4.0.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.0.0
293
338
[` v4.1.0 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.1.0
339
+ [` v4.1.2 ` ]: https :// github.com/Devtography/electron-react-typescript-webpack-boilerplate/releases/tag/v4.1.2
0 commit comments