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

未关闭
#29 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
typescript
领域
testing-qa

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
0
派生
0
平均合并
38 分钟
30 天内合并 PR
96

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Rule-Of-Code/RoC 的其他 Issue

查看 Rule-Of-Code/RoC 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。