Skip to content

Commit

Permalink
chore: split Jest configuration for Client and Electron
Browse files Browse the repository at this point in the history
The Jest configuration and setup files have been split into separate ones for client and Electron app testing. This will allow distinct test configuration and match patterns for the two different environments. Furthermore, corresponding changes are made in the package.json file to add different test scripts for running these new configuration files.
  • Loading branch information
pixelass committed Feb 21, 2024
1 parent 8156dd4 commit 1383d6e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 1 addition & 3 deletions jest.config.ts → jest.config.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { defaults } from "jest-config";

const jestConfig = {
...defaults,
roots: ["<rootDir>/src/client"],
testMatch: ["**/?(*.)test.ts?(x)"],
testPathIgnorePatterns: [".e2e."],
transform: {
"^.+\\.(t|j)sx?$": [
"@swc/jest",
Expand All @@ -22,7 +22,6 @@ const jestConfig = {
},
moduleNameMapper: {
"@/(.*)": "<rootDir>/src/client/$1",
"$/(.*)": "<rootDir>/src/electron/future/$1",
"#/(.*)": "<rootDir>/src/shared/$1",
},
collectCoverage: true,
Expand All @@ -37,7 +36,6 @@ const jestConfig = {
testEnvironment: "jsdom",
transformIgnorePatterns: ["/node_modules/"],
extensionsToTreatAsEsm: [".ts", ".tsx"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};

export default jestConfig;
31 changes: 31 additions & 0 deletions jest.config.electron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defaults } from "jest-config";

// Adjust the import path to your tsconfig.json file

const jestConfig = {
...defaults,
roots: ["<rootDir>/src/electron"],
testMatch: ["**/?(*.)test.ts"],
testPathIgnorePatterns: [".e2e."],
transform: {
"^.+\\.ts$": ["@swc/jest"],
},
moduleNameMapper: {
"@/(.*)": "<rootDir>/src/electron/future/$1",
"#/(.*)": "<rootDir>/src/shared/$1",
},
collectCoverage: true,
coverageDirectory: "./coverage",
coverageProvider: "v8",
coverageReporters: ["lcov", "text", "json"],
coverageThreshold: {
global: {
lines: 80,
},
},
transformIgnorePatterns: ["/node_modules/"],
extensionsToTreatAsEsm: [".ts"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.electron.ts"],
};

export default jestConfig;
16 changes: 7 additions & 9 deletions jest.setup.ts → jest.setup.electron.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
jest.mock("electron", () => {
const mockBrowserWindow = jest.fn().mockImplementation(() => ({
loadURL: jest.fn(),
on: jest.fn(),
once: jest.fn(),
close: jest.fn(),
}));

const mockWebContents = {
send: jest.fn(),
};
Expand All @@ -17,8 +10,13 @@ jest.mock("electron", () => {
close: jest.fn(),
webContents: mockWebContents,
};

mockBrowserWindow.getFocusedWindow = jest.fn(() => mockFocusedWindow);
const mockBrowserWindow = jest.fn().mockImplementation(() => ({
loadURL: jest.fn(),
on: jest.fn(),
once: jest.fn(),
close: jest.fn(),
getFocusedWindow: jest.fn(() => mockFocusedWindow),
}));

return {
BrowserWindow: mockBrowserWindow,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"toc": "npx markdown-toc README.md -i",
"tsc:noEmit": "tsc --noEmit",
"caption:test": "ts-node-esm main/captions/misc.ts",
"test:unit": "jest --runInBand --config jest.config.ts --verbose",
"test:electron": "jest --runInBand --config jest.config.electron.ts --verbose",
"test:client": "jest --runInBand --config jest.config.client.ts --verbose",
"pretest:e2e": "nextron build --no-pack",
"test:e2e": "npx playwright test"
},
Expand Down

0 comments on commit 1383d6e

Please sign in to comment.