Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep duplicated test config files in sync
When a mock/mapper is added to one test config, update every parallel test config that duplicates it.
Bad example
| 1 | // jest.config.json (unit tests) |
| 2 | { |
| 3 | "moduleNameMapper": { |
| 4 | "^@org/logger$": "<rootDir>/test/mocks/logger.ts", |
| 5 | "^@org/cache-client$": "<rootDir>/test/mocks/cache-client.ts" |
| 6 | } |
| 7 | } |
| 8 |
|
| 9 | // test/jest-e2e.json (e2e tests) — left unchanged |
| 10 | { |
| 11 | "moduleNameMapper": { |
| 12 | "^@org/logger$": "<rootDir>/../test/mocks/logger.ts" |
| 13 | } |
| 14 | } |
Explanation (EN)
Adding a mock or mapper to only one of several parallel test config files leaves the others out of sync; any suite using the stale config fails to load a module it doesn't know how to mock, and if that suite isn't part of the same pre-commit/CI hook the break can go unnoticed.
Objašnjenje (HR)
Ako se mock ili mapper doda samo u jedan od više paralelnih test config fileova, ostali ostaju nesinkronizirani; svaki test suite koji koristi zastarjeli config ne uspijeva učitati modul koji ne zna mockati, a ako taj suite nije dio istog pre-commit/CI hooka, kvar može proći nezamijećeno.
Good example
| 1 | // jest.config.json AND test/jest-e2e.json both updated identically |
| 2 | { |
| 3 | "moduleNameMapper": { |
| 4 | "^@org/logger$": "<rootDir>/test/mocks/logger.ts", |
| 5 | "^@org/cache-client$": "<rootDir>/test/mocks/cache-client.ts" |
| 6 | } |
| 7 | } |
Explanation (EN)
When a project keeps separate configs per test runner/type, grep for every config file that duplicates the setting and update them together — and make sure CI/pre-commit actually runs every test type, not just the fast one.
Objašnjenje (HR)
Kad projekt drži odvojene configove po tipu testova, pretraži sve fileove koji dupliciraju tu postavku i ažuriraj ih zajedno — i provjeri da CI/pre-commit doista pokreće sve tipove testova, ne samo brži.
Notes (EN)
Worth flagging in the same review whether the missing test type is even wired into pre-commit/CI at all — a config fix doesn't help if the suite is never run.
Bilješke (HR)
Vrijedi u istom reviewu provjeriti je li taj tip testova uopće ukopčan u pre-commit/CI — popravak configa ne pomaže ako se taj suite nikad ne pokreće.