Skip to content

Refactor/unit test rewrite#4584

Merged
burgerni10 merged 84 commits into
mainfrom
refactor/unit-test-rewrite
May 12, 2026
Merged

Refactor/unit test rewrite#4584
burgerni10 merged 84 commits into
mainfrom
refactor/unit-test-rewrite

Conversation

@kbalinthunor
Copy link
Copy Markdown
Collaborator

@kbalinthunor kbalinthunor commented Apr 29, 2026

What changed:

  • Migrated all 126 backend spec files from Jest to node:test (Node.js built-in test runner), removing jest, @types/jest, and jest-environment-jsdom from devDependencies
  • Replaced jest.fn() / expect() / jest.mock() with mock.fn() / assert.* / a require-cache swap pattern (mockModule + reloadModule) that works with ESM/CommonJS interop under tsx
  • Added tsx as the test transformer; updated all npm test scripts accordingly
  • Added createMockServices() factory to test-utils — centralizes mock service construction for all 13 controller specs, eliminating repeated Object.assign({} as Services, partial) workarounds
  • Added unit tests for all 5 Express middleware files (auth, ip-filter, services, sse, web-client) — these were completely uncovered before
  • Removed unreachable dead code in auth.middleware.ts (a duplicate if (req.url === '/api/users/current-user') block that could never execute)
  • Added --test-coverage-exclude flags for files with no testable logic: entry point, auto-generated routes, DB migrations, connector manifests, type-only model files, and build scripts

@kbalinthunor kbalinthunor requested a review from burgerni10 April 29, 2026 07:13
@kbalinthunor kbalinthunor force-pushed the refactor/unit-test-rewrite branch 2 times, most recently from 7f389f9 to ebc9727 Compare May 11, 2026 07:23
@kbalinthunor kbalinthunor force-pushed the refactor/unit-test-rewrite branch from 5df2e3d to f150765 Compare May 11, 2026 10:09
…history-query, ip-filter, north, oianalytics) to node:test
…n-mode, south, transformer, user) to node:test
…ter, log, scan-mode, user, utils-*) to node:test
…production code

Replace pino.Logger with a narrow ILogger interface across all production files and mock classes.
LoggerMock now implements ILogger, eliminating ~200 as-unknown-as-pino.Logger casts
and the asLogger() escape-hatch helper from test-utils.
…and spec

Extract toSouthConnectorItemDTO, toSouthItemGroupDTO, toHistoryQueryItemDTO,
and toScanModeDTO into lightweight utility files that do not transitively
import south-connector-factory, eliminating the ODBC crash on spec load.
Update oianalytics-command.service.ts and the spec to import from these files
instead of south.service / history-query.service. Fix incorrect cancel count
assertion in the "should check retrieved command" test.
… migration

- Add ILogger interface to remove pino.Logger dependency in mocks
- Add narrow interfaces in service files to decouple from concrete class imports
- Fix mock classes to extend real classes for type safety
- Fix ODBC loading by using import type for DataStreamEngine in service files
- Move southManifestList/northManifestList imports to dedicated manifest files
- Fix history-query.service.ts setter propagation crash in HistoryQueryMock
- Fix metrics getter shape to match engine expectations
@kbalinthunor kbalinthunor force-pushed the refactor/unit-test-rewrite branch from 2c30c48 to c731b47 Compare May 12, 2026 07:34
kbalinthunor and others added 4 commits May 12, 2026 11:37
Move nodeOptions and testRunner sections from the standalone
node.coverage.config.json into package.json, pointing
--experimental-config-file at package.json itself.
@burgerni10 burgerni10 force-pushed the refactor/unit-test-rewrite branch from 1ded4fc to f452564 Compare May 12, 2026 10:13
@burgerni10 burgerni10 merged commit e113d06 into main May 12, 2026
4 checks passed
@burgerni10 burgerni10 deleted the refactor/unit-test-rewrite branch May 12, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants