Skip to content

Next#4741

Merged
weareoutman merged 114 commits into
v3from
next
Jun 24, 2025
Merged

Next#4741
weareoutman merged 114 commits into
v3from
next

Conversation

@weareoutman

@weareoutman weareoutman commented Jun 24, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • 新功能

    • 增加依赖安装后自动应用补丁的支持。
  • 修复与优化

    • 提升资源体积检测阈值,允许更大的资源文件。
    • 依赖项全面升级,包括 Babel、Jest、Cypress、TypeScript、Prettier、ESLint 等,提升兼容性和稳定性。
    • Docker 环境升级至更高版本的 Cypress 镜像。
  • 测试

    • 测试断言方式统一升级,采用更明确的 Jest 匹配器,提升测试准确性和可读性。
  • 类型与样式

    • 优化部分类型定义,提升类型系统一致性。
  • 其他

    • 多个包的依赖小幅升级,增强整体安全性和兼容性。

renovate Bot and others added 30 commits March 31, 2025 04:17
chore(deps): Update babel monorepo to ^7.27.0 (next)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
chore(deps): Update dependency body-parser to v2 (next)
chore(deps): Update dependency typescript to ^5.8.3 (next)
chore(deps): Update dependency webpack to ^5.99.5 (next)
chore(deps): Update eslint monorepo to ^9.24.0 (next)
…-middleware-vulnerability

chore(deps): Update dependency http-proxy-middleware to v3.0.5 [SECURITY] (next)
chore(deps): Update dependency webpack to ^5.99.6 (next)
…-env-10.x

chore(deps): Update dependency postcss-preset-env to ^10.1.6 (next)
chore(deps): Update babel monorepo to ^7.27.1 (next)
chore(deps): Update dependency webpack to ^5.99.7 (next)
chore(deps): Update babel monorepo to ^7.27.2 (next)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
chore(deps): Update dependency cssnano to ^7.0.7 (next)
renovate Bot and others added 23 commits June 10, 2025 09:23
* chore(deps): Update dependency core-js to ^3.43.0

* chore(): increase size limit

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Shenwei Wang <wangshenwei@qq.com>
…int-monorepo

chore(deps): Update dependency typescript-eslint to ^8.34.0 (next)
…-env-10.x

chore(deps): Update dependency postcss-preset-env to ^10.2.2 (next)
chore(deps): Update postcss packages (next)
chore(deps): Update dependency prettier to ^3.6.0 (next)
BREAKING CHANGE: upgrade jest to v30
…kages

chore(deps): Update jest packages to v30 (next) (major)
…int-monorepo

chore(deps): Update dependency typescript-eslint to ^8.35.0 (next)
chore(deps): Update eslint monorepo to ^9.29.0 (next)
@coderabbitai

coderabbitai Bot commented Jun 24, 2025

Copy link
Copy Markdown

Walkthrough

本次变更主要聚焦于依赖包的升级、测试代码的 Jest 断言方法规范化,以及部分类型声明和导出类型签名的调整。涉及大量 package.json 依赖版本提升、Jest 测试断言从 toBeCalled* 系列统一替换为 toHaveBeenCalled* 系列、部分错误断言由 toThrowError 改为 toThrow,以及少量类型声明、函数签名和枚举声明的简化或重命名。此外,还包括 Docker 镜像版本更新、jsdom 补丁调整 window.location 属性的 configurable 属性等。

Changes

文件/路径分组 变更简述
cypress/e2e/size-check.spec.js 资源体积限制测试断言的最大值提升(总资源从 320,000 到 330,000 字节,JS 资源从 300,000 到 310,000 字节)。
docker-compose.yml e2e 服务的 Cypress 镜像版本由 14.1.0 升级到 14.4.1。
package.json 新增 postinstall 脚本,添加 patch-package 相关依赖,大量 devDependencies 及 resolutions 升级,lint-staged 配置微调。
.../babel-preset-next/package.json
.../brick-container/package.json
.../build-next-bricks/package.json
.../build-next-libs/package.json
.../cook/package.json
.../create-api-sdk/package.json
.../doc-helpers/package.json
.../brick-playground/package.json
.../eslint-config-next/package.json
.../runtime/package.json
.../test-next/package.json
.../webpack/package.json
多个 package.json 升级依赖版本(Babel、Jest、TypeScript、Webpack、Prettier、ESLint、第三方库等),部分 peerDependencies/description 字段调整。
.../brick-container/src/.spec.ts
.../cook/src/
.spec.ts
.../create-api-sdk/src/.spec.ts
.../easyops-runtime/src/**/
.spec.ts
.../element/src/NextElement.spec.ts
.../http/src/http.spec.ts
.../loader/src/.spec.ts
.../react-element/src/
.spec.tsx
.../react-runtime/src//*.spec.ts[x]
.../runtime/src/
/.spec.ts[x]
.../utils/src/**/
.spec.ts
大量测试文件将 Jest 断言从 toBeCalled*/toBeCalledWith/toBeCalledTimes/not.toBeCalled 等统一替换为 toHaveBeenCalled*/toHaveBeenCalledWith/toHaveBeenCalledTimes/not.toHaveBeenCalled,部分 toThrowError 改为 toThrow,个别测试对错误消息或快照内容做了细化。
packages/react-element/src/wrapBrick.tsx 类型别名 WrappedBrickWrappedBrickWithEventsMap 签名调整,wrapLocalBrick/wrapBrick 泛型参数重命名(E→_E),forwardRef 泛型及 props 类型简化,移除多余的 children 类型注解。
packages/yo/src/templates/brick/i18n.ts 枚举 K 由带注释成员变为空枚举,注释移至枚举外部。
packages/test-next/src/run.js Jest 导入方式由默认改为具名(import { run }),调用方式相应调整。
patches/jsdom+26.1.0.patch jsdom 的 Window.js 内 window.location 属性 configurable 属性由 false 改为 true。

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

cypress/e2e/size-check.spec.js

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

packages/brick-container/src/loadBootstrapData.spec.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

packages/brick-container/src/preview/initialize.spec.ts

