Skip to content

Commit 1e020a5

Browse files
authored
feat: add comprehensive test suite with Vitest and Playwright (#16)
* feat: add comprehensive test suite with Vitest and Playwright Add testing infrastructure for the application: - Configure Vitest with separate configs for main and renderer processes - Add React Testing Library for component testing - Set up Playwright for E2E testing - Create test setup files with mocks for Electron APIs Test coverage includes: - Renderer hooks: useDebounce, useKeyboardEvent, useKeyboardShortcuts - Contexts: Settings, Theme, Update, Breadcrumb - Components: DataTable, NewPatientForm - Main process: repository tests (structure only, requires Electron env) - Integration tests (structure only, requires Electron env) - E2E tests with Playwright (skipped by default) Update CI workflow to run tests before build. * fix: correct test schemas and CI workflow order - Fix activity.test.ts: use camelCase properties (entityType, surgeryId) and correct action types ('created'/'updated' instead of 'create'/'update') - Fix patient.test.ts: use correct schema (phn, birth_year, gender) - Fix dashboard.test.ts: use correct patient/surgery schema - Fix surgery.test.ts: use correct schema (title, bht, ward instead of procedure) - Fix surgery-template.test.ts: use title instead of name - Fix app-settings.test.ts: handle possibly undefined results - Fix backup.test.ts: add type annotation for array - Fix NewPatientForm.test.tsx: use Date objects for created_at/updated_at - Fix renderer-setup.ts: import beforeEach from vitest - Update tsconfig.web.json: add jest-dom types - Update CI workflow: run tests after lint and typecheck
1 parent 9e2ff2b commit 1e020a5

40 files changed

+7299
-2
lines changed

.github/workflows/build.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ jobs:
5858
- name: Typecheck
5959
run: pnpm typecheck
6060

61+
- name: Run Tests
62+
run: pnpm test:run
63+
6164
- name: Build
6265
run: pnpm build

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
"build:linux": "electron-vite build && electron-builder --linux --publish=never",
2626
"electron-rebuild": "electron-rebuild -f -w better-sqlite3",
2727
"prepare": "husky",
28-
"commitlint": "commitlint --edit"
28+
"commitlint": "commitlint --edit",
29+
"test": "vitest",
30+
"test:main": "vitest --config vitest.config.main.ts",
31+
"test:renderer": "vitest --config vitest.config.renderer.ts",
32+
"test:run": "vitest run --config vitest.config.renderer.ts",
33+
"test:coverage": "vitest run --coverage",
34+
"test:ui": "vitest --ui",
35+
"test:e2e": "playwright test",
36+
"test:e2e:ui": "playwright test --ui"
2937
},
3038
"dependencies": {
3139
"@electron-toolkit/preload": "^3.0.1",
@@ -95,14 +103,20 @@
95103
"@electron-toolkit/tsconfig": "^1.0.1",
96104
"@electron/rebuild": "^3.7.1",
97105
"@eslint/js": "^9.39.2",
106+
"@playwright/test": "^1.57.0",
98107
"@tailwindcss/typography": "^0.5.16",
99108
"@tailwindcss/vite": "^4.0.0",
100109
"@tanstack/eslint-plugin-query": "^5.62.8",
110+
"@testing-library/jest-dom": "^6.9.1",
111+
"@testing-library/react": "^16.3.1",
112+
"@testing-library/user-event": "^14.6.1",
101113
"@types/better-sqlite3": "^7.6.12",
102114
"@types/node": "^22.10.5",
103115
"@types/react": "^18.3.18",
104116
"@types/react-dom": "^18.3.5",
105117
"@vitejs/plugin-react": "^4.3.4",
118+
"@vitest/coverage-v8": "^4.0.17",
119+
"@vitest/ui": "^4.0.17",
106120
"electron": "^33.3.1",
107121
"electron-builder": "^25.1.8",
108122
"electron-vite": "^2.3.0",
@@ -111,12 +125,15 @@
111125
"eslint-plugin-react-hooks": "^5.1.0",
112126
"globals": "^17.0.0",
113127
"husky": "^9.1.7",
128+
"jsdom": "^27.4.0",
114129
"postcss": "^8.4.49",
115130
"prettier": "^3.4.2",
116131
"react": "^18.3.1",
117132
"react-dom": "^18.3.1",
118133
"tailwindcss": "^4.0.0",
119134
"typescript": "^5.7.2",
120-
"vite": "^6.0.7"
135+
"vite": "^6.0.7",
136+
"vitest": "^4.0.17",
137+
"vitest-mock-extended": "^3.1.0"
121138
}
122139
}

playwright.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
export default defineConfig({
4+
testDir: './tests/e2e',
5+
fullyParallel: false,
6+
forbidOnly: !!process.env.CI,
7+
retries: process.env.CI ? 2 : 0,
8+
workers: 1,
9+
reporter: 'html',
10+
timeout: 60000,
11+
use: {
12+
trace: 'on-first-retry',
13+
screenshot: 'only-on-failure'
14+
},
15+
projects: [
16+
{
17+
name: 'electron',
18+
use: { ...devices['Desktop Chrome'] }
19+
}
20+
]
21+
})

0 commit comments

Comments
 (0)