Skip to content

Commit 72e4a8d

Browse files
committed
Merge branch 'hotfix/4.1.2' into develop
2 parents 92eed0a + 832d77c commit 72e4a8d

File tree

8 files changed

+241
-214
lines changed

8 files changed

+241
-214
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const jestConfig = {
7979
],
8080
rules: {
8181
...tsConfig.rules,
82+
'import/no-extraneous-dependencies': 'off',
8283
'@typescript-eslint/no-non-null-assertion': 'off',
8384
},
8485
settings: tsConfig.settings,

CHANGELOG_V4+.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [v4.1.2] - 2022-08-15
10+
### Added
11+
- Function `pathsToESModuleNameMapper` in `jest.config.js` to create the module
12+
mappings with ESM relative import with file extension (`.js`) syntax support
13+
for Jest from the path aliases set in `tsconfig`.
14+
15+
### Changed
16+
- Disable ESLint rule `import/no-extraneous-dependencies` on unit test files.
17+
- NPM script `test` now clear the cache for Jest before running the test and
18+
execute Jest with `NODE_OPTIONS=--experimental-vm-modules` flag to allow
19+
using dynamic import syntax.
20+
21+
### Fixed
22+
- Cannot find module issue reported by TypeScript server on relative imports in
23+
the unit test files after setting up native ES module support in [v4.1.0].
24+
25+
---
26+
27+
### Updates on package dependencies
28+
### Update
29+
- Minor & patch version updates:
30+
- `electron` - `20.0.1` -> `20.0.2`
31+
- `eslint` - `8.21.0` -> `8.22.0`
32+
- `eslint-import-resolver-typescript` - `3.4.0` -> `3.4.1`
33+
934
## [v4.1.1] - 2022-08-10
1035
### Fixed
1136
- Cannot find module issue reported by TypeScript server on relative imports
12-
after the migration to ES modules.
37+
after setting up native ES module support in [v4.1.0].
38+
39+
---
1340

1441
### Updates on package dependencies
42+
### Update
1543
- Minor & patch version updates:
1644
- `@types/react` - `18.0.15` -> `18.0.17`
1745
- `@typescript-eslint/eslint-plugin` & `@typescript-eslint/parser` -
@@ -46,6 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4674
- Module import order warnings in most modules.
4775
- ESLint warnings & errors on `jest.config.js` & `webpack.config.js`.
4876

77+
---
78+
4979
### Updates on package dependencies
5080
### Added
5181
- `eslint-import-resolver-typescript` *- Enhanced TypeScript support for ESLint
@@ -109,6 +139,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
109139
- Spectron as it ahs been deprecated.
110140
*See - [Spectron Deprecation Notice](https://www.electronjs.org/blog/spectron-deprecation-notice)*
111141

142+
---
143+
112144
### Updates on package dependencies
113145
### Added
114146
- `@types/jest`, `jest`, `ts-jest`, `eslint-plugin-jest` *- Jest support*
@@ -151,7 +183,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
151183
`ts-jest`*
152184
- `spectron` *- Deprecated package; No replacement*
153185

154-
[Unreleased]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.1.1...HEAD
186+
[Unreleased]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.1.2...HEAD
155187
[v4.0.0]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v3.0.0...v4.0.0
156188
[v4.1.0]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.0.0...v4.1.0
157-
[v4.1.1]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.2.0...v4.1.1
189+
[v4.1.1]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.1.0...v4.1.1
190+
[v4.1.2]: https://github.com/Devtography/electron-react-typescript-webpack-boilerplate/compare/v4.1.1...v4.1.2

README.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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

48
A boilerplate that let you instantly start working on your next [Electron] app
59
project 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 😉 ☕️️
263311
Electron 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

jest.config.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ import { pathsToModuleNameMapper } from 'ts-jest';
44
const require = createRequire(import.meta.url);
55
const { compilerOptions } = require('./tsconfig.json');
66

7+
/**
8+
* Enhance the Jest path mappings map returned from `pathsModuleNameMapper`
9+
* to support ES modules import syntax in TypeScript.
10+
*
11+
* @returns Jest path mappings map.
12+
*/
13+
function pathsToESModuleNameMapper() {
14+
const map = pathsToModuleNameMapper(
15+
compilerOptions.paths,
16+
{ prefix: '<rootDir>' },
17+
);
18+
const esmMap = {};
19+
20+
Object.entries(map).forEach((entry) => {
21+
const [key, val] = entry;
22+
23+
if (/.*\(\.\*\)\$$/.test(key)) {
24+
const convertedKey = `${key.substring(0, key.length - 1)}\\.js$`;
25+
esmMap[convertedKey] = val;
26+
}
27+
28+
esmMap[key] = val;
29+
});
30+
31+
return esmMap;
32+
}
33+
734
export default {
835
testEnvironment: 'node',
936
globals: {
@@ -12,10 +39,7 @@ export default {
1239
},
1340
},
1441
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
15-
moduleNameMapper: pathsToModuleNameMapper(
16-
compilerOptions.paths,
17-
{ prefix: '<rootDir>/' },
18-
),
42+
moduleNameMapper: pathsToESModuleNameMapper(),
1943
modulePathIgnorePatterns: [
2044
'<rootDir>/dist',
2145
'<rootDir>/node_modules',

0 commit comments

Comments
 (0)