Oops! Something went wrong! :(

ESLint: 9.29.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@next-core/eslint-config-next' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

  • 67 others
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov

codecov Bot commented Jun 24, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.26%. Comparing base (e452085) to head (5201307).
Report is 115 commits behind head on v3.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##               v3    #4741   +/-   ##
=======================================
  Coverage   95.26%   95.26%           
=======================================
  Files         209      209           
  Lines        9058     9060    +2     
  Branches     1743     1744    +1     
=======================================
+ Hits         8629     8631    +2     
  Misses        319      319           
  Partials      110      110           
Files with missing lines Coverage Δ
packages/react-element/src/wrapBrick.tsx 100.00% <100.00%> (ø)
🚀 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.

@cypress

cypress Bot commented Jun 24, 2025

Copy link
Copy Markdown

next-core    Run #11449

Run Properties:  status check passed Passed #11449  •  git commit 5201307fb3: Merge pull request #4740 from easyops-cn/renovate/next-eslint-monorepo
Project next-core
Branch Review next
Run status status check passed Passed #11449
Run duration 00m 24s
Commit git commit 5201307fb3: Merge pull request #4740 from easyops-cn/renovate/next-eslint-monorepo
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 16
View all changes introduced in this branch ↗︎

@cypress

cypress Bot commented Jun 24, 2025

Copy link
Copy Markdown

next-core    Run #11451

Run Properties:  status check passed Passed #11451  •  git commit 0eed613e2a ℹ️: Merge 5201307fb3a0eb2d0c929f95c665f650f5eccc03 into e452085933a05133f4b6e536f527...
Project next-core
Branch Review next
Run status status check passed Passed #11451
Run duration 00m 23s
Commit git commit 0eed613e2a ℹ️: Merge 5201307fb3a0eb2d0c929f95c665f650f5eccc03 into e452085933a05133f4b6e536f527...
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 16
View all changes introduced in this branch ↗︎

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🔭 Outside diff range comments (3)
packages/runtime/src/CustomProcessors.spec.ts (1)

11-14: 测试后未清理全局状态,可能导致用例间串扰
customProcessors 在多文件/多用例共享同一实例时,已注册的 processor 会在其他测试中继续存在,导致重复注册或结果非预期。建议:

  1. afterEach 中调用 customProcessors.clear()(若有)或手动删除已注册项。
  2. 或者在此文件独立创建新的 CustomProcessors 实例注入被测模块。

这样可避免并行执行或后续用例出现状态污染。

packages/runtime/src/isStrictMode.spec.ts (1)

4-6: Spy 创建在文件顶层但未重置,后续断言可能失效

console.warn / console.error 的 spy 会在多个用例间共享调用计数。
后续对 “未被调用” 的断言(如第 29、37、47、57 行)在第一次调用后将永远失败,除非 Jest 全局配置了 resetMocks。为了显式可靠,建议手动清理:

 describe("warnAboutStrictMode", () => {
+  beforeEach(() => {
+    jest.clearAllMocks();
+  });
packages/utils/src/storyboard/functions/collectMemberUsageInFunction.spec.ts (1)

49-66: 同样需要清理 console.error Spy 调用计数

本段测试期望 consoleError 被调用一次,但前序用例可能已经产生调用。应在 beforeEach 中执行 consoleError.mockClear() 或全局 jest.clearAllMocks(),以避免计数叠加导致误报。

♻️ Duplicate comments (2)
packages/react-runtime/src/useCurrentApp.spec.ts (1)

74-76: 同上一条关于 spy 污染的问题

此处断言与 44-46 行相同,若未清理 spy,mock.calls[0] 仍可能指向上一用例。请参考前述修改。

packages/utils/src/storyboard/functions/collectMemberUsageInFunction.spec.ts (1)

98-111: “未被调用” 断言依赖前序用例状态,需重置 Spy

第 110 行断言 consoleError 未被调用,同样受前序用例影响。请参考上方建议添加重置逻辑。

🧹 Nitpick comments (17)
packages/react-runtime/src/useProvider/useProvider.spec.tsx (1)

138-138: 建议使用 toHaveBeenCalledTimes(1) 提高断言严格度

toHaveBeenCalled() 只能证明函数被调用过,但无法保证调用次数。
如果期望只调用一次,改用 toHaveBeenCalledTimes(1) 能避免误把多次调用视为通过。

-expect(onError).toHaveBeenCalled();
+expect(onError).toHaveBeenCalledTimes(1);
packages/utils/src/general/deepFreeze.spec.ts (1)

36-40: delete 操作在测试中触发 Biome 报警,可考虑局部禁用或改用赋值 undefined

Biome 对 delete 的性能警告虽然对单元测试影响不大,但持续出现会增加噪音。建议两种方案二选一:

-      delete (frozen as Partial<typeof object>).string;
+      // biome-ignore lint/performance/noDelete -- acceptable in unit tests
+      delete (frozen as Partial<typeof object>).string;

-      delete (frozen as Partial<typeof object>).string;
+      (frozen as Partial<typeof object>).string = undefined;

这样既能消除 linter 警告,也保持测试意图清晰。

Also applies to: 52-55

packages/runtime/src/CustomProcessors.spec.ts (1)

30-34: 建议断言具体错误信息以提升测试可靠性
toThrow() 仅校验“抛出任意错误”,一旦未来实现改为静默忽略或抛出不同错误类型,测试无法及时发现。
推荐同时断言错误消息或类型,示例:

-}).toThrow();
+}).toThrow(/duplicated processor/i);

这样能确保真正因为“重复注册”而失败。

packages/utils/src/storyboard/expressions/traverse.spec.ts (1)

70-71: 建议改用 expect.objectContaining 以降低引用耦合

当前断言依赖 data 数组的引用完全一致:

expect(visitObject).toHaveBeenCalledWith(data);

traverseStoryboardExpressions 在内部构造了等价但非同引用的数组(例如 Array.from(data)),测试将误判失败。可考虑:

-expect(visitObject).toHaveBeenCalledWith(data);
+expect(visitObject).toHaveBeenCalledWith(expect.objectContaining(data));

这样只校验数组内容,而不强依赖引用。

packages/react-runtime/src/useRouteRender.spec.ts (2)

5-6: 建议在测试结束后恢复 spy,避免对其他测试造成影响

两处 jest.spyOn 在文件顶层创建,会在整个测试运行期间保持活跃。虽然当前文件只有一个测试用例,但养成在 afterAll(或 afterEach)中执行 mockRestore() 的习惯,可防止未来新增测试时出现意外的全局污染。

+afterAll(() => {
+  spyOnAddEventListener.mockRestore();
+  spyOnRemoveEventListener.mockRestore();
+});

30-32: 同时断言调用次数,保证只清理一次监听器

目前仅校验参数一致,未限制调用次数。若实现出现多余的 removeEventListener 调用,此测试仍会通过。建议补充一次性断言来提高健壮性。

+    expect(spyOnRemoveEventListener).toHaveBeenCalledTimes(1);
     expect(spyOnRemoveEventListener).toHaveBeenCalledWith(
       ...spyOnAddEventListener.mock.calls[0]
     );
packages/react-runtime/src/useCurrentTheme.spec.ts (2)

11-13: 在测试结束后还原全局 spy,避免对其他测试造成污染
当前使用 jest.spyOn 挂在 window 上的两个全局方法,但未在测试结束后执行 jest.restoreAllMocks() 或单独对这两个 spy 做 mockRestore()。如果其他测试同样涉及到 addEventListener / removeEventListener,将出现相互干扰的风险。建议在 afterEach 钩子中统一恢复。

+afterEach(() => {
+  jest.restoreAllMocks();
+});

31-34: 补充对 addEventListener 调用次数的断言,提升可读性与健壮性
目前直接使用 spyOnAddEventListener.mock.calls[0] 作为期望参数,若 addEventListener 未被调用会导致 undefined 访问而抛错,但错误信息并不直观。显式断言调用次数可以让失败提示更明确。

-unmount();
-expect(spyOnRemoveEventListener).toHaveBeenCalledWith(
-  ...spyOnAddEventListener.mock.calls[0]
-);
+unmount();
+expect(spyOnAddEventListener).toHaveBeenCalledTimes(1);
+expect(spyOnRemoveEventListener).toHaveBeenCalledWith(
+  ...spyOnAddEventListener.mock.calls[0]
+);
packages/easyops-runtime/src/auth.spec.ts (1)

88-92: 无效的断言仍被注释,导致这部分逻辑未被测试

虽然已将过时的 toBeCalled 替换为 toHaveBeenCalled,但相关 importjest.mock 及两条断言仍被注释,测试对 resetPermissionPreChecks 的调用校验实际并未执行。若该校验对业务行为重要,请取消注释并正确 mock;否则建议删除避免干扰阅读。

建议改动示例:

-// import { resetPermissionPreChecks } from "./internal/checkPermissions.js";
+import { resetPermissionPreChecks } from "./internal/checkPermissions.js";

-// jest.mock("./internal/checkPermissions");
+jest.mock("./internal/checkPermissions");

-    // expect(resetPermissionPreChecks).not.toHaveBeenCalled();
+    expect(resetPermissionPreChecks).not.toHaveBeenCalled();

     logout();

-    // expect(resetPermissionPreChecks).toHaveBeenCalled();
+    expect(resetPermissionPreChecks).toHaveBeenCalled();
packages/utils/src/storyboard/expressions/track.spec.ts (2)

24-26: 考虑同时断言调用次数并恢复 spy

更新 toHaveBeenCalledWith 是正确的,但在多数情况下,最好再断言调用次数并在测试结束后恢复 spy,以避免跨测试的副作用。例如:

 expect(consoleWarn).toHaveBeenCalledWith(
   expect.stringContaining(`no \`CTX\` usage found`)
 );
+expect(consoleWarn).toHaveBeenCalledTimes(1);
+consoleWarn.mockRestore();

这样既保证警告只触发一次,也消除了对后续测试可能造成的影响。


60-62: 同上:断言调用次数并清理 spy

同样地,在这里建议补充调用次数断言并显式恢复 spy:

 expect(consoleWarn).toHaveBeenCalledWith(
   expect.stringContaining(`no "CTX" or "STATE" or "FORM_STATE" usage found`)
 );
+expect(consoleWarn).toHaveBeenCalledTimes(1);
+consoleWarn.mockRestore();

保持测试隔离,避免潜在的污染。

packages/easyops-runtime/src/menu/fetchMenuById.spec.ts (2)

492-497: 建议同时断言调用次数以避免误报

toHaveBeenCalledWith 只能保证至少发生过一次匹配调用,若未来实现里多出额外调用将无法被捕获。可以补充一次 toHaveBeenCalledTimes(2)(或使用 toHaveBeenNthCalledWith)以确保调用次数符合预期。

 expect(preCheckPermissionsForAny).toHaveBeenCalledWith(
   expect.objectContaining({
     useProvider: "my-timeout-provider",
   })
 );
+expect(preCheckPermissionsForAny).toHaveBeenCalledTimes(2);
 expect(preCheckPermissionsForAny).toHaveBeenCalledWith(expect.any(Array));

562-564: 建议在测试结束后恢复 console.error 的 spy

这里只调用 mockReset() 而未恢复原实现,会导致后续测试继续使用 mocked 版本的 console.error,影响日志与断言。
在测试用例末尾或 afterEach 中调用 mockRestore() 更安全:

 expect(consoleError).toHaveBeenCalledTimes(1);
 expect(consoleError).toHaveBeenCalledWith(expect.any(YAMLException));
+consoleError.mockRestore();
packages/yo/src/templates/brick/i18n.ts (1)

18-22: 显式绑定泛型以恢复自动补全

修复 K 后,可将键类型显式传给 getFixedT,IDE 补全更友好:

-export const t = i18n.getFixedT(null, NS);
+export const t = i18n.getFixedT<keyof typeof K>(null, NS);
packages/easyops-runtime/src/websocket/MessageService.spec.ts (1)

55-64: 断言过于具体,未来改动易破坏

这里直接断言 %d1,如果实现层把重连时间改成可配置或指数回退,测试会立刻失效。可以改用 expect.any(Number) 来降低耦合:

-expect(consoleLog).toHaveBeenCalledWith(
-  "WebSocket will reconnect after %d seconds",
-  1
-);
+expect(consoleLog).toHaveBeenCalledWith(
+  "WebSocket will reconnect after %d seconds",
+  expect.any(Number)
+);
packages/easyops-runtime/src/websocket/MessageDispatcher.spec.ts (1)

100-104: 考虑断言调用顺序提升可读性

现在只检查 onMessage 被调用 2 次且参数包含 message/message2,但无法保证先后顺序。若顺序很重要,可使用 toHaveBeenNthCalledWith

-expect(onMessage).toHaveBeenCalledTimes(2);
-expect(onMessage).toHaveBeenCalledWith(message);
-expect(onMessage).toHaveBeenCalledWith(message2);
+expect(onMessage).toHaveBeenNthCalledWith(1, message);
+expect(onMessage).toHaveBeenNthCalledWith(2, message2);
packages/runtime/src/internal/secret_internals.spec.ts (1)

1406-1407: 优化 delete 操作符的性能

静态分析工具建议避免使用 delete 操作符,因为它可能影响性能。建议使用 undefined 赋值替代。

应用此修复来优化性能:

-delete (window as any).location;
+(window as any).location = undefined;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e452085 and 5201307.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (85)
  • cypress/e2e/size-check.spec.js (1 hunks)
  • docker-compose.yml (1 hunks)
  • package.json (2 hunks)
  • packages/babel-preset-next/package.json (1 hunks)
  • packages/brick-container/package.json (3 hunks)
  • packages/brick-container/src/loadBootstrapData.spec.ts (9 hunks)
  • packages/brick-container/src/loadCheckLogin.spec.ts (1 hunks)
  • packages/brick-container/src/preview/initialize.spec.ts (1 hunks)
  • packages/brick-container/src/preview/listen.spec.ts (4 hunks)
  • packages/brick-playground/package.json (1 hunks)
  • packages/build-next-bricks/package.json (1 hunks)
  • packages/build-next-libs/package.json (1 hunks)
  • packages/cook/package.json (1 hunks)
  • packages/cook/src/cook.spec.ts (8 hunks)
  • packages/cook/src/precook.spec.ts (7 hunks)
  • packages/cook/src/precookFunction.spec.ts (1 hunks)
  • packages/cook/src/preevaluate.spec.ts (1 hunks)
  • packages/create-api-sdk/package.json (1 hunks)
  • packages/create-api-sdk/src/contractGit.spec.ts (4 hunks)
  • packages/create-api-sdk/src/index.spec.ts (2 hunks)
  • packages/doc-helpers/package.json (1 hunks)
  • packages/easyops-runtime/src/analytics/analytics.spec.ts (5 hunks)
  • packages/easyops-runtime/src/analytics/http.spec.ts (5 hunks)
  • packages/easyops-runtime/src/analytics/pageView.spec.ts (2 hunks)
  • packages/easyops-runtime/src/auth.spec.ts (1 hunks)
  • packages/easyops-runtime/src/checkInstalledApps.spec.ts (3 hunks)
  • packages/easyops-runtime/src/checkPermissions.spec.ts (8 hunks)
  • packages/easyops-runtime/src/flowApi/FlowApiProvider.spec.ts (2 hunks)
  • packages/easyops-runtime/src/menu/fetchMenuById.spec.ts (2 hunks)
  • packages/easyops-runtime/src/websocket/MessageDispatcher.spec.ts (2 hunks)
  • packages/easyops-runtime/src/websocket/MessageService.spec.ts (2 hunks)
  • packages/element/src/NextElement.spec.ts (16 hunks)
  • packages/eslint-config-next/package.json (1 hunks)
  • packages/http/src/http.spec.ts (2 hunks)
  • packages/loader/src/loadScript.spec.ts (2 hunks)
  • packages/loader/src/loadSharedModule.spec.ts (1 hunks)
  • packages/loader/src/loadStyle.spec.ts (2 hunks)
  • packages/loader/src/stableLoadBricks.spec.ts (22 hunks)
  • packages/loader/src/standalone.spec.ts (1 hunks)
  • packages/react-element/src/ReactNextElement.spec.tsx (1 hunks)
  • packages/react-element/src/wrapBrick.spec.tsx (1 hunks)
  • packages/react-element/src/wrapBrick.tsx (4 hunks)
  • packages/react-runtime/src/ReactUseBrick.spec.tsx (14 hunks)
  • packages/react-runtime/src/useCurrentApp.spec.ts (2 hunks)
  • packages/react-runtime/src/useCurrentTheme.spec.ts (1 hunks)
  • packages/react-runtime/src/useNavConfig.spec.ts (1 hunks)
  • packages/react-runtime/src/useProvider/useProvider.spec.tsx (1 hunks)
  • packages/react-runtime/src/useRouteRender.spec.ts (1 hunks)
  • packages/runtime/package.json (1 hunks)
  • packages/runtime/src/CustomProcessors.spec.ts (1 hunks)
  • packages/runtime/src/CustomTemplates.spec.ts (6 hunks)
  • packages/runtime/src/Dialog.spec.ts (5 hunks)
  • packages/runtime/src/Notification.spec.ts (2 hunks)
  • packages/runtime/src/StoryboardFunctionRegistry.spec.ts (2 hunks)
  • packages/runtime/src/createRoot.spec.ts (5 hunks)
  • packages/runtime/src/handleHttpError.spec.ts (5 hunks)
  • packages/runtime/src/internal/ErrorNode.spec.ts (1 hunks)
  • packages/runtime/src/internal/Renderer.spec.ts (25 hunks)
  • packages/runtime/src/internal/Runtime.spec.ts (18 hunks)
  • packages/runtime/src/internal/bindListeners.spec.ts (43 hunks)
  • packages/runtime/src/internal/compute/evaluate.spec.ts (1 hunks)
  • packages/runtime/src/internal/compute/getStorageItem.spec.ts (1 hunks)
  • packages/runtime/src/internal/data/DataStore.spec.ts (22 hunks)
  • packages/runtime/src/internal/data/resolveData.spec.ts (8 hunks)
  • packages/runtime/src/internal/data/resolveDataStore.spec.ts (4 hunks)
  • packages/runtime/src/internal/devtools.spec.ts (2 hunks)
  • packages/runtime/src/internal/hasInstalledApp.spec.ts (1 hunks)
  • packages/runtime/src/internal/historyExtended.spec.ts (8 hunks)
  • packages/runtime/src/internal/matchRoutes.spec.ts (1 hunks)
  • packages/runtime/src/internal/mediaQuery.spec.ts (1 hunks)
  • packages/runtime/src/internal/poll.spec.ts (10 hunks)
  • packages/runtime/src/internal/secret_internals.spec.ts (6 hunks)
  • packages/runtime/src/isStrictMode.spec.ts (1 hunks)
  • packages/runtime/src/setWatermark.spec.ts (2 hunks)
  • packages/runtime/src/themeAndMode.spec.ts (2 hunks)
  • packages/test-next/package.json (2 hunks)
  • packages/test-next/src/run.js (2 hunks)
  • packages/utils/src/general/deepFreeze.spec.ts (1 hunks)
  • packages/utils/src/storyboard/expressions/track.spec.ts (2 hunks)
  • packages/utils/src/storyboard/expressions/traverse.spec.ts (1 hunks)
  • packages/utils/src/storyboard/functions/collectMemberUsageInFunction.spec.ts (2 hunks)
  • packages/utils/src/storyboard/functions/traverse.spec.ts (2 hunks)
  • packages/webpack/package.json (1 hunks)
  • packages/yo/src/templates/brick/i18n.ts (1 hunks)
  • patches/jsdom+26.1.0.patch (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/utils/src/general/deepFreeze.spec.ts

[error] 38-38: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 53-53: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/runtime/src/internal/secret_internals.spec.ts

[error] 1406-1407: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

packages/runtime/src/internal/bindListeners.spec.ts

[error] 190-190: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)


