-
Notifications
You must be signed in to change notification settings - Fork 670
test: preserve module-scope mock defaults #15529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /** Matches the un narrowed callable shape of a fresh `vi.fn()`. */ | ||
| type AnyMockProcedure = (...args: any[]) => any |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ const hoisted = vi.hoisted(() => ({ | |
| isEnabled: true, | ||
| isMobileUa: true, | ||
| mockPreload: vi.fn(), | ||
| mockSubmit: vi.fn().mockResolvedValue(undefined) | ||
| mockSubmit: vi.fn<AnyMockProcedure>(async () => undefined) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target test ---'
cat -n apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts | sed -n '1,80p'
printf '%s\n' '--- shared type ---'
cat -n apps/website/src/env.d.ts | sed -n '1,40p'
printf '%s\n' '--- AnyMockProcedure usages and definitions ---'
rg -n -C 3 '\bAnyMockProcedure\b' --glob '!node_modules/**' .
printf '%s\n' '--- relevant type guidance ---'
cat -n docs/guidance/typescript.md | sed -n '1,220p'
printf '%s\n' '--- changed-file status ---'
git status --short
git diff --stat -- apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts apps/website/src/env.d.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 50383 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- working directory and candidate files ---'
pwd
printf '%s\n' 'Tracked env/global declarations:'
git ls-files | grep -E '(^|/)(env|global)\.d\.ts$' || true
printf '%s\n' 'AnyMockProcedure occurrences with file paths:'
rg -l '\bAnyMockProcedure\b' --glob '!node_modules/**' | head -80
printf '%s\n' '--- declaration files ---'
for f in apps/website/src/env.d.ts apps/website/global.d.ts global.d.ts; do
if [ -f "$f" ]; then
echo "FILE: $f"
cat -n "$f" | sed -n '1,30p'
fi
done
printf '%s\n' '--- requestDownloadLink declaration and implementation ---'
rg -n -C 8 'requestDownloadLink|function requestDownloadLink|const requestDownloadLink' apps/website/src
printf '%s\n' '--- target test references and package TypeScript settings ---'
rg -n -C 4 'mockSubmit|requestDownloadLink|AnyMockProcedure' apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts apps/website/src/components/product/local/MobileDownloadEmailForm.vue apps/website/src/scripts/customerio* apps/website/tsconfig*.json 2>/dev/null || trueRepository: Comfy-Org/ComfyUI_frontend Length of output: 392 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- repository root entries ---'
ls -ld apps apps/website apps/website/src 2>&1 || true
printf '%s\n' '--- declaration contents ---'
for f in apps/website/src/env.d.ts global.d.ts; do
echo "FILE: $f"
if [ -f "$f" ]; then cat -n "$f" | sed -n '1,30p'; else echo 'missing'; fi
done
printf '%s\n' '--- exact target files ---'
for f in apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts apps/website/src/components/product/local/MobileDownloadEmailForm.vue; do
echo "FILE: $f"
if [ -f "$f" ]; then cat -n "$f" | sed -n '1,180p'; else echo 'missing'; fi
done
printf '%s\n' '--- customerio files ---'
find apps/website/src -maxdepth 4 -iname '*customerio*' -print 2>/dev/null
grep -RIn -E 'requestDownloadLink|AnyMockProcedure' apps/website/src/scripts apps/website/src/components/product/local 2>/dev/null | head -120Repository: Comfy-Org/ComfyUI_frontend Length of output: 16713 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- focused diff ---'
git diff -- apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts apps/website/src/env.d.ts global.d.ts
printf '%s\n' '--- requestDownloadLink implementation ---'
cat -n apps/website/src/scripts/customerio.ts | sed -n '1,75p'
printf '%s\n' '--- Vitest configuration and mock typing examples ---'
rg -n -C 3 '"vitest"|"vitest":|vi\.fn<.*requestDownloadLink|vi\.fn<typeof|MockedFunction' package.json apps/website/package.json pnpm-lock.yaml apps/website/src --glob '*.ts' | head -180
printf '%s\n' '--- read-only invariant probe ---'
python3 - <<'PY'
from pathlib import Path
import re
env = Path('apps/website/src/env.d.ts').read_text()
global_decl = Path('global.d.ts').read_text()
test = Path('apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts').read_text()
customerio = Path('apps/website/src/scripts/customerio.ts').read_text()
aliases = re.findall(r'type\s+AnyMockProcedure\s*=\s*([^\n]+)', env + '\n' + global_decl)
target = re.search(r'mockSubmit:\s*vi\.fn<([^>]+)>\((async\s*\(\)\s*=>\s*undefined)\)', test)
signature = re.search(
r'export\s+async\s+function\s+requestDownloadLink\s*'
r'\(([^)]*)\)\s*\{',
customerio,
)
print(f'AnyMockProcedure declarations: {len(aliases)}')
for i, alias in enumerate(aliases, 1):
print(f' {i}: {alias}')
print(f'target mock generic: {target.group(1) if target else "not found"}')
print(f'target mock implementation: {target.group(2) if target else "not found"}')
print(f'requestDownloadLink parameters: {signature.group(1) if signature else "not found"}')
print(f'AnyMockProcedure contains any: {any("any" in alias for alias in aliases)}')
PYRepository: Comfy-Org/ComfyUI_frontend Length of output: 3116 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- TypeScript project configuration ---'
find apps/website -maxdepth 2 -name 'tsconfig*.json' -print -exec sh -c 'echo "FILE: $1"; cat -n "$1" | sed -n "1,180p"' sh {} \;
printf '%s\n' '--- guidance references to AnyMockProcedure and mock typing ---'
grep -RIn -E 'AnyMockProcedure|vi\.fn|mock' docs/guidance/typescript.md .agents/checks/test-quality.md docs/guidance/vitest.md docs/testing/vitest-patterns.md | head -160
printf '%s\n' '--- compact usage inventory ---'
python3 - <<'PY'
from pathlib import Path
import re
root = Path('apps/website/src')
files = sorted(root.rglob('*.ts'))
matches = []
for path in files:
lines = path.read_text(errors='replace').splitlines()
for i, line in enumerate(lines):
if 'vi.fn<AnyMockProcedure>' in line:
context = ' '.join(x.strip() for x in lines[i:i+4])
matches.append((str(path), i + 1, context))
print(f'usages: {len(matches)}')
for path, line, context in matches:
print(f'{path}:{line}: {context}')
PYRepository: Comfy-Org/ComfyUI_frontend Length of output: 5200 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- root TypeScript configuration ---'
for f in tsconfig.json tsconfig.*.json; do
if [ -f "$f" ]; then
echo "FILE: $f"
cat -n "$f" | sed -n '1,160p'
fi
done
printf '%s\n' '--- repository source layout ---'
git ls-files | grep -E '(^|/)src/|^apps/' | head -120
printf '%s\n' '--- declaration references in configs ---'
grep -RIn -E 'global\.d\.ts|env\.d\.ts|apps/website|include|exclude' --include='tsconfig*.json' --include='astro.config.*' . | head -160Repository: Comfy-Org/ComfyUI_frontend Length of output: 30096 Use the
🤖 Prompt for AI AgentsSources: Coding guidelines, Path instructions |
||
| })) | ||
|
|
||
| vi.mock('../../../scripts/customerio', () => ({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| /// <reference path="../.astro/types.d.ts" /> | ||
|
|
||
| /** Matches the un narrowed callable shape of a fresh `vi.fn()`. */ | ||
| type AnyMockProcedure = (...args: any[]) => any |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ declare const __ALGOLIA_APP_ID__: string | |
| declare const __ALGOLIA_API_KEY__: string | ||
| declare const __USE_PROD_CONFIG__: boolean | ||
|
|
||
| /** Matches the un narrowed callable shape of a fresh `vi.fn()`. */ | ||
| type AnyMockProcedure = (...args: any[]) => any | ||
|
Comment on lines
+8
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- tracked candidate files ---'
git ls-files | rg '(^|/)(global\.d\.ts|test-mocks\.d\.ts|env\.d\.ts|typescript\.md)$|docs/guidance/typescript\.md'
printf '%s\n' '--- declaration files ---'
for f in global.d.ts apps/desktop-ui/src/test-mocks.d.ts apps/website/src/env.d.ts docs/guidance/typescript.md; do
if [ -f "$f" ]; then
printf '\n### %s\n' "$f"
cat -n "$f"
fi
done
printf '%s\n' '--- AnyMockProcedure references ---'
rg -n -C 4 'AnyMockProcedure|vi\.fn|MockProcedure' --glob '*.ts' --glob '*.tsx' --glob '*.vue' --glob '*.json' .Repository: Comfy-Org/ComfyUI_frontend Length of output: 50383 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- exact tracked declarations and guidance ---'
git ls-files | rg '(^|/)(global\.d\.ts|test-mocks\.d\.ts|env\.d\.ts)$|docs/guidance/typescript\.md' | while IFS= read -r f; do
printf '\n### %s\n' "$f"
wc -l "$f"
cat -n "$f"
done
printf '%s\n' '--- exact alias references ---'
rg -n -C 2 '\bAnyMockProcedure\b' --glob '*.ts' --glob '*.tsx' --glob '*.vue' . | head -n 500
printf '%s\n' '--- TypeScript guidance references ---'
rg -n -C 3 'AnyMockProcedure|any|vi\.fn|mock' docs/guidance/typescript.md
printf '%s\n' '--- Vitest and TypeScript configuration files ---'
git ls-files | rg '(^|/)(package\.json|tsconfig[^/]*\.json|vitest[^/]*\.(ts|js|json))$' | head -n 100Repository: Comfy-Org/ComfyUI_frontend Length of output: 50384 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- Vitest version declarations ---'
rg -n -C 2 '"vitest"|vitest@|vitest/' package.json package-lock.json pnpm-lock.yaml yarn.lock bun.lockb apps packages 2>/dev/null | head -n 200 || true
printf '%s\n' '--- existing callable aliases and safe vi.fn generic patterns ---'
rg -n -C 2 'type [A-Za-z0-9_]*(Procedure|Function|Mock)|interface [A-Za-z0-9_]*(Procedure|Function|Mock)|vi\.fn<\(' --glob '*.ts' --glob '*.tsx' --glob '*.vue' --glob '*.d.ts' . | head -n 500
printf '%s\n' '--- TypeScript configuration references to declarations ---'
rg -n -C 3 'global\.d\.ts|test-mocks\.d\.ts|env\.d\.ts|types|include|exclude' --glob 'tsconfig*.json' --glob '*.config.ts' --glob '*.config.js' . | head -n 400
printf '%s\n' '--- installed standalone tooling ---'
command -v tsc || true
tsc --version 2>/dev/null || true
command -v node || true
node --version 2>/dev/null || trueRepository: Comfy-Org/ComfyUI_frontend Length of output: 50382 🌐 Web query:
💡 Result: In Vitest 4.1.10, the vi.fn function utilizes a simplified generic type signature designed to improve TypeScript ergonomics [1]. Historically, vi.fn required separate generic arguments for parameters and return types (e.g., vi.fn<TArgs, TReturn>). This has been updated to accept a single function type directly [1]. Implementation Signature: The signature is defined as: function fn<T extends Procedure | Constructable>(fn?: T): Mock Usage Patterns: 1. Typing with a specific function signature: If you want to create a mock that matches an existing function signature, pass the function type directly as a generic [1]: const add = (x: number, y: number): number => x + y; const mockAdd = vi.fn; 2. Using the Mock type explicitly: You can also apply the type to the Mock variable itself [1]: const mockAdd: Mock = vi.fn; Key Points for TypeScript Users: - Avoid older types like MockedFunction if possible, as the library now recommends using the Mock or MockInstance types for better compatibility [2]. - If you call vi.fn without any arguments, it defaults to a mock that accepts any arguments and returns unknown [3]. - When using mockImplementation, the implementation must be compatible with the function signature inferred from the initial call to vi.fn or the generic type provided [3]. This simplified approach aligns Vitest more closely with modern TypeScript standards and reduces the verbosity previously associated with mocking complex function signatures [1][3]. Citations:
Replace
📍 Affects 3 files
🤖 Prompt for AI AgentsSources: Coding guidelines, Path instructions |
||
|
|
||
| interface ImpactQueueFunction { | ||
| (...args: unknown[]): void | ||
| a?: unknown[][] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Comfy-Org/ComfyUI_frontend
Length of output: 283
🏁 Script executed:
Repository: Comfy-Org/ComfyUI_frontend
Length of output: 18927
🌐 Web query:
Vitest vi.fn no implementation returns undefined mock function documentation💡 Result:
When you create a mock function using vi.fn without providing an implementation, it returns undefined by default when invoked [1][2]. The official Vitest documentation states that vi.fn creates a spy on a function or, if no function is provided, a new mock function [2][3]. Because it tracks call arguments and instances without an associated implementation by default, any call to this mock function will result in an undefined return value [1][2]. You can control the return value of such a mock function using methods like.mockReturnValue(value) or.mockImplementation( => value) [4][1]. If you want a default return value other than undefined, you can also provide it directly during initialization with vi.fn( => defaultValue) [4][5]. Top results: [4][1][2]
Citations:
🏁 Script executed:
Repository: Comfy-Org/ComfyUI_frontend
Length of output: 5034
🏁 Script executed:
Repository: Comfy-Org/ComfyUI_frontend
Length of output: 224
Preserve the async default for
installRequirements.vi.fn<[], Promise<void>>()returnsundefinedbefore a test configures it. Initialize it with an async implementation to match itsPromise<void>type.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions