unit-test-quality/test-data-management penalise real in-memory implementations and require mocks

Aperta
#29 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
testing-qa

Direzione di ricerca

Start by locating the rules and tests for unit-test-quality-standards and test-data-management, then trace how they determine whether tests use mocks. The issue offers two alternative directions, so clarify which behavior is wanted before changing anything. Done means the tests cover the chosen policy and real in-memory implementations are no longer penalized unfairly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Version: 7.17.6
Laws: unit-test-quality-standards, test-data-management

What happens

Both laws report against test suites that deliberately use real in-memory
implementations instead of mocks:

• Dependencies found but no mocking detected in .../launch.page.spec.ts
• Dependencies found but no mocking detected in .../capability-matrix.spec.ts
• External dependencies are not properly mocked in tests

Every one of those files is a suite we would hold up as an example. The laws
are asking us to weaken them.

Why this is the wrong direction

A mock asserts that the code agrees with the test author's belief about a
collaborator, rather than with the collaborator. Two concrete cases from this
repository:

1. InMemoryPlatformCapabilityService runs the same resolution function
and the same capability matrix as production. Only the reported environment
differs. Mocking it would mean asserting against a hand-written table that can
drift from the real matrix — which is exactly the bug the tests exist to catch.

2. InMemoryResourceEnvironment keeps a real monotonic clock and a real
task queue that the test advances. It replaced a faked-timer approach precisely
because fake timers hide the ordering bugs a polling primitive is prone to:
overlapping refreshes, a stale alarm firing after teardown, a poll scheduled
from inside a finally.

Both are strictly stronger than mocking the collaborator away. Under these laws
they score worse than a suite full of jest.fn() that asserts nothing about
real behaviour.

That is the definition of a checkbox that lies, and it is the one thing our
engineering canon forbids outright — so we are reporting it rather than
complying, and rather than waiving it.

Suggested fix

Two options, either would work:

  1. Detect test doubles by role, not by framework. A class named
    InMemory* / Fake* / Stub* injected in place of a real collaborator is
    a test double. The current check appears to look only for a mocking library.
  2. Invert the law toward the property that matters: "a unit test must not
    reach real I/O — no network, no filesystem, no wall clock". That is what
    mocking is a means to, and it can be detected directly. A suite using real
    in-memory implementations passes it honestly; a suite that quietly hits the
    network fails it, which today's version does not catch.

(2) would also have caught a genuine bug in a sibling repository, where a test
was found to be making a live network call.

Lingua principale
TypeScript
Stelle
0
Fork
0
Merge medio
38m
PR unite (30g)
96

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Rule-Of-Code/RoC

Tutte le issue di Rule-Of-Code/RoC

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.