[error] 195-195: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build (20.x)
🔇 Additional comments (110)
packages/loader/src/standalone.spec.ts (1)

27-39: 采用 toHaveBeenCalledWith 取代 toBeCalledWith 更符合 Jest 规范

toHaveBeenCalledWith 语义更清晰,也与 Jest 官方文档保持一致;本次替换不会影响断言逻辑, 👍🏻。

packages/runtime/src/setWatermark.spec.ts (2)

176-176: 统一改为 toHaveBeenCalled,语义更清晰 👍
替换过期的 toBeCalled 断言符合 Jest 官方推荐,逻辑保持不变。


189-189: 同上,断言升级 LGTM
保持一致性,增强可读性。

packages/utils/src/storyboard/functions/traverse.spec.ts (2)

43-43: 👍 使用 toHaveBeenCalledTimes 是 Jest 官方推荐写法,更新到位。
该改动提高了断言语义的清晰度,与当前 Jest 版本保持一致,无需额外调整。


75-75: 👍 同理,这里也已正确替换为 toHaveBeenCalledTimes
两处改动保持了一致的断言风格,测试可读性更佳。

packages/utils/src/general/deepFreeze.spec.ts (2)

26-30: 统一使用 toThrow 断言 👍

toThrowError 改为 toThrow 保持了与全仓库一致的 Jest 断言风格,可读性更好,无功能性风险。


61-65: 嵌套对象与数组变异断言覆盖充分

对深层对象、数组的多种变异方式均已断言抛错,测试完备,👍。

packages/utils/src/storyboard/expressions/traverse.spec.ts (1)

63-69: Jest 匹配器替换十分到位

已将 toBeCalledTimes / toBeCalledWith 升级为推荐的 toHaveBeenCalledTimes / toHaveBeenCalledWith,与 Jest ≥ 25 的 API 一致,可避免未来的弃用警告。实现正确,无其它隐患。

packages/react-element/src/ReactNextElement.spec.tsx (1)

302-304: 验证断言松化是否符合预期

toThrowError() 改为 toThrow() 放宽了错误断言的要求。toThrowError() 专门验证抛出 Error 对象,而 toThrow() 接受任何抛出的值。请确认这种松化是有意为之,不会降低测试的有效性。

packages/react-runtime/src/useNavConfig.spec.ts (1)

36-38: LGTM:Jest 断言方法的标准化改进

toBeCalledWith 更新为 toHaveBeenCalledWith 是一个很好的改进,后者更加明确和具有描述性。这个改动符合 Jest 的最佳实践,并与整个代码库的标准化努力保持一致。

packages/runtime/src/themeAndMode.spec.ts (4)

65-65: 优秀的 Jest 断言方法更新!

not.toBeCalled() 更新为 not.toHaveBeenCalled() 是一个很好的改进,使用了 Jest 推荐的更明确的断言方法。


67-67: 优秀的 Jest 断言方法更新!

toBeCalled() 更新为 toHaveBeenCalled() 是一个很好的改进,使用了 Jest 推荐的更明确的断言方法。


120-120: 优秀的 Jest 断言方法更新!

not.toBeCalled() 更新为 not.toHaveBeenCalled() 是一个很好的改进,使用了 Jest 推荐的更明确的断言方法。


122-122: 优秀的 Jest 断言方法更新!

toBeCalled() 更新为 toHaveBeenCalled() 是一个很好的改进,使用了 Jest 推荐的更明确的断言方法。

packages/runtime/src/StoryboardFunctionRegistry.spec.ts (2)

135-136: LGTM! Jest断言方法更新符合最佳实践

toBeCalledTimestoBeCalledWith更新为toHaveBeenCalledTimestoHaveBeenCalledWith是很好的改进。新的方法名更加明确和具有描述性,符合Jest的推荐做法。


300-315: LGTM! 测试断言更新保持一致性

在coverage收集测试中统一使用toHaveBeenCalledTimestoHaveBeenCalledWith方法,与整个代码库的更新保持一致。这些新的断言方法更加明确,有助于提高代码可读性。

packages/runtime/src/internal/compute/getStorageItem.spec.ts (1)

12-12: 使用 toHaveBeenCalledWith 替换 toBeCalledWith 👍

采用更语义化的 Jest 断言,提升了可读性与一致性。

packages/runtime/src/createRoot.spec.ts (2)

32-34: 匹配器升级 👍

toBeCalled / not.toBeCalled 替换为推荐的 toHaveBeenCalled / not.toHaveBeenCalled,符合 Jest 最佳实践。


244-248: 快照更新与样式校验一致 👍

将 error boundary 外层 div 增加 style="color: var(--color-error);" 后同步更新了快照,保持测试一致性。

packages/yo/src/templates/brick/i18n.ts (1)

6-13: en / zh 当前为空,占位意义有限

在补全 K 的同时,请同步为 enzh 填充对应字段,否则运行时无法取得翻译文本。

packages/element/src/NextElement.spec.ts (12)

23-43: 一致性替换为 toHaveBeenCalled* 👍

将所有 toBeCalled* 别名替换为官方推荐的 toHaveBeenCalled* 形式,符合 Jest 最新实践,语义也更清晰。实现无问题。


58-76: 继续保持新断言写法 ✅

这里同样完成了 matcher 统一,逻辑未变,OK。


112-140: 布尔属性测试更新正确

计数断言与预期流程一致,改动纯粹是 API 切换。


156-164: 默认 true 场景断言更新无误


181-189: 默认 truefalse 场景断言更新无误


204-232: 数字属性测试断言统一 ✅


247-259: 复杂属性场景断言统一 ✅


311-341: 继承场景渲染计数断言统一 ✅


370-381: 解析后挂载场景断言统一 ✅


424-430: 事件监听断言统一,语义更清晰 👍


523-534: 特定 attribute 场景断言统一 ✅


584-593: render: false 场景断言统一 ✅

packages/react-runtime/src/useCurrentApp.spec.ts (2)

44-46: 使用 toHaveBeenCalledWith 替换旧匹配器 👍

断言已更新为更明确的 toHaveBeenCalledWith,符合 Jest 推荐做法。
若补充上一条建议(清理 spy),此断言将更稳健。


16-20: 为确认其他测试文件中是否已在 afterEach 清理这两个 spy,运行以下脚本查看四个测试文件的 afterEach 配置:

#!/bin/bash
for file in \
  packages/react-runtime/src/useNavConfig.spec.ts \
  packages/react-runtime/src/useRouteRender.spec.ts \
  packages/react-runtime/src/useCurrentTheme.spec.ts \
  packages/react-runtime/src/useCurrentApp.spec.ts; do
  echo "----- $file -----"
  rg -n "afterEach" -C3 $file || echo "No afterEach found"
done
packages/runtime/package.json (1)

64-64: 验证依赖版本的有效性和安全性

请确认 @microsoft/api-extractor 版本 ^7.52.8 确实存在,并检查是否有相关的安全建议。

#!/bin/bash
# 检查 @microsoft/api-extractor 的最新版本和安全建议
curl -s https://registry.npmjs.org/@microsoft/api-extractor | jq '.versions | keys | .[-5:]'

# 检查安全建议
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "@microsoft/api-extractor") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'
packages/brick-playground/package.json (1)

43-43: 依赖版本升级看起来正常

webpack-dev-server^5.2.0 升级到 ^5.2.2 是补丁版本升级,应该是安全的。建议验证该版本确实存在。

