Comfy-Org / Comfy-Org/ComfyUI_frontend

Document that global Vitest fake timers invalidate timing measurements

Open
#15,782 0 comments 0 reactions 1 assignee Claimed by @christian-byrne View on GitHub
agent-ok area:testing documentation
Dominant language
TypeScript
Stars
2k
Forks
704
Avg merge
1d 8h
Merged PRs (30d)
512

Description

## Problem / Goal

`vitest.timer.setup.ts` calls `vi.useFakeTimers()` in a global `beforeEach`. In this test environment, that fakes both `performance.now()` and `process.hrtime.bigint()`. A benchmark can therefore report a plausible constant duration of zero while the test remains green.

The repository's Vitest guidance does not mention this. The current behavior is visible on `main` at `9ea9802c42ad3f525fea98a253e692a8715184d2`:

```ts
beforeEach(() => {
// ...
vi.useFakeTimers()
})
```

The goal is to prevent invalid benchmark results without changing the global timer setup.

## Proposed Solution

Update `docs/guidance/vitest.md` to state that timing or benchmark tests must:

1. Call `vi.useRealTimers()` before taking timing samples.
2. Include a known-nonzero control so a frozen timing instrument cannot silently pass.
3. Restore or otherwise respect the repository's existing timer lifecycle after the test.

Keep the guidance concise and place it near the running-tests or test-quality guidance. Do not redesign the global fake-timer policy, add a benchmark, or change unrelated guidance.

## Acceptance Criteria

- `docs/guidance/vitest.md` names both affected clocks: `performance.now()` and `process.hrtime.bigint()`.
- It explains the silent-zero failure mode and the `vi.useRealTimers()` remedy.
- It recommends a known-nonzero control for performance measurements.
- No production or test setup behavior changes.
- `pnpm format:check` passes.

## Verification

```bash
rg -n 'useFakeTimers|useRealTimers|performance\.now|hrtime' vitest.timer.setup.ts docs/guidance/vitest.md
pnpm format:check
```

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.