Skip to content

Commit 9475ffb

Browse files
committed
test(electron): switch to @kayahr/jest-electron-runner and fix electron unit tests
1 parent 769e8d2 commit 9475ffb

5 files changed

Lines changed: 612 additions & 5375 deletions

File tree

config/electron-jest.config.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,64 @@
1+
// these paths must be specified because otherwise typescript relies on the
2+
// "main" field in each package.json file, which points to the compiled JS and
3+
// we want to run Jest against the TS source
4+
const paths = {
5+
// @bugsnag/core must resolve to source so that module-level singleton state
6+
// (e.g. clone-client's onCloneCallbacks) is shared across jest.isolateModules
7+
// boundaries. Without this, bundled dist creates duplicate state.
8+
'@bugsnag/core': ['./packages/core/src/index.ts']
9+
}
10+
11+
const moduleNameMapper = Object.fromEntries(
12+
Object.entries(paths)
13+
.map(([name, directories]) => [
14+
`^${name}$`,
15+
directories.map(directory => directory.replace('./', '<rootDir>/'))
16+
])
17+
)
18+
19+
const defaultModuleConfig = {
20+
preset: 'ts-jest/presets/js-with-ts',
21+
moduleNameMapper,
22+
transform: {
23+
'^.+\\.m?[tj]sx?$': [
24+
'ts-jest',
25+
{
26+
isolatedModules: true,
27+
tsconfig: {
28+
module: 'commonjs',
29+
target: 'ES2019',
30+
esModuleInterop: true,
31+
allowSyntheticDefaultImports: true,
32+
allowJs: true,
33+
skipLibCheck: true,
34+
jsx: 'react',
35+
paths
36+
}
37+
}
38+
]
39+
}
40+
}
41+
142
module.exports = {
243
projects: [
344
{
4-
resolver: '<rootDir>/jest/node-exports-resolver',
45+
...defaultModuleConfig,
546
setupFilesAfterEnv: ['<rootDir>/test/electron/setup.ts'],
647
clearMocks: true,
748
modulePathIgnorePatterns: ['.verdaccio', 'fixtures', 'examples'],
849
displayName: 'electron main',
9-
runner: '@jest-runner/electron/main',
50+
runner: '@kayahr/jest-electron-runner/main',
51+
testEnvironment: 'node',
1052
testMatch: ['**/test/**/*.test-main.ts']
1153
},
1254
{
13-
resolver: '<rootDir>/jest/node-exports-resolver',
55+
...defaultModuleConfig,
1456
setupFilesAfterEnv: ['<rootDir>/test/electron/setup.ts'],
1557
clearMocks: true,
1658
modulePathIgnorePatterns: ['.verdaccio', 'fixtures', 'examples'],
1759
displayName: 'electron renderer',
18-
runner: '@jest-runner/electron',
60+
runner: '@kayahr/jest-electron-runner',
61+
testEnvironment: '@kayahr/jest-electron-runner/environment',
1962
testMatch: ['**/test/**/*.test-renderer.ts']
2063
}
2164
]

jest/node-exports-resolver.js

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)