From 1383d6ef885165286e94d610b11f05d6e869f7d2 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 21:40:48 +0100 Subject: [PATCH] chore: split Jest configuration for Client and Electron 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. --- jest.config.ts => jest.config.client.ts | 4 +--- jest.config.electron.ts | 31 +++++++++++++++++++++++++ jest.setup.ts => jest.setup.electron.ts | 16 ++++++------- package.json | 3 ++- 4 files changed, 41 insertions(+), 13 deletions(-) rename jest.config.ts => jest.config.client.ts (85%) create mode 100644 jest.config.electron.ts rename jest.setup.ts => jest.setup.electron.ts (88%) diff --git a/jest.config.ts b/jest.config.client.ts similarity index 85% rename from jest.config.ts rename to jest.config.client.ts index 0f0f04cfa..3487af15e 100644 --- a/jest.config.ts +++ b/jest.config.client.ts @@ -4,8 +4,8 @@ import { defaults } from "jest-config"; const jestConfig = { ...defaults, + roots: ["/src/client"], testMatch: ["**/?(*.)test.ts?(x)"], - testPathIgnorePatterns: [".e2e."], transform: { "^.+\\.(t|j)sx?$": [ "@swc/jest", @@ -22,7 +22,6 @@ const jestConfig = { }, moduleNameMapper: { "@/(.*)": "/src/client/$1", - "$/(.*)": "/src/electron/future/$1", "#/(.*)": "/src/shared/$1", }, collectCoverage: true, @@ -37,7 +36,6 @@ const jestConfig = { testEnvironment: "jsdom", transformIgnorePatterns: ["/node_modules/"], extensionsToTreatAsEsm: [".ts", ".tsx"], - setupFilesAfterEnv: ["/jest.setup.ts"], }; export default jestConfig; diff --git a/jest.config.electron.ts b/jest.config.electron.ts new file mode 100644 index 000000000..ae6b30719 --- /dev/null +++ b/jest.config.electron.ts @@ -0,0 +1,31 @@ +import { defaults } from "jest-config"; + +// Adjust the import path to your tsconfig.json file + +const jestConfig = { + ...defaults, + roots: ["/src/electron"], + testMatch: ["**/?(*.)test.ts"], + testPathIgnorePatterns: [".e2e."], + transform: { + "^.+\\.ts$": ["@swc/jest"], + }, + moduleNameMapper: { + "@/(.*)": "/src/electron/future/$1", + "#/(.*)": "/src/shared/$1", + }, + collectCoverage: true, + coverageDirectory: "./coverage", + coverageProvider: "v8", + coverageReporters: ["lcov", "text", "json"], + coverageThreshold: { + global: { + lines: 80, + }, + }, + transformIgnorePatterns: ["/node_modules/"], + extensionsToTreatAsEsm: [".ts"], + setupFilesAfterEnv: ["/jest.setup.electron.ts"], +}; + +export default jestConfig; diff --git a/jest.setup.ts b/jest.setup.electron.ts similarity index 88% rename from jest.setup.ts rename to jest.setup.electron.ts index d787f1429..a338e4589 100644 --- a/jest.setup.ts +++ b/jest.setup.electron.ts @@ -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(), }; @@ -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, diff --git a/package.json b/package.json index 0b74e92de..a35f8f2db 100644 --- a/package.json +++ b/package.json @@ -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" },