[Feature] Add test framework and write tests #9

Open
opened 2026-08-16 06:34:42 +00:00 by nasandre · 2 comments
Owner

Problem
The repository has zero test files. No test framework (Jest, Vitest, etc.) is configured in any package.json. The frontend tsconfig.json excludes **/*.test.tsx, suggesting test file patterns were anticipated but never implemented.

Proposed fix

  1. Add test runner configuration:
    • Frontend: vitest (pairs well with Vite) or jest
    • Backend: jest or vitest with tsx
  2. Add basic test scripts to root package.json:
    "test": "vitest run",
    "test:watch": "vitest",
    "test:coverage": "vitest run --coverage"
    
  3. Write tests for:
    • Backend: userService.ts (auth, password hashing), characterService.ts (CRUD, search), database.ts query translation (SQLite dialect)
    • Frontend: authStore.ts (login/logout state), characterStore.ts (fetch/create/update), DiceRoller components

Priority: Medium
Labels: feature, testing, backend, frontend

**Problem** The repository has zero test files. No test framework (Jest, Vitest, etc.) is configured in any `package.json`. The frontend `tsconfig.json` excludes `**/*.test.tsx`, suggesting test file patterns were anticipated but never implemented. **Proposed fix** 1. Add test runner configuration: - Frontend: `vitest` (pairs well with Vite) or `jest` - Backend: `jest` or `vitest` with `tsx` 2. Add basic test scripts to root `package.json`: ```json "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage" ``` 3. Write tests for: - Backend: `userService.ts` (auth, password hashing), `characterService.ts` (CRUD, search), `database.ts` query translation (SQLite dialect) - Frontend: `authStore.ts` (login/logout state), `characterStore.ts` (fetch/create/update), `DiceRoller` components **Priority:** Medium **Labels:** feature, testing, backend, frontend
Author
Owner

Status update after review: vitest is now configured in both backend/package.json (npm test → vitest run) and frontend/package.json, but there are zero test files in either package (no __tests__ dirs, no .test. files). Framework step done; actual tests still needed. Highest-value first targets: characterService.createCharacter (skills/equipment matching), campaignService authorization helpers (isCampaignMember/isCampaignGM), auth middleware.

Status update after review: vitest is now configured in both backend/package.json (`npm test` → `vitest run`) and frontend/package.json, but there are **zero test files** in either package (no `__tests__` dirs, no *.test.* files). Framework step done; actual tests still needed. Highest-value first targets: characterService.createCharacter (skills/equipment matching), campaignService authorization helpers (isCampaignMember/isCampaignGM), auth middleware.
Owner

Automated triage (openclaw monitor):

Diagnosis

  • No test framework configured in any package.json (frontend or backend)
  • Zero test files exist despite frontend/tsconfig.json excluding **/*.test.tsx
  • Backend services (userService.ts, characterService.ts) and frontend stores (authStore.ts, characterStore.ts) lack test coverage
  • No CI configuration for running tests (.forgejo/workflows/ci.yml exists but likely doesn't run tests)

Possible fix

Backend (Node.js/Express):

  1. Add backend/jest.config.js with TypeScript support
  2. Install dependencies: jest @types/jest ts-jest @jest/globals
  3. Add scripts to backend/package.json:
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage"
    
  4. Write tests for:
    • backend/src/services/userService.ts (auth, password hashing)
    • backend/src/services/characterService.ts (CRUD, search)
    • backend/src/config/database.ts (query translation)

Frontend (React/Vite):

  1. Add frontend/vitest.config.ts with React support
  2. Install dependencies: @testing-library/react @testing-library/jest-dom vitest jsdom
  3. Add scripts to frontend/package.json:
    "test": "vitest run",
    "test:watch": "vitest",
    "test:coverage": "vitest run --coverage"
    
  4. Write tests for:
    • frontend/src/store/authStore.ts (login/logout state)
    • frontend/src/store/characterStore.ts (fetch/create/update)
    • DiceRoller components

Root:
Add test scripts to root package.json to run both:

"test": "npm run test:backend && npm run test:frontend",
"test:backend": "cd backend && npm test",
"test:frontend": "cd frontend && npm test"

Notes

  • Which test runner preferred: vitest for both or jest for backend?
  • Target test coverage percentage?
  • Should tests run in CI? If so, update .forgejo/workflows/ci.yml
  • Mocking strategy for database/API calls?
  • Prioritize auth/character services first?
Automated triage (openclaw monitor): ## Diagnosis - No test framework configured in any `package.json` (frontend or backend) - Zero test files exist despite `frontend/tsconfig.json` excluding `**/*.test.tsx` - Backend services (`userService.ts`, `characterService.ts`) and frontend stores (`authStore.ts`, `characterStore.ts`) lack test coverage - No CI configuration for running tests (`.forgejo/workflows/ci.yml` exists but likely doesn't run tests) ## Possible fix **Backend (Node.js/Express):** 1. Add `backend/jest.config.js` with TypeScript support 2. Install dependencies: `jest @types/jest ts-jest @jest/globals` 3. Add scripts to `backend/package.json`: ```json "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage" ``` 4. Write tests for: - `backend/src/services/userService.ts` (auth, password hashing) - `backend/src/services/characterService.ts` (CRUD, search) - `backend/src/config/database.ts` (query translation) **Frontend (React/Vite):** 1. Add `frontend/vitest.config.ts` with React support 2. Install dependencies: `@testing-library/react @testing-library/jest-dom vitest jsdom` 3. Add scripts to `frontend/package.json`: ```json "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage" ``` 4. Write tests for: - `frontend/src/store/authStore.ts` (login/logout state) - `frontend/src/store/characterStore.ts` (fetch/create/update) - DiceRoller components **Root:** Add test scripts to root `package.json` to run both: ```json "test": "npm run test:backend && npm run test:frontend", "test:backend": "cd backend && npm test", "test:frontend": "cd frontend && npm test" ``` ## Notes - Which test runner preferred: `vitest` for both or `jest` for backend? - Target test coverage percentage? - Should tests run in CI? If so, update `.forgejo/workflows/ci.yml` - Mocking strategy for database/API calls? - Prioritize auth/character services first?
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nasandre/wh40-rogue-trader#9
No description provided.