Comfy-Org / Comfy-Org/ComfyUI_frontend

refactor(test): reduce vi.mock() factory signature drift with Parameters<typeof ...>

Open
#11,793 0 comments 0 reactions 1 assignee Claimed by @jaeone94 View on GitHub
area:testing developer experience
Dominant language
TypeScript
Stars
2k
Forks
704
Avg merge
1d 8h
Merged PRs (30d)
512

Description

## Summary

In `src/platform/missingModel/missingModelPipeline.test.ts`, each `vi.mock()` factory manually re-types the full signature of every wrapped function (e.g. `scanAllModelCandidates`, `enrichWithEmbeddedMetadata`, `verifyAssetSupportedCandidates`). This duplicates upstream signatures and will silently drift whenever those functions evolve.

## Suggested Fix

Replace the verbose wrapper pattern:

```ts
vi.mock('@/platform/missingModel/missingModelScan', () => ({
scanAllModelCandidates: (
graph: LGraph,
isAssetSupported: (nodeType: string, widgetName: string) => boolean,
getDirectory?: (nodeType: string) => string | undefined
) => mockHandles.scanAllModelCandidates(graph, isAssetSupported, getDirectory),
// ...
}))
```

with the `Parameters` forwarding pattern:

```ts
import type { scanAllModelCandidates, enrichWithEmbeddedMetadata, verifyAssetSupportedCandidates } from '@/platform/missingModel/missingModelScan'

vi.mock('@/platform/missingModel/missingModelScan', () => ({
scanAllModelCandidates: (...args: Parameters) =>
mockHandles.scanAllModelCandidates(...args),
enrichWithEmbeddedMetadata: (...args: Parameters) =>
mockHandles.enrichWithEmbeddedMetadata(...args),
verifyAssetSupportedCandidates: (...args: Parameters) =>
mockHandles.verifyAssetSupportedCandidates(...args),
}))
```

This halves the boilerplate and ensures wrappers stay in sync with upstream signatures automatically.

## Context

- Raised during review of PR #11751 (comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11751#discussion_r3171340085)
- PR author (@jaeone94) agreed to defer as a follow-up nit to keep PR #11751 focused on the blocking shared mock identity issue.
- @DrJKL requested the tracking issue.

## Files Affected

- `src/platform/missingModel/missingModelPipeline.test.ts`

┆Issue is synchronized with this [Notion page](https://app.notion.com/p/Issue-11793-refactor-test-reduce-vi-mock-factory-signature-drift-with-Parameters-typeof-3536d73d365081629ac3f1bc0ef604bd) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.