#!/bin/bash
# 验证 webpack-dev-server 版本是否存在
curl -s https://registry.npmjs.org/webpack-dev-server | jq '.versions | has("5.2.2")'
packages/doc-helpers/package.json (2)

33-33: 验证 prettier 版本升级是否引入格式化变更

prettier^3.5.3 升级到 ^3.6.0 可能会影响代码格式化规则。建议检查是否有格式化变更。

#!/bin/bash
# 检查 prettier 版本和变更日志
curl -s https://registry.npmjs.org/prettier | jq '.versions | has("3.6.0")'
curl -s https://api.github.com/repos/prettier/prettier/releases | jq '.[0:3] | .[] | {tag_name, published_at, body}' | head -30

31-31: 验证 fast-xml-parser 版本升级的兼容性

fast-xml-parser^5.0.8 升级到 ^5.2.5 是次要版本升级,可能包含新功能。请验证版本兼容性。

#!/bin/bash
# 检查 fast-xml-parser 版本和变更日志
curl -s https://registry.npmjs.org/fast-xml-parser | jq '.versions | has("5.2.5")'
curl -s https://api.github.com/repos/NaturalIntelligence/fast-xml-parser/releases | jq '.[0:3] | .[] | {tag_name, published_at, body}' | head -30
packages/easyops-runtime/src/flowApi/FlowApiProvider.spec.ts (2)

112-112: Jest 断言方法现代化

toBeCalledWith 更新为 toHaveBeenCalledWith 是好的实践,新方法更明确且是推荐的用法。


211-213: Jest 断言方法现代化

toBeCalledWith 更新为 toHaveBeenCalledWith 是好的实践,新方法更明确且是推荐的用法。

packages/loader/src/loadScript.spec.ts (4)

30-30: Jest 断言方法现代化

toBeCalledTimes 更新为 toHaveBeenCalledTimes 是好的实践,新方法更明确且是推荐的用法。


38-38: Jest 断言方法现代化

toBeCalledTimes 更新为 toHaveBeenCalledTimes 是好的实践,新方法更明确且是推荐的用法。


47-47: Jest 断言方法现代化

toBeCalledTimes 更新为 toHaveBeenCalledTimes 是好的实践,新方法更明确且是推荐的用法。


55-55: Jest 断言方法现代化

toBeCalledTimes 更新为 toHaveBeenCalledTimes 是好的实践,新方法更明确且是推荐的用法。

packages/loader/src/loadStyle.spec.ts (1)

30-30: Jest 断言方法现代化更新

toBeCalledTimes 更新为 toHaveBeenCalledTimes 是一个很好的改进。新的语法更加明确和易读,符合 Jest 的最佳实践。

Also applies to: 38-38, 47-47, 55-55

packages/test-next/src/run.js (2)

4-4: Jest v30 导入方式更新

从默认导入改为命名导入符合 Jest v30 的 API 变更。


26-26: 验证 Jest v30 兼容性

直接调用 run(args) 与新的导入方式一致。请确保这与 Jest v30 的 API 完全兼容。

#!/bin/bash
# 验证 Jest v30 的 run 函数导入和使用方式
rg -A 3 -B 3 "import.*run.*from.*jest" --type js --type ts
packages/test-next/package.json (2)

4-4: 包描述更新

更新描述以反映 Jest v30 的使用是合适的。


35-35: 验证 Jest v30 重大版本升级的兼容性

Jest 从 v29 升级到 v30 是一个重大版本更新,可能包含破坏性变更。请确保所有相关的测试和功能在新版本下正常工作。

其他依赖更新看起来是常规的小版本或补丁版本更新。

Jest v30 有哪些重大变化和破坏性更新?

Also applies to: 38-39, 41-42, 45-45

packages/easyops-runtime/src/analytics/analytics.spec.ts (1)

44-44: Jest 断言方法标准化

将所有 toBeCalled* 方法更新为 toHaveBeenCalled* 方法提高了代码的一致性和可读性。这些更现代的 Jest 断言方法更加明确表达了测试意图。

Also applies to: 108-108, 162-162, 203-203, 239-239

packages/brick-container/package.json (2)

50-50: 常规依赖更新

ws、core-js 和 webpack-dev-server 的版本更新都是安全的小版本或补丁版本更新,应该不会引入破坏性变更。

Also applies to: 68-68, 71-71


39-39: 验证 body-parser 重大版本升级

body-parser 从 v1.20.3 升级到 v2.2.0 是一个重大版本更新。请确认这个升级不会引入破坏性变更,特别是在现有的 Express 中间件配置中。

body-parser v2.x 相比 v1.x 有哪些破坏性变更?
packages/easyops-runtime/src/analytics/pageView.spec.ts (1)

27-36: 为了确认 pageView.spec.ts 中是否存在 spyOnjest.mock 调用,请执行以下脚本:

#!/bin/bash
# 查找测试文件路径
fd pageView.spec.ts -t f

# 在文件中搜索 spyOn 和 jest.mock 调用
rg "spyOn" -A3 packages/easyops-runtime/src/analytics/pageView.spec.ts
rg "jest\\.mock" -A3 packages/easyops-runtime/src/analytics/pageView.spec.ts
packages/build-next-bricks/package.json (1)

37-57: 大版本依赖升级需验证兼容性

  • @babel/parser/traversewebpackpostcss 等工具链均有次版本升级,可能引入 Breaking Change(如 Node 版本要求、AST 节点变更)。
  • 目前 engines.node 仍为 >=16,请确认所有新版本依赖仍兼容 Node 16。

建议本地执行完整构建+回归测试,或在 CI 中增加 matrix 覆盖 Node 16/18。

packages/webpack/package.json (1)

22-26: devDependencies 与 peerDependencies 同步升级 👍

webpack 版本已在两处保持一致,可避免安装冲突。
确认其它包(如 webpack-dev-server、插件)版本也与 5.99.x 兼容即可。

packages/easyops-runtime/src/checkPermissions.spec.ts (1)

63-63: Jest 断言方法现代化的优秀改进

toBeCalled()toBeCalledWith() 更新为更明确的 toHaveBeenCalled()toHaveBeenCalledWith() 是一个很好的改进,符合 Jest 的最佳实践。这些更改提高了测试代码的可读性和一致性。

Also applies to: 65-65, 72-72, 74-76, 83-86, 88-90, 107-112, 114-119, 262-267, 268-270, 288-293, 294-294, 303-303, 306-308, 321-321, 333-333, 340-340, 348-348

packages/loader/src/loadSharedModule.spec.ts (2)

14-15: Mock 函数签名改进

显式地接受参数 _scope_id 使 mock 函数的签名更加清晰和准确,即使这些参数在测试中没有被使用。下划线前缀正确地表明了这些参数是有意未使用的。


20-21: Jest 断言方法现代化

toBeCalledWith 更新为 toHaveBeenCalledWith 符合 Jest 的最佳实践,提供了更明确和推荐的断言方法。

packages/easyops-runtime/src/checkInstalledApps.spec.ts (1)

65-65: 一致的 Jest 断言现代化

在所有测试用例中一致地将 toBeCalledTimes()toBeCalledWith() 更新为 toHaveBeenCalledTimes()toHaveBeenCalledWith() 很好地遵循了 Jest 的推荐实践。这些更改提高了测试代码的一致性和可读性。

Also applies to: 93-93, 113-113, 115-119

packages/react-runtime/src/ReactUseBrick.spec.tsx (1)

77-77: 全面的 Jest 断言现代化

这个文件中全面且系统地将所有 Jest 断言方法从过时的 toBeCalled* 系列更新为推荐的 toHaveBeenCalled* 系列,涵盖了所有测试用例和 mock 函数。这种一致的现代化改进了测试代码的可读性和维护性,完全符合 Jest 的最佳实践。

Also applies to: 90-90, 94-95, 102-108, 113-119, 121-121, 124-125, 133-140, 143-158, 179-186, 191-198, 206-206, 214-227, 250-256, 268-281, 294-300, 321-329, 347-361, 381-392

packages/loader/src/stableLoadBricks.spec.ts (2)

57-57: Mock 函数签名的灵活性改进

使用 (..._args: unknown[]) 使 mock 函数更加灵活,能够接受任意数量和类型的参数,这更准确地反映了实际使用场景。下划线前缀正确地表明了参数是有意未使用的。


94-94: 大规模 Jest 断言现代化

在整个测试套件中系统地将 toBeCalledTimes 更新为 toHaveBeenCalledTimes,以及相关的 mock 函数断言更新,完美地完成了 Jest 最佳实践的现代化。这种一致的更改提高了整个测试代码库的质量和可维护性。

Also applies to: 132-132, 200-200, 237-246, 266-266, 283-283, 312-312, 333-346, 364-364, 399-399, 433-447, 486-486, 557-557, 600-600, 644-644, 688-710, 751-785

packages/react-element/src/wrapBrick.tsx (3)

17-17: 类型定义优化符合React最佳实践

使用PropsWithChildren<P>替代手动定义children属性是React推荐的做法,这样的改进提高了类型安全性和代码的可读性。

Also applies to: 21-21


37-37: 未使用的泛型参数命名规范

将未使用的泛型参数E重命名为_E符合TypeScript命名约定,清楚地表明该参数未被使用,提高了代码的可维护性。

Also applies to: 74-74


49-62: forwardRef类型简化改进代码可读性

通过利用React的PropsWithChildren类型和简化类型注解,代码变得更加简洁和易读,同时保持了相同的功能性和类型安全性。

Also applies to: 78-90

packages/react-element/src/wrapBrick.spec.tsx (1)

111-111: Jest断言方法现代化

toBeCalled()toBeCalledTimes(1)更新为toHaveBeenCalled()toHaveBeenCalledTimes(1)符合Jest最佳实践,新的方法名更加明确和易读。这种统一的更新提高了测试代码的一致性。

Also applies to: 113-113

packages/cook/package.json (1)

52-52: 依赖版本升级合理

@babel/parser^7.26.10升级到^7.27.5是一个合理的小版本升级,通常包含bug修复和性能改进。这与整个monorepo的依赖升级策略保持一致。

packages/create-api-sdk/package.json (1)

52-53: 依赖版本升级适当

prettier升级到^3.6.0semver升级到^7.7.2都是合理的版本升级。prettier的小版本升级可能包含格式化改进,而semver的补丁版本升级通常包含bug修复,这些升级有助于保持依赖的现代性和稳定性。

packages/brick-container/src/preview/initialize.spec.ts (1)

78-80: Jest断言方法标准化

toBeCalledWith更新为toHaveBeenCalledWith符合Jest最佳实践,新方法名更加明确,与整个代码库中的测试断言现代化保持一致。

packages/runtime/src/internal/matchRoutes.spec.ts (1)

22-25: LGTM! Jest 断言方法标准化

toBeCalledWith 更新为更明确的 toHaveBeenCalledWith 是一个很好的标准化改进,提高了测试代码的可读性和一致性。

cypress/e2e/size-check.spec.js (1)

38-39: 合理的资源大小限制调整

资源大小限制的增加(总资源从320KB增加到330KB,JS资源从300KB增加到310KB)与Cypress版本升级相符。这些适度的调整有助于确保测试的稳定性。

建议验证这些限制增加是否确实必要:

#!/bin/bash
# 描述:检查资源大小变化是否与Cypress升级相关

# 搜索其他可能的资源大小配置
rg -A 3 -B 3 "lessThan.*e[0-9]" --type js
packages/build-next-libs/package.json (1)

22-23: Babel 依赖版本升级

Babel CLI 和 Core 的版本升级是合理的维护更新,应该提供错误修复和改进功能。

建议验证这些版本是否包含安全修复:

@babel/cli 7.27.2 和 @babel/core 7.27.4 版本是否包含重要的安全修复或错误修复?
docker-compose.yml (1)

4-4: Cypress Docker 镜像版本升级

将 Cypress Docker 镜像从 14.1.0 升级到 14.4.1 与整体的 Cypress 升级策略保持一致,应该提供更好的稳定性和功能改进。

packages/runtime/src/internal/ErrorNode.spec.ts (1)

257-257: Jest 断言方法标准化

toBeCalledTimes 更新为 toHaveBeenCalledTimes 符合 Jest 最佳实践,提高了测试代码的明确性和一致性。

packages/create-api-sdk/src/contractGit.spec.ts (1)

25-25: Jest 断言方法标准化更新正确

toBeCalledWithtoBeCalled 替换为更明确的 toHaveBeenCalledWithtoHaveBeenCalled 是 Jest 的最佳实践,提高了代码的可读性和明确性。

Also applies to: 43-43, 63-63, 66-66

packages/runtime/src/internal/compute/evaluate.spec.ts (1)

365-365: Jest 断言方法更新符合最佳实践

toBeCalledTimes 替换为 toHaveBeenCalledTimes 是正确的标准化更新。

packages/runtime/src/internal/mediaQuery.spec.ts (1)

29-29: Jest 断言方法标准化正确

lastCalledWith 更新为 toHaveBeenLastCalledWith 提高了断言的明确性。

packages/babel-preset-next/package.json (1)

14-19: 验证 Babel 依赖版本更新的兼容性

这些 Babel 相关包的版本更新看起来是协调一致的升级,建议验证新版本是否存在已知的兼容性问题或破坏性更改。

Are there any breaking changes or known issues in Babel 7.27.x versions compared to previous 7.x versions?
packages/runtime/src/internal/hasInstalledApp.spec.ts (1)

56-57: Jest 断言方法标准化更新一致

toBeCalledTimestoBeCalledWith 更新为 toHaveBeenCalledTimestoHaveBeenCalledWith 与整个代码库的标准化努力保持一致。

packages/cook/src/precookFunction.spec.ts (1)

296-299: Jest断言方法现代化,提升代码可读性

toBeCalledTimestoBeCalledWith 更新为更明确的 toHaveBeenCalledTimestoHaveBeenCalledWith,这符合 Jest 的最佳实践,提高了测试断言的可读性。

packages/runtime/src/internal/devtools.spec.ts (1)

47-47: Jest断言方法标准化

统一使用 toHaveBeenCalledTimes 替代 toBeCalledTimes,与整个代码库的现代化保持一致,提升了测试代码的清晰度。

Also applies to: 67-67

packages/runtime/src/internal/historyExtended.spec.ts (1)

143-143: 全面更新Jest断言方法

将所有 toBeCalledWith 实例统一替换为 toHaveBeenCalledWith,这是Jest推荐的更明确的断言方法。此更改提高了测试代码的一致性和可读性,同时保持了所有测试逻辑不变。

Also applies to: 172-172, 223-223, 232-246, 254-255, 262-263, 299-299, 328-328, 338-338

packages/runtime/src/internal/data/resolveDataStore.spec.ts (1)

163-163: Jest断言方法现代化改进

在多个测试用例中统一将 toBeCalledTimes 更新为 toHaveBeenCalledTimes,提升了测试断言的明确性。这些更改遵循Jest最佳实践,增强了代码的可维护性。

Also applies to: 174-174, 182-182, 189-189, 254-254, 261-261, 268-268, 323-323

packages/create-api-sdk/src/index.spec.ts (1)

19-19: 完整的Jest断言方法升级

全面更新了所有Jest断言方法:toBeCalledWithtoHaveBeenCalledWithtoBeCalledtoHaveBeenCalled。这些更改提高了测试代码的明确性和一致性,符合现代Jest测试最佳实践。

Also applies to: 27-27, 35-35, 47-48

packages/runtime/src/Notification.spec.ts (2)

37-41: Jest 断言方法现代化改进很好!

toBeCalledWithtoBeCalled 更新为更明确的 toHaveBeenCalledWithtoHaveBeenCalled 是很好的实践,提高了代码可读性。


48-49: Jest 断言方法统一性改进

一致地使用 toHaveBeenCalledTimestoHaveBeenCalledWith 替代已弃用的方法,保持了整个测试文件的一致性。

Also applies to: 59-61

packages/runtime/src/internal/data/resolveData.spec.ts (1)

63-63: Jest 断言方法现代化完成得很好

系统性地将 toBeCalledTimes 更新为 toHaveBeenCalledTimes 提高了测试代码的现代性和一致性。这些更改保持了相同的语义,只是使用了更明确的方法名。

Also applies to: 75-75, 87-87, 116-116, 126-126, 189-190, 209-209, 222-222

packages/cook/src/preevaluate.spec.ts (1)

80-82: 错误信息更加详细和有用

新的错误信息比之前的通用语法错误信息更具描述性,明确指出了问题所在(应该包含一个表达式,但在位置 (1:5) 遇到了意外字符 :)。这个改进与 @babel/parser 版本升级相符,提供了更好的开发体验。

packages/brick-container/src/loadBootstrapData.spec.ts (1)

316-316: Jest 断言方法全面现代化

在整个测试文件中一致地将已弃用的 Jest 匹配器方法(toBeCalledWithtoBeCalledTimestoBeCalled)更新为推荐的对应方法(toHaveBeenCalledWithtoHaveBeenCalledTimestoHaveBeenCalled),提高了代码的现代性和一致性。

Also applies to: 361-362, 431-431, 473-474, 708-708, 722-723, 748-748, 771-771, 773-773, 797-797, 835-835

packages/runtime/src/internal/poll.spec.ts (1)

69-71: Jest 断言方法全面系统性升级

在整个测试文件中系统性地将已弃用的 Jest 断言方法(toBeCalledtoBeCalledWithtoBeCalledTimes)更新为推荐的现代方法(toHaveBeenCalledtoHaveBeenCalledWithtoHaveBeenCalledTimes)。这种全面的现代化改进了代码的一致性和可维护性,符合 Jest 最佳实践。

Also applies to: 77-79, 114-114, 119-124, 153-158, 189-192, 197-199, 233-237, 271-271, 276-279, 311-311, 316-319, 356-356, 359-359, 366-370, 413-413, 416-416, 419-419, 423-426, 476-476, 479-479, 482-482, 487-490

packages/http/src/http.spec.ts (2)

145-166: Jest断言方法标准化升级

正确地将过时的Jest匹配器方法替换为推荐的现代等价方法,提高了测试代码的一致性和可读性。


253-262: Jest断言方法标准化升级

正确地将过时的Jest匹配器方法替换为推荐的现代等价方法,保持了与代码库其他部分的一致性。

packages/runtime/src/CustomTemplates.spec.ts (1)

31-31: Jest断言方法标准化升级

在整个文件中一致地将过时的Jest匹配器方法替换为推荐的现代等价方法,这提高了测试代码的清晰度和标准化程度。

Also applies to: 54-59, 177-182, 244-250, 278-282, 315-320

packages/brick-container/src/preview/listen.spec.ts (1)

50-61: Jest断言方法标准化升级

正确地将过时的Jest匹配器方法替换为推荐的现代等价方法,与代码库的整体标准化努力保持一致。

Also applies to: 90-101, 114-115, 144-145

packages/cook/src/precook.spec.ts (1)

72-72: Jest断言方法标准化升级

在整个测试文件中一致地应用Jest断言方法的现代化替换,提高了测试代码的可读性和标准化程度。

Also applies to: 509-509, 527-527, 559-559, 652-652, 680-680, 713-713

packages/eslint-config-next/package.json (1)

18-27: 依赖版本升级

合理地将ESLint及相关工具链升级到较新的稳定版本。将eslint的peerDependency从范围版本改为明确的最小版本要求,提供了更清晰的兼容性指导。

packages/runtime/src/internal/Renderer.spec.ts (1)

225-225: LGTM! Jest 断言方法现代化改进

将已弃用的 toBeCalledTimes/toBeCalledWith 更新为推荐的 toHaveBeenCalledTimes/toHaveBeenCalledWith 是最佳实践。这些更改提高了测试代码的明确性和一致性。

Also applies to: 238-242, 363-367, 425-425, 510-510, 751-752, 786-786, 818-818, 883-883, 924-929, 940-941, 995-999, 1196-1196, 1199-1199, 1215-1215, 1219-1219, 1238-1238, 1280-1280, 1283-1283, 1345-1345, 1349-1349, 1369-1369, 1372-1372, 1379-1379, 1383-1383, 1399-1399, 2175-2177, 2182-2184, 2280-2280, 2283-2283, 2345-2345, 2349-2349, 3323-3323, 3744-3748, 3782-3782, 3812-3815, 3852-3852

patches/jsdom+26.1.0.patch (1)

9-10: 验证 window.location 可配置性变更的影响

window.location 属性从不可配置改为可配置可能会影响测试行为和安全性。请确认:

  1. 此变更是否为了解决特定的测试需求?
  2. 是否已验证不会导致测试与真实浏览器环境的行为差异?
  3. 是否考虑了潜在的安全影响?

建议添加注释说明此补丁的必要性和用途。

#!/bin/bash
# 搜索代码库中可能依赖 window.location 可配置性的代码
rg -A 3 -B 3 "window\.location.*=|Object\.defineProperty.*location|location.*configurable"
packages/runtime/src/handleHttpError.spec.ts (1)

126-126: LGTM! Jest 断言方法标准化更新

将 Jest 断言方法统一更新为推荐的 toHaveBeenCalled* 形式,提高了测试代码的可读性和一致性。所有变更都保持了原有的测试逻辑不变。

Also applies to: 128-133, 134-134, 149-154, 156-160, 161-161, 173-178, 180-184, 185-185, 197-202, 204-205, 216-221, 222-222, 227-227

packages/runtime/src/Dialog.spec.ts (1)

35-38: LGTM! Jest 断言方法和格式优化

更新为推荐的 toHaveBeenCalled* 断言方法,并改进了多参数调用的格式化,提高了代码可读性。所有变更都保持了测试逻辑的完整性。

Also applies to: 45-49, 56-57, 66-70, 80-81, 90-94, 101-103, 111-115, 122-124

packages/easyops-runtime/src/analytics/http.spec.ts (1)

63-64: ✅ Jest 断言方法现代化更新

将 Jest 的旧断言方法更新为推荐的新方法是很好的实践:

  • toBeCalledTimestoHaveBeenCalledTimes
  • toBeCalledWithtoHaveBeenCalledWith

这些更改提高了测试代码的清晰度和一致性,符合 Jest 的最佳实践。

Also applies to: 103-104, 140-141, 172-173, 204-204

packages/brick-container/src/loadCheckLogin.spec.ts (1)

17-17: ✅ Jest 断言方法标准化

正确地将 Jest 的旧断言方法更新为新的推荐方法:

  • toBeCalledtoHaveBeenCalled
  • toBeCalledWithtoHaveBeenCalledWith

这些更改提高了测试代码的可读性和维护性。

Also applies to: 23-23, 31-32

packages/runtime/src/internal/data/DataStore.spec.ts (1)

369-369: ✅ 全面的 Jest 断言方法现代化

在整个测试文件中系统性地将 Jest 的旧断言方法更新为新的推荐方法,包括:

  • toBeCalledtoHaveBeenCalled
  • toBeCalledTimestoHaveBeenCalledTimes
  • toBeCalledWithtoHaveBeenCalledWith

这种一致性的更新提高了代码质量,符合 Jest 的现代化最佳实践。更改保持了测试逻辑的完整性,仅改进了断言方法的表达方式。

Also applies to: 373-376, 378-378, 449-449, 509-509, 542-543, 574-575, 614-614, 621-621, 662-662, 672-672, 686-686, 738-739, 752-753, 900-900, 932-932, 964-964, 995-995, 1031-1031, 1058-1058, 1087-1087, 1225-1225, 1237-1237

packages/cook/src/cook.spec.ts (1)

208-208: ✅ Jest 断言方法全面升级

本文件包含了两种类型的 Jest API 现代化更新:

  1. 异常断言改进toThrowErrortoThrow
  2. 模拟函数调用断言改进toBeCalled*toHaveBeenCalled*

这些更改都符合 Jest 的最佳实践,提高了测试代码的清晰度和一致性。toThrow 方法比 toThrowError 更简洁且为 Jest 官方推荐。

Also applies to: 245-245, 274-274, 331-331, 357-357, 363-363, 368-375, 384-384, 404-411

packages/runtime/src/internal/bindListeners.spec.ts (1)

85-87: ✅ 广泛的 Jest 断言方法标准化

在整个测试套件中系统性地更新 Jest 断言方法,包括:

  • toBeCalledtoHaveBeenCalled
  • toBeCalledTimestoHaveBeenCalledTimes
  • toBeCalledWithtoHaveBeenCalledWith

这种大规模的一致性更新显著提升了测试代码的现代化水平和可维护性。所有更改都保持了测试逻辑的完整性,仅改进了断言语法的表达方式。

Also applies to: 93-93, 122-122, 132-132, 143-143, 159-162, 188-188, 191-198, 218-218, 229-229, 255-255, 265-265, 336-336, 583-583, 593-593, 604-604, 623-623, 633-633, 652-652, 666-666, 678-678, 702-704, 713-713, 724-724, 736-736, 747-747, 758-758, 769-772, 786-789, 805-808, 1020-1020, 1059-1067, 1092-1095, 1135-1144, 1182-1192, 1209-1210, 1227-1228, 1245-1246, 1263-1264, 1284-1287, 1297-1299, 1437-1445, 1498-1501, 1528-1531, 1544-1544

packages/runtime/src/internal/Runtime.spec.ts (1)

749-750: LGTM!Jest 断言方法现代化

这些更改将已弃用的 Jest 匹配器方法(如 toBeCalled()toBeCalledTimes()toBeCalledWith())替换为更明确和推荐的对应方法(toHaveBeenCalled()toHaveBeenCalledTimes()toHaveBeenCalledWith())。这种现代化改进了代码的可读性和明确性,符合 Jest 最佳实践。

Also applies to: 872-873, 921-926, 1009-1009, 1631-1631, 1647-1647, 1688-1688, 1751-1754, 1810-1815, 1899-1899, 1922-1927, 1940-1943, 1953-1956, 1982-1985, 2028-2031, 2046-2054, 2142-2155

packages/runtime/src/internal/secret_internals.spec.ts (1)

143-143: LGTM!Jest 断言方法现代化

与其他文件类似,这些更改将 Jest 匹配器方法更新为推荐的形式,提高了测试代码的清晰度和一致性。

Also applies to: 240-240, 494-495, 525-526

package.json (3)

26-27: LGTM!添加 patch-package 支持

新增的 postinstall 脚本和 patch-package 依赖为项目提供了应用补丁文件的能力,这对于修复第三方包问题很有用。trailing comma 的添加也符合代码风格要求。


41-74: LGTM!依赖版本更新

这些依赖更新包括了 Babel、Jest、ESLint、TypeScript 等核心工具的版本升级,与代码库的现代化工作保持一致。新增的 patch-packagepostinstall-postinstall 依赖支持补丁功能。


79-85: LGTM!解析版本同步

resolutions 部分的更新确保了关键依赖(如 Babel parser、runtime 和 React types)在整个项目中使用一致的版本,避免了潜在的版本冲突问题。

Comment on lines +19 to 20
expect(localStorage.getItem).toHaveBeenCalledWith("visit-history");
expect(value).toEqual({ id: "mockId" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

应断言 sessionStorage.getItem 以保持语义准确

当前测试验证的是 sessionStorage 分支,却仍使用 localStorage.getItem 作为断言对象,容易引起误解。建议改为断言 sessionStorage.getItem,并在每个 test 结束后调用 jest.clearAllMocks(),避免跨用例调用次数累积。示例修改:

-    expect(localStorage.getItem).toHaveBeenCalledWith("visit-history");
+    expect(sessionStorage.getItem).toHaveBeenCalledWith("visit-history");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(localStorage.getItem).toHaveBeenCalledWith("visit-history");
expect(value).toEqual({ id: "mockId" });
expect(sessionStorage.getItem).toHaveBeenCalledWith("visit-history");
expect(value).toEqual({ id: "mockId" });
🤖 Prompt for AI Agents
In packages/runtime/src/internal/compute/getStorageItem.spec.ts around lines 19
to 20, the test incorrectly asserts localStorage.getItem instead of
sessionStorage.getItem, which causes semantic confusion since the tested branch
uses sessionStorage. Change the assertion to expect sessionStorage.getItem to
have been called with "visit-history". Additionally, add jest.clearAllMocks() at
the end of each test to prevent mock call counts from accumulating across test
cases.

Comment on lines +66 to 68
expect(applyTheme).not.toHaveBeenCalled();
expect(scrollTo).not.toHaveBeenCalled();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

beforeEach 中清理 mock,避免跨测试计数污染

applyThemescrollToconsoleError 的调用次数在不同测试间累积,
导致第 1 个测试调用 0 次、第 2 个测试期望 1 次、第 3 个测试又期望 0 次时出现互相干扰。
请在 beforeEach 中统一清理所有 mock:

   beforeEach(async () => {
     await i18n.changeLanguage("en");
+    // 防止不同测试之间的调用次数相互影响
+    jest.clearAllMocks();
   });

或显式调用

applyTheme.mockClear();
(window.scrollTo as jest.Mock).mockClear();
consoleError.mockClear();

确保每个 expect(...CalledTimes()) 都仅针对当前测试的调用。

Also applies to: 129-131, 212-215

🤖 Prompt for AI Agents
In packages/runtime/src/createRoot.spec.ts around lines 66 to 68, the mocks for
applyTheme, scrollTo, and consoleError are not cleared before each test, causing
call count interference across tests. Fix this by adding a beforeEach block that
calls mockClear() on applyTheme, window.scrollTo, and consoleError to reset
their call counts before every test, ensuring each
expect(...toHaveBeenCalledTimes()) assertion only reflects calls made during the
current test. Apply the same fix around lines 129-131 and 212-215.

Comment on lines +3 to 5
export enum K {}
// HELLO = "HELLO",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

空枚举导致下游类型全部变为 never,破坏 i18n 类型安全

export enum K {} 会把 K 推断为 never。随后 Localet 都依赖 K,结果无法再传入任何 key,也失去了编译期校验。应至少保留一个键或改用其他方式描述。

-export enum K {}
-// HELLO = "HELLO",
+// TODO: 补充实际文案 key,以下仅示例
+export enum K {
+  HELLO = "HELLO",
+}

若暂时无法确定键,建议移除 K 并把 Locale 改为 Record<string, string>,以免误导。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export enum K {}
// HELLO = "HELLO",
// TODO: 补充实际文案 key,以下仅示例
export enum K {
HELLO = "HELLO",
}
🤖 Prompt for AI Agents
In packages/yo/src/templates/brick/i18n.ts around lines 3 to 5, the empty enum K
causes downstream types to become never, breaking i18n type safety. To fix this,
either define at least one key in the enum K or remove the enum entirely and
change the Locale type to Record<string, string> to avoid misleading type
inference when keys are not yet determined.

Comment on lines +31 to +41
expect(onMessage).toHaveBeenCalledWith("ok");

client.reset();
server.send('"again"');
expect(onMessage).toBeCalledTimes(1);
expect(onMessage).toHaveBeenCalledTimes(1);

client.close();
server.close();

// `onClose` is not called because of reset
expect(onClose).not.toBeCalled();
expect(onClose).not.toHaveBeenCalled();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

👍 新匹配器使用正确,但需注意 spy 污染

toHaveBeenCalledWith / toHaveBeenCalledTimes / not.toHaveBeenCalled 的替换完全符合 Jest 的推荐做法,逻辑无误。不过 consoleLog / consoleError 的 spy 创建在文件最顶层,而 没有beforeEach 清空调用记录;如果后续再新增测试用例,调用次数会跨用例累积,导致断言不稳定。建议在 beforeEach 里清空,或在 afterAlljest.restoreAllMocks()

beforeEach(() => {
  server = new WS(url);
  client = new MessageService(url);
+
+  // 避免不同测试之间相互影响
+  consoleLog.mockClear();
+  consoleError.mockClear();
});
+
+afterAll(() => {
+  jest.restoreAllMocks();
+});

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/easyops-runtime/src/websocket/MessageService.spec.ts around lines 31
to 41, the Jest spies for consoleLog and consoleError are created at the top
level but their call histories are not cleared before each test, causing
potential cross-test pollution and flaky assertions. To fix this, add a
beforeEach hook that clears the call history of these spies using mockClear or
mockReset, or alternatively add an afterAll hook that calls
jest.restoreAllMocks() to restore original implementations after all tests
complete.

Comment on lines +140 to 141
expect(onClose).not.toHaveBeenCalled();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

同样注意 spy 清理

consoleErrorconsole.log 的 spy 在文件作用域创建,但未在各用例之间重置;请在 beforeEachmockClear(),或在最末 afterAll 统一 restoreAllMocks(),与上一文件保持一致。

🤖 Prompt for AI Agents
In packages/easyops-runtime/src/websocket/MessageDispatcher.spec.ts around lines
140 to 141, the spies for consoleError and console.log are created at the file
scope but are not cleared between test cases. To fix this, add mockClear() calls
for these spies in a beforeEach block or call restoreAllMocks() in an afterAll
block at the end of the file to ensure consistent spy cleanup across tests.

@weareoutman weareoutman merged commit e2ccd7a into v3 Jun 24, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant