Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Sep 25, 2025

Summary by CodeRabbit

  • Chores

    • Added Vitest to development tooling for improved test running.
  • Tests

    • Migrated test imports and helpers to align with TypeScript sources.
    • Updated test paths to new mock plugin locations.
    • Skipped a failing/flaky test to stabilize the suite.
    • Introduced Vitest imports and minor formatting adjustments.
  • Documentation

    • Updated installation instructions to use the scoped mock package name (@eggjs/mock) in both English and Chinese READMEs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Dev tooling adds Vitest to cluster package devDependencies. Tests adjust imports to TypeScript sources, update mock paths to plugins/mock, and skip one cluster test. Documentation updates replace egg-mock with @eggjs/mock in both English and Chinese READMEs. No runtime code or public API changes.

Changes

Cohort / File(s) Summary of changes
Dev tooling (cluster)
packages/cluster/package.json
Added vitest to devDependencies. No changes to scripts, exports, or runtime configuration.
Test updates (paths, TS imports, skip)
packages/cluster/test/app_worker.test.ts, packages/core/test/loader/file_loader.test.ts, packages/utils/test/import.test.ts
- Skipped a test in cluster (itit.skip).
- Switched imports to .ts helpers/sources.
- Updated test paths from mock to plugins/mock.
- Added Vitest imports where needed.
Docs (mock package rename)
plugins/mock/README.md, plugins/mock/README.zh_CN.md
Replaced installation reference egg-mock with @eggjs/mock. No other content changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit taps keys with a testing delight,
Vitest hops in, the suites feel light.
One flaky trail? We mark it “skip,”
Then bound to plugins/mock we zip.
Docs get a shiny scoped new stock—
@eggjs/mock, tick-tock, rock! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "chore: move mock to plugins" clearly and concisely summarizes the primary change of relocating the mock package to the plugins directory and updating associated tests and documentation. It follows conventional commit conventions by using a “chore” prefix and imperative phrasing. The title is specific enough for team members to understand the core modification without listing every minor update. It accurately reflects the most important change in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch move-mock-to-plugin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: c7a910d
Status:🚫  Build failed.

View logs

@cloudflare-workers-and-pages
Copy link

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: c7a910d
Status:🚫  Build failed.

View logs

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fengmk2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring effort by relocating the mock package from its previous location within packages to a dedicated plugins directory. This move aims to enhance the project's modularity and organization, clearly separating core components from pluggable functionalities. The changes also include necessary updates to test file paths, import statements, and documentation to ensure consistency and functionality within the new structure.

Highlights

  • Package Relocation: The entire mock package has been moved from the packages/mock directory to a new plugins/mock directory, signifying a structural reorganization.
  • Dependency Update: The packages/cluster module now includes vitest as a development dependency.
  • Test Adjustments: Several test files across packages/cluster, packages/core, and packages/utils have been updated to reflect the new mock package location and import paths. One specific test case in packages/cluster/test/app_worker.test.ts has been temporarily skipped.
  • Documentation Update: The README.md files for the mock package have been updated to reflect the new package name @eggjs/mock in installation instructions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.84%. Comparing base (cd8e398) to head (c7a910d).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5537      +/-   ##
==========================================
- Coverage   75.87%   75.84%   -0.04%     
==========================================
  Files         114      114              
  Lines        5770     5770              
  Branches     1152     1149       -3     
==========================================
- Hits         4378     4376       -2     
- Misses       1212     1214       +2     
  Partials      180      180              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/mock/README.zh_CN.md (1)

13-15: Update lingering egg-mock references
Replace all imports and mentions of egg-mock (e.g. require('egg-mock/bootstrap'), docs links) with the new @eggjs/mock package across site/docs/tutorials, docs/core/unittest, quickstart guides, and create-egg templates.

🧹 Nitpick comments (7)
packages/utils/test/import.test.ts (2)

11-15: Prefer node:assert over Vitest expect in Vitest suites.
Repo convention uses built-in assert. Suggest replacing expect here.

Apply this diff:

-    it('should be true', () => {
-      expect(isESM).toBe(true);
-    });
+    it('should be true', () => {
+      assert.equal(isESM, true);
+    });

186-193: Use node:assert for assertions (consistency).
Replace toBeDefined with assert.ok.

-      expect(obj.Agent).toBeDefined();
+      assert.ok(obj.Agent);
packages/cluster/test/app_worker.test.ts (1)

318-338: Make the skip actionable (reason/issue link) or guard with skipIf.
Add a short comment or use it.skipIf with a condition, mirroring the suite-level skip rationale.

-    it.skip('should refork when app_worker exit', async () => {
+    // TODO: flaky on CI (refork race). Re-enable after stabilization. Track: <issue-url>
+    it.skip('should refork when app_worker exit', async () => {
packages/core/test/loader/file_loader.test.ts (1)

14-16: Test title no longer matches what’s exercised.
You’re passing a concrete src directory, not resolving via package.json exports. Either rename the test or switch to an exports-resolved path.

Rename for clarity:

-  it('should load files with package.json#exports', async () => {
+  it('should load files from plugin sources (mock middleware)', async () => {
plugins/mock/README.md (3)

14-15: Update package name in description.
Use @eggjs/mock instead of egg-mock.

-`egg-mock` inherits all APIs from [node_modules/mm](https://github.com/node-modules/mm), offering more flexibility.
+`@eggjs/mock` inherits all APIs from [node_modules/mm](https://github.com/node-modules/mm), offering more flexibility.

422-422: Typo: “alse” → “also”.

-You can alse mock agent.httpclient
+You can also mock agent.httpclient

487-489: Doc consistency: replace egg-mock with @eggjs/mock.

-And if you use mm.app to bootstrap app, you can manually call setGetAppCallback,
-then egg-mock will inject ctx for each test case.
+And if you use mm.app to bootstrap app, you can manually call setGetAppCallback,
+then @eggjs/mock will inject ctx for each test case.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd8e398 and c7a910d.

⛔ Files ignored due to path filters (4)
  • plugins/mock/test/__snapshots__/app_proxy.test.ts.snap is excluded by !**/*.snap
  • plugins/mock/test/fixtures/yadan_app/node_modules/yadan/config/config.default.js is excluded by !**/node_modules/**
  • plugins/mock/test/fixtures/yadan_app/node_modules/yadan/index.js is excluded by !**/node_modules/**
  • plugins/mock/test/fixtures/yadan_app/node_modules/yadan/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (6)
  • packages/cluster/package.json (1 hunks)
  • packages/cluster/test/app_worker.test.ts (1 hunks)
  • packages/core/test/loader/file_loader.test.ts (1 hunks)
  • packages/utils/test/import.test.ts (2 hunks)
  • plugins/mock/README.md (1 hunks)
  • plugins/mock/README.zh_CN.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
packages/*/package.json

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use "workspace:*" for internal workspace dependencies in package.json

Files:

  • packages/cluster/package.json
{packages,plugins,tools}/**/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

{packages,plugins,tools}/**/package.json: Individual packages must reference external dependencies via "catalog:" from pnpm-workspace.yaml
Use "workspace:*" for internal monorepo dependencies between packages

Files:

  • packages/cluster/package.json
packages/**/test/**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

packages/**/test/**/*.test.ts: Name test files as test/**/*.test.ts and run them with Vitest
Use import { describe, it } from 'vitest' in tests
Use Node.js built-in assert module for test assertions

Files:

  • packages/cluster/test/app_worker.test.ts
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
{packages,plugins}/**/test/**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

{packages,plugins}/**/test/**/*.test.ts: Vitest test files should follow the naming pattern test/**/*.test.ts and import from vitest
Use Node.js built-in assert for assertions in Vitest tests

Files:

  • packages/cluster/test/app_worker.test.ts
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.ts: Prefer TypeScript and ESM: write sources and exports in .ts (ESM-first) rather than CommonJS
Use two-space indentation, trailing commas, and semicolons (Prettier/oxlint defaults)
Name files in lowercase with hyphens (e.g., loader-context.ts)
Name classes in PascalCase
Name functions and variables in camelCase
Re-export types thoughtfully to keep the public API stable

Files:

  • packages/cluster/test/app_worker.test.ts
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
**/test/**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/test/**/*.test.ts: Place test suites following Vitest discovery: /test//*.test.ts
Mirror the repository test pattern when adding new suites

Files:

  • packages/cluster/test/app_worker.test.ts
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/vitest.config.ts : Each non-CLI package must include a vitest.config.ts for test configuration
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/test/**/*.test.ts : egg-bin (CLI tool) tests must use Mocha
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/test/**/*.test.ts : Use Node.js built-in assert for assertions in Vitest tests
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/**/test/**/*.test.ts : Use import { describe, it } from 'vitest' in tests
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/**/test/**/*.test.ts : Name test files as test/**/*.test.ts and run them with Vitest
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/test/**/*.test.ts : Vitest test files should follow the naming pattern test/**/*.test.ts and import from vitest
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/vitest.config.ts : Each non-CLI package must include a vitest.config.ts for test configuration

Applied to files:

  • packages/cluster/package.json
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/test/**/*.test.ts : Use Node.js built-in assert for assertions in Vitest tests

Applied to files:

  • packages/cluster/package.json
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to {packages,plugins}/**/test/**/*.test.ts : Vitest test files should follow the naming pattern test/**/*.test.ts and import from vitest

Applied to files:

  • packages/cluster/package.json
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/**/test/**/*.test.ts : Use import { describe, it } from 'vitest' in tests

Applied to files:

  • packages/cluster/package.json
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/**/test/**/*.test.ts : Name test files as test/**/*.test.ts and run them with Vitest

Applied to files:

  • packages/cluster/package.json
  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-15T01:56:16.297Z
Learnt from: CR
PR: eggjs/egg#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-15T01:56:16.297Z
Learning: Applies to tools/egg-bin/test/**/*.test.ts : egg-bin (CLI tool) tests must use Mocha

Applied to files:

  • plugins/mock/README.zh_CN.md
  • plugins/mock/README.md
📚 Learning: 2025-09-18T07:56:17.417Z
Learnt from: CR
PR: eggjs/egg#0
File: AGENTS.md:0-0
Timestamp: 2025-09-18T07:56:17.417Z
Learning: Applies to **/test/**/*.test.ts : Place test suites following Vitest discovery: **/test/**/*.test.ts

Applied to files:

  • packages/utils/test/import.test.ts
📚 Learning: 2025-09-14T08:41:30.618Z
Learnt from: CR
PR: eggjs/egg#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-14T08:41:30.618Z
Learning: Applies to packages/**/test/**/*.test.ts : Use Node.js built-in assert module for test assertions

Applied to files:

  • packages/utils/test/import.test.ts
  • packages/core/test/loader/file_loader.test.ts
📚 Learning: 2025-09-18T07:56:17.417Z
Learnt from: CR
PR: eggjs/egg#0
File: AGENTS.md:0-0
Timestamp: 2025-09-18T07:56:17.417Z
Learning: Applies to **/test/**/*.test.ts : Mirror the repository test pattern when adding new suites

Applied to files:

  • packages/utils/test/import.test.ts
🧬 Code graph analysis (2)
packages/utils/test/import.test.ts (1)
packages/utils/src/import.ts (1)
  • importResolve (275-361)
packages/core/test/loader/file_loader.test.ts (1)
packages/core/test/helper.ts (1)
  • getFilepath (17-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Test egg-bin (ubuntu-latest, 24)
  • GitHub Check: Test egg-bin (macos-latest, 22)
  • GitHub Check: Test egg-bin (ubuntu-latest, 22)
  • GitHub Check: Test egg-bin (windows-latest, 24)
  • GitHub Check: Test egg-bin (windows-latest, 22)
  • GitHub Check: Test packages (ubuntu-latest, 22)
  • GitHub Check: Test egg-bin (macos-latest, 24)
  • GitHub Check: Test packages (windows-latest, 24)
  • GitHub Check: Test packages (ubuntu-latest, 24)
  • GitHub Check: Test packages (macos-latest, 24)
  • GitHub Check: Test packages (macos-latest, 22)
  • GitHub Check: Test packages (windows-latest, 22)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
plugins/mock/README.zh_CN.md (1)

19-19: LGTM: install command now points to @eggjs/mock.

packages/utils/test/import.test.ts (2)

8-8: LGTM: helper import switched to .ts to match TS sources.


20-22: Confirm intent: resolving plugin source path under development.
Asserting resolve('plugins/mock/app') -> 'plugins/mock/src/app.ts' is correct for dev. Ensure this stays accurate if plugin build layout changes.

packages/core/test/loader/file_loader.test.ts (1)

8-9: LGTM: tests now import TS sources and helpers.

plugins/mock/README.md (1)

19-19: LGTM: install command updated to @eggjs/mock.

packages/cluster/package.json (2)

74-76: LGTM: add vitest to devDependencies for this package.
Matches test script (“vitest run”) and test usage.


24-30: All non-CLI packages have vitest.config.ts
packages/cluster/vitest.config.ts exists, and no root packages under packages/ or plugins/ are missing a config (the only “missing” paths were test fixture apps, which don’t require their own vitest.config.ts).

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot 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

This pull request primarily involves refactoring by moving the mock package into the plugins directory. The changes are mostly path updates across various files, which appear to be correct and consistent with the move. The dependencies have been updated to include vitest, and test imports now correctly reference TypeScript source files. Documentation has also been updated to reflect the new scoped package name @eggjs/mock.

I have one suggestion regarding a skipped test to ensure it's tracked for future resolution. Overall, this is a solid refactoring effort.

});

it('should refork when app_worker exit', async () => {
it.skip('should refork when app_worker exit', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While skipping a flaky test is a good temporary measure to stabilize the build, it's crucial to ensure it doesn't get forgotten. I've added a // TODO: comment to track the fix for this test. Please replace #XYZ with the actual issue number if one exists, or create one.

Suggested change
it.skip('should refork when app_worker exit', async () => {
// TODO: This test is flaky and has been temporarily skipped. See issue #XYZ for details.
it.skip('should refork when app_worker exit', async () => {

@fengmk2 fengmk2 merged commit 55bb584 into next Sep 25, 2025
22 of 25 checks passed
@fengmk2 fengmk2 deleted the move-mock-to-plugin branch September 25, 2025 08:53
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.

1 participant