Skip to content

fix(test): codetool test timeout#12862

Merged
kangfenmao merged 2 commits intomainfrom
fix/code-tool-test-timeout
Feb 12, 2026
Merged

fix(test): codetool test timeout#12862
kangfenmao merged 2 commits intomainfrom
fix/code-tool-test-timeout

Conversation

@GeorgeDong32
Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 commented Feb 10, 2026

What this PR does

Before this PR:

  • Tests used a dynamic import for generateToolEnvironment which caused a test timeout and an import-order warning.

After this PR:

  • Replaced the dynamic import with a static import to resolve the test timeout.
  • Reordered imports in CodeToolsPage unit test: moved generateToolEnvironment import below test framework and type imports to satisfy linting/import-order rules and preserve mock setup.

Fixes #

Why we need it and why it was done in this way

The dynamic import caused test execution to hang/time out. Using a static import and adjusting import order both fixes the timeout and satisfies linting rules while keeping the existing mock setup intact. The test now only cost 4ms compared to 10s before modify.

Checklist

  • PR: The PR description is expressive enough and will help future contributors
  • Code: Write code that humans can understand and keep it simple
  • Refactor: Left the code cleaner than found
  • Documentation: No user-guide update required

Release note

Fix test timeout and import-order warning by replacing dynamic import with static import and reordering imports in CodeToolsPage unit test.

@GeorgeDong32 GeorgeDong32 force-pushed the fix/code-tool-test-timeout branch from a11f3e2 to 41d3dcd Compare February 10, 2026 15:24
@GeorgeDong32 GeorgeDong32 changed the title fix/code-tool-test-timeout fix(test): codetool test timeout Feb 10, 2026
@GeorgeDong32 GeorgeDong32 force-pushed the fix/code-tool-test-timeout branch 2 times, most recently from e3070fe to fdfff0e Compare February 11, 2026 15:51
Move generateToolEnvironment import below test framework and type imports
to satisfy linting/order rules and keep import groups consistent. This fixes
an import-order warning in the index.test.ts file and preserves the mock
setup for CodeToolsPage.
@GeorgeDong32 GeorgeDong32 force-pushed the fix/code-tool-test-timeout branch from fdfff0e to 4889d07 Compare February 12, 2026 12:08
EurFelux

This comment was marked as duplicate.

Copy link
Copy Markdown
Collaborator

@EurFelux EurFelux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: fix(test): codetool test timeout

Overview

This PR replaces dynamic await import('../index') calls within each test case with a single static import { generateToolEnvironment } from '../index' at the top of the file. This resolves a test timeout issue (10s → 4ms) and eliminates an import-order lint warning.

What's Good

  • Root cause is correct: Dynamic imports inside test cases cause Vitest to re-evaluate the module (and all its transitive dependencies) on every invocation, which explains the timeout. A static import lets Vitest resolve the module once and cache it.
  • Mock setup remains valid: All vi.mock() calls are still hoisted above the static import by Vitest's transform, so mock isolation is preserved.
  • Tests become synchronous: Removing async/await from test cases that don't need it is a clean improvement — it simplifies the test signatures and makes failures easier to diagnose.
  • CI passes: All checks (basic-checks, general-test, render-test) are green.
  • Minimal diff: +11 / -17 lines — focused and easy to review.

Minor Observations

  1. Comment wording change (line 5): the original "which is the default export" reads slightly better grammatically than "which is default export", but this is purely cosmetic and not worth blocking.

Risk Assessment

  • Low risk — this is a test-only change with no impact on production code.
  • The mock hoisting behavior in Vitest is well-documented and reliable for static imports, so this pattern is safe.

Verdict

Clean, focused fix that correctly addresses the root cause. LGTM.

@kangfenmao kangfenmao merged commit 3e4faf2 into main Feb 12, 2026
10 checks passed
@kangfenmao kangfenmao deleted the fix/code-tool-test-timeout branch February 12, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants