-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
437e92d
commit 99c9507
Showing
2 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
slug: release/3.19.0 | ||
title: Release 3.19.0 | ||
authors: [harry] | ||
tags: [release] | ||
|
||
--- | ||
|
||
升级请参考 [如何更新 Midway](/docs/how_to_update_midway) 中描述,请不要单独升级某个组件包。 | ||
|
||
本次 3.19 版本,主要引入了 Kafka 组件的重构,以及一些性能优化和 bug 修复。 | ||
|
||
下面是更为细节的描述。 | ||
|
||
## Kafka 组件重构 | ||
|
||
从 v3.19 开始,Kafka 组件进行了重构,配置和使用方法与之前有较大差异。虽然原有的使用方式仍然兼容,但文档不再保留。新的 Kafka 组件提供了更灵活的配置和更强大的功能。 | ||
|
||
```typescript | ||
// src/config/config.default.ts | ||
export default { | ||
kafka: { | ||
consumer: { | ||
sub1: { | ||
connectionOptions: { | ||
clientId: 'my-app', | ||
brokers: ['localhost:9092'], | ||
}, | ||
consumerOptions: { | ||
groupId: 'groupId-test-1', | ||
}, | ||
subscribeOptions: { | ||
topics: ['topic-test-1'], | ||
} | ||
}, | ||
}, | ||
producer: { | ||
clients: { | ||
pub1: { | ||
connectionOptions: { | ||
clientId: 'my-app', | ||
brokers: ['localhost:9092'], | ||
}, | ||
producerOptions: { | ||
// ... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
更多的内容,请参考 [Kafka 组件文档](/docs/extensions/kafka)。 | ||
|
||
## Mock 功能分组 | ||
|
||
从 `3.19.0` 开始,Midway 的 mock 功能支持通过分组来管理不同的 mock 数据。你可以在创建 mock 时指定一个分组名称,这样可以在需要时单独恢复或清理某个分组的 mock 数据。 | ||
|
||
```typescript | ||
import { mockContext, restoreMocks } from '@midwayjs/mock'; | ||
|
||
it('should test mock with groups', async () => { | ||
const app = await createApp(); | ||
|
||
// 创建普通对象的 mock | ||
const a = {}; | ||
mockProperty(a, 'getUser', async () => { | ||
return 'midway'; | ||
}, 'group1'); | ||
|
||
// 创建上下文的 mock | ||
mockContext(app, 'user', 'midway', 'group1'); | ||
mockContext(app, 'role', 'admin', 'group2'); | ||
|
||
// 恢复单个分组 | ||
restoreMocks('group1'); | ||
|
||
// 恢复所有分组 | ||
restoreAllMocks(); | ||
}); | ||
``` | ||
|
||
通过分组,你可以更灵活地管理和控制 mock 数据,特别是在复杂的测试场景中。 | ||
|
||
## 新增了一个启动性能分析的命令 | ||
|
||
在开发环境下,新增了一个 `perf-init` 命令,用于在启动时初始化性能分析,需要配合最新的 `mwtsc` 一同使用。 | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app.js --perf-init" | ||
} | ||
} | ||
``` | ||
|
||
|
||
## 其他更新 | ||
|
||
* 更新了一些依赖库以提高安全性和稳定性。 | ||
|
||
更多的更新内容和详细信息,请参考我们的 [ChangeLog](https://midwayjs.org/changelog/v3.19.0)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters