review-tests
GitHub针对Chrome DevTools前端测试代码的代码审查技能,涵盖测试辅助函数复用、模块化钩子使用及异步同步规范,旨在提升测试稳定性与可维护性。
Trigger Scenarios
Install
npx skills add ChromeDevTools/devtools-frontend --skill review-tests -g -y
SKILL.md
Frontmatter
{
"name": "review-tests",
"description": "Reviews Chrome DevTools frontend changes in target directories (\\.test\\.ts$, ^test\/, ^front_end\/testing\/), strictly reflecting review standards, architectural invariants, and security boundaries derived from historical code reviews."
}
Chrome DevTools frontend reviewer skill: tests
This skill provides review guidance for Chrome DevTools frontend changes matching the target directories (.test.ts$, ^test/, ^front_end/testing/). It focuses specifically on code review verification for test changes, complementing authoring guidance in devtools-testing-guidance and integrating with the general review checklist in code-review. Every rule below recurred in at least 5 CLs from 2 distinct reviewers in historical reviews; cite the rule id in findings.
Path group tests (9 rules)
TEST_SHARED_FIXTURE_AND_HELPER_REUSE: Reuse canonical front_end/testing helpers and beforeEach setup without mutating cached shared fixtures
- Severity: WARNING
- Why: Duplicating mock factories (
createTarget,createNetworkRequest,mockAidaClient,cleanTextContent) or mutating cached objects returned byTraceLoadercauses cross-test state corruption and maintenance drift across the test suite. - Look for: Custom inline network request or AIDA client mocks in
.test.tsfiles, in-place mutation ofparsedTraceobjects returned byTraceLoader, or manualdivcontainer creation aroundrenderElementIntoDOM(widget). - Do not flag: Specialized test helpers inside
front_end/testing/that define the canonical factory implementations themselves.
TEST_MODULAR_HOOKS_AND_TEST_UNIVERSE: Use lightweight modular setup hooks and TestUniverse instead of heavyweight describeWithEnvironment wrappers
- Severity: WARNING
- Why: Wrapping unit tests in
describeWithEnvironmentinitializes all DevTools global singletons and settings, slowing down tests and hiding implicit global dependencies. Tests should useTestUniverseor granular hooks (setupLocaleHooks(),setupSettingsHooks(),updateHostConfig()) and never mixTestUniversewithdescribeWithEnvironment. - Look for:
describeWithEnvironmentin unit tests that only need locale, settings, orTestUniverse, or suites combiningnew TestUniverse()withdescribeWithEnvironment, or direct mutation ofRoot.Runtime.hostConfiginstead ofupdateHostConfig(...). - Do not flag: Integration-style panel tests that exercise legacy singleton classes not yet migrated to
Universedependency injection. Bot-only CLI flags, credentials, or standalone runner scripts undertest/conductor/ortest/ai_evals/that do not run inside the standard Mocha unit test harness.
TEST_DETERMINISTIC_ASYNC_SYNCHRONIZATION: Synchronize asynchronous test assertions using lifecycle promises, expectCall, or raf instead of arbitrary setTimeout delays
- Severity: ERROR
- Why: Waiting on wall-clock
setTimeoutdelays or arbitrary microtask ticks makes unit tests slow and flaky under CPU contention on CI bots. Tests should await explicit widget update promises (await widget.updateComplete), event promises (target.once(...)), stub invocation helpers (expectCall(stub)), orraf(). - Look for:
new Promise(r => setTimeout(r, ...))in.test.tsfiles, synchronous DOM assertions immediately afterrequestUpdate(), or redundantclock.tick()calls when no fake timers are pending. - Do not flag: Tests specifically verifying debounce/throttle timer expiration using
sinon.useFakeTimers().
TEST_STRICT_ASSERTIONS_AND_LITERAL_EXPECTATIONS: Use strict Chai and Sinon assertions against literal expected values rather than assert.isNotNull on undefined-unions or conditional guards
- Severity: ERROR
- Why: Calling
assert.isNotNull(x)on a value typed asT | undefinedpasses whenxisundefined, silently skipping assertions. Similarly, wrapping assertions insideif (el)or computing expected values by calling the same production helper under test allows broken code to pass. - Look for:
assert.isNotNull(...)oncontainer?.querySelector/Map.get/Array.find/ optional properties,if (el) { assert... }blocks,assert.isTrue(spy.called)instead ofsinon.assert.calledWith, or assertions comparing output against production formatting helpers. - Do not flag: Variables whose static return type is strictly
T | null(and neverundefined).
TEST_VIEW_AND_PRESENTER_ISOLATION: Test presenters via createViewFunctionStub and test pure view functions directly without piercing internal DOM structures
- Severity: WARNING
- Why: In DevTools' MVP (
UI.Widget+DEFAULT_VIEW) architecture, presenter tests should follow the view stubbing conventions documented indocs/ui_engineering.mdby stubbing the view function withcreateViewFunctionStub(Presenter)and asserting onawait view.nextInput, while view rendering tests should invokeDEFAULT_VIEW(input, output, target)directly or use screenshot assertions. - Look for: Presenter tests instantiating full DOM trees and querying shadow/child DOM selectors to simulate clicks when the widget accepts a
viewfunction, or view tests instantiating full presenters just to test template markup. - Do not flag: Legacy widgets that have not yet separated their template rendering into a standalone
DEFAULT_VIEWfunction.
TEST_PUBLIC_API_AND_ENCAPSULATION: Exercise classes through public APIs and constructor-injected dependencies rather than accessing private members or stubbing unused singletons
- Severity: WARNING
- Why: Accessing
#privateorprivatemethods via(instance as any)or@ts-expect-error, piercing child component shadow roots, or stubbingClass.instance()when dependencies are already passed via constructor couples tests to internal implementation details. - Look for:
@ts-expect-erroror(obj as any).privateMethod()calls in.test.tsfiles,sinon.stub(Class, 'instance')alongsidenew UnderTest(mockInstance), orchild.shadowRoot.querySelector(...)inside parent component tests. - Do not flag: Intentional negative type tests documented with an explanatory
@ts-expect-errorcomment.
TEST_SINGLE_RESPONSIBILITY_AND_CONCISENESS: Keep each it() block focused on a single behavior and prune duplicate or obsolete tests when features change
- Severity: WARNING
- Why: Combining multiple independent user interactions or feature scenarios into a single monolithic
it()block obscures failure root causes, while leaving duplicate or orphaned tests behind increases suite runtime and maintenance burden. - Look for:
it('... and ...')blocks testing multiple orthogonal interactions sequentially, nested{ ... }scope blocks inside a singleit(), or identical test cases duplicated acrossdescribeblocks. - Do not flag: Multi-step stateful workflow tests where earlier steps are required preconditions to reach the state under test.
TEST_TYPE_SAFE_MOCKS_AND_EVENTS: Construct typed stubs and real DOM or event instances instead of casting fake objects with as unknown as
- Severity: WARNING
- Why: Casting partial object literals via
as unknown as Toras anybypasses TypeScript compile-time checks, masks missing methods when interfaces evolve, and causes brittle runtime failures. Usingsinon.createStubInstance(Class), real DOM/Event constructors (DataTransfer,ClipboardEvent), or typed fixture helpers preserves type safety. - Look for:
as unknown asoras anycasts on mock objects, fake DOM nodes, or synthetic events in.test.tsfiles, or untypedquerySelector(...) as HTMLElementcalls. - Do not flag: Tests explicitly verifying runtime handling of malformed untrusted payloads or narrow generic type parameters inside shared
front_end/testing/helpers.
TEST_CLEANUP_MUTATED_GLOBALS_AND_WIDGETS: Restore mutated global properties and detach manually instantiated widgets or singletons in afterEach or finally blocks
- Severity: WARNING
- Why: While Sinon stubs are restored automatically, direct mutations to
window,globalThis, prototypes, orlocalStorage, as well as widgets and panels instantiated with.markAsRoot()orshow(), persist across tests and leak listeners unless explicitly cleaned up inafterEachortry...finally. - Look for: Direct assignments to
window.*,globalThis.*,Object.prototype.*,localStorage.*, orpanel.show(document.body)in.test.tsfiles without a matching restoration ordetach()inafterEachorfinally. - Do not flag: Widgets mounted directly via
renderElementIntoDOM(widget), which detaches widgets automatically during global harness teardown.
Version History
- 6527f72 Current 2026-10-20 02:26


