Skip to content

Commit 562d76a

Browse files
authored
refactor: convert more tests to typescript (#5379)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit Based on the comprehensive summary, here are the high-level release notes for end-users: - **New Features** - Enhanced logging capabilities with more detailed performance timers. - Improved error handling with new custom error classes. - More robust context and request/response type management. - New methods for accessing logger instances and locals in the context interface. - Introduction of new HTTP client and context types. - **Bug Fixes** - Resolved issues with context delegation and type safety. - Improved handling of asynchronous operations and promise rejections. - **Performance** - Optimized HTTP client and messenger implementations. - Enhanced timing and performance tracking mechanisms. - **Breaking Changes** - Significant updates to context type handling. - Changes in plugin configuration and import mechanisms. - Modifications to how context and request/response objects are managed. These release notes provide a concise overview of the key changes in the framework, focusing on user-facing improvements and potential impacts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e440fad commit 562d76a

File tree

152 files changed

+2671
-2285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+2671
-2285
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, next ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, next ]
88

99
jobs:
1010
Job:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Release
22

33
on:
44
push:
5-
branches: [ skip-releases ]
5+
branches: [ next ]
66

77
jobs:
88
release:

index-old.d.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
// import 'egg-onerror';
3636
// import 'egg-session';
3737
// import 'egg-i18n';
38-
// import '@eggjs/watcher';
3938
// import 'egg-multipart';
4039
// import 'egg-security';
41-
// import 'egg-development';
4240
// import 'egg-logrotator';
4341
// import '@eggjs/schedule';
4442
// import 'egg-static';
@@ -218,30 +216,6 @@
218216

219217
// export type LoggerLevel = EggLoggerLevel;
220218

221-
222-
// /**
223-
// * egg app info
224-
// * @example
225-
// * ```js
226-
// * // config/config.default.ts
227-
// * import { EggAppInfo } from 'egg';
228-
// *
229-
// * export default (appInfo: EggAppInfo) => {
230-
// * return {
231-
// * keys: appInfo.name + '123456',
232-
// * };
233-
// * }
234-
// * ```
235-
// */
236-
// export interface EggAppInfo {
237-
// pkg: any; // package.json
238-
// name: string; // the application name from package.json
239-
// baseDir: string; // current directory of application
240-
// env: EggEnvType; // equals to serverEnv
241-
// HOME: string; // home directory of the OS
242-
// root: string; // baseDir when local and unittest, HOME when other environment
243-
// }
244-
245219
// type IgnoreItem = string | RegExp | ((ctx: Context) => boolean);
246220
// type IgnoreOrMatch = IgnoreItem | IgnoreItem[];
247221

@@ -1082,40 +1056,6 @@
10821056
// urlFor(name: string, params?: PlainObject): string;
10831057
// }
10841058

1085-
// // egg env type
1086-
// export type EggEnvType = 'local' | 'unittest' | 'prod' | string;
1087-
1088-
// /**
1089-
// * plugin config item interface
1090-
// */
1091-
// export interface IEggPluginItem {
1092-
// env?: EggEnvType[];
1093-
// path?: string;
1094-
// package?: string;
1095-
// enable?: boolean;
1096-
// }
1097-
1098-
// export type EggPluginItem = IEggPluginItem | boolean;
1099-
1100-
// /**
1101-
// * build-in plugin list
1102-
// */
1103-
// export interface EggPlugin {
1104-
// [key: string]: EggPluginItem | undefined;
1105-
// onerror?: EggPluginItem;
1106-
// session?: EggPluginItem;
1107-
// i18n?: EggPluginItem;
1108-
// watcher?: EggPluginItem;
1109-
// multipart?: EggPluginItem;
1110-
// security?: EggPluginItem;
1111-
// development?: EggPluginItem;
1112-
// logrotator?: EggPluginItem;
1113-
// schedule?: EggPluginItem;
1114-
// static?: EggPluginItem;
1115-
// jsonp?: EggPluginItem;
1116-
// view?: EggPluginItem;
1117-
// }
1118-
11191059
// /**
11201060
// * Singleton instance in Agent Worker, extend {@link EggApplication}
11211061
// */

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egg",
3-
"version": "4.0.0-beta.11",
3+
"version": "4.0.0-beta.15",
44
"engines": {
55
"node": ">= 18.19.0"
66
},
@@ -21,14 +21,13 @@
2121
"dependencies": {
2222
"@eggjs/cluster": "^3.0.0",
2323
"@eggjs/cookies": "^3.0.0",
24-
"@eggjs/core": "^6.2.5",
24+
"@eggjs/core": "^6.2.13",
25+
"@eggjs/development": "^4.0.0",
2526
"@eggjs/schedule": "^5.0.2",
26-
"@eggjs/utils": "^4.1.5",
27-
"@eggjs/watcher": "^4.0.1",
27+
"@eggjs/utils": "^4.2.4",
28+
"@eggjs/watcher": "^4.0.3",
2829
"circular-json-for-egg": "^1.0.0",
2930
"cluster-client": "^3.7.0",
30-
"delegates": "^1.0.0",
31-
"egg-development": "^3.0.0",
3231
"egg-errors": "^2.3.1",
3332
"egg-i18n": "^2.1.1",
3433
"egg-jsonp": "^2.0.0",
@@ -46,7 +45,7 @@
4645
"is-type-of": "^2.1.0",
4746
"koa-bodyparser": "^4.4.1",
4847
"koa-override": "^4.0.0",
49-
"onelogger": "^1.0.0",
48+
"onelogger": "^1.0.1",
5049
"performance-ms": "^1.1.0",
5150
"sendmessage": "^3.0.1",
5251
"urllib": "^4.6.11",
@@ -57,10 +56,9 @@
5756
"@arethetypeswrong/cli": "^0.17.1",
5857
"@eggjs/bin": "^7.0.0",
5958
"@eggjs/koa": "^2.19.1",
60-
"@eggjs/mock": "^6.0.3",
59+
"@eggjs/mock": "^6.0.5",
6160
"@eggjs/supertest": "^8.1.1",
6261
"@eggjs/tsconfig": "1",
63-
"@types/delegates": "^1.0.3",
6462
"@types/koa-bodyparser": "^4.3.12",
6563
"@types/mocha": "^10.0.7",
6664
"@types/ms": "^0.7.34",
@@ -78,7 +76,7 @@
7876
"formstream": "^1.5.1",
7977
"koa-static": "^5.0.0",
8078
"mm": "^3.4.0",
81-
"pedding": "^1.1.0",
79+
"pedding": "^2.0.1",
8280
"prettier": "^2.7.1",
8381
"rimraf": "6",
8482
"runscript": "^2.0.1",

site/docs/advanced/loader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ All the methods mounted on `beforeClose` are called in an inverted order after `
266266

267267
**We don't recommend to use this function in a PROD env, because the process may end before it finishes.**
268268

269-
What's more, we can use [`egg-development`](https://github.com/eggjs/egg-development#loader-trace) to see the loading process.
269+
What's more, we can use [`@eggjs/development`](https://github.com/eggjs/development#loader-trace) to see the loading process.
270270

271271
### File-Loading Rules
272272

site/docs/advanced/loader.zh-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ module.exports = AppBootHook;
270270

271271
**此方法不建议在生产环境使用,因可能会出现未完全执行结束就结束进程的情况。**
272272

273-
另外,我们可以使用 [`egg-development`](https://github.com/eggjs/egg-development#loader-trace) 来查看加载过程。
273+
另外,我们可以使用 [`@eggjs/development`](https://github.com/eggjs/development#loader-trace) 来查看加载过程。
274274

275275
### 文件加载规则
276276

@@ -537,4 +537,4 @@ module.exports = {
537537
参考链接:
538538
- [loader](https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js)
539539
- [appworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/app_worker_loader.js)
540-
- [agentworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/agent_worker_loader.js)
540+
- [agentworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/agent_worker_loader.js)

site/docs/basics/plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ Specific consolidation rules can be found in [Configuration](./config.md).
163163
  - [onerror](https://github.com/eggjs/egg-onerror) Uniform Exception Handling
164164
  - [Session](https://github.com/eggjs/egg-session) Session implementation
165165
  - [i18n](https://github.com/eggjs/egg-i18n) Multilingual
166-
  - [watcher](https://github.com/eggjs/egg-watcher) File and folder monitoring
166+
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring
167167
  - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload
168168
  - [security](https://github.com/eggjs/egg-security) Security
169-
  - [development](https://github.com/eggjs/egg-development) Development Environment Configuration
169+
  - [development](https://github.com/eggjs/development) Development Environment Configuration
170170
  - [logrotator](https://github.com/eggjs/egg-logrotator) Log segmentation
171171
  - [schedule](https://github.com/eggjs/egg-schedule) Timing tasks
172172
  - [static](https://github.com/eggjs/egg-static) Static server

site/docs/basics/plugin.zh-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ exports.mysql = {
163163
- [onerror](https://github.com/eggjs/egg-onerror) 统一异常处理
164164
- [Session](https://github.com/eggjs/egg-session) Session 实现
165165
- [i18n](https://github.com/eggjs/egg-i18n) 多语言
166-
- [watcher](https://github.com/eggjs/egg-watcher) 文件和文件夹监控
166+
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控
167167
- [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传
168168
- [security](https://github.com/eggjs/egg-security) 安全
169-
- [development](https://github.com/eggjs/egg-development) 开发环境配置
169+
- [development](https://github.com/eggjs/development) 开发环境配置
170170
- [logrotator](https://github.com/eggjs/egg-logrotator) 日志切分
171171
- [schedule](https://github.com/eggjs/egg-schedule) 定时任务
172172
- [static](https://github.com/eggjs/egg-static) 静态服务器

site/docs/core/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ And then we may start app by `npm run dev`.
3535

3636
To start app in local, environment needs to be set as `env: local`. The configuration comes from the combination of both `config.local.js` and `config.default.js`.
3737

38-
> Note: The local development environment relies on 'egg-development' module, enabled by default, and closed other environment, Configuration reference [config/config.default.js](https://github.com/eggjs/egg-development/blob/master/config/config.default.js)
38+
> Note: The local development environment relies on '@eggjs/development' module, enabled by default, and closed other environment, Configuration reference [config/config.default.ts](https://github.com/eggjs/development/blob/master/src/config/config.default.ts)
3939
4040
### About `Reload`
4141

site/docs/core/development.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ npm i egg-bin --save-dev
3535

3636
本地启动的应用是以 `env: local` 启动的,读取的配置是 `config.default.js``config.local.js` 合并的结果。
3737

38-
> 注意:本地开发环境依赖 `egg-development` 插件,该插件默认开启,而在其他环境下关闭。配置参考 [config/config.default.js](https://github.com/eggjs/egg-development/blob/master/config/config.default.js)
38+
> 注意:本地开发环境依赖 `@eggjs/development` 插件,该插件默认开启,而在其他环境下关闭。配置参考 [config/config.default.ts](https://github.com/eggjs/development/blob/master/src/config/config.default.ts)
3939
4040
### 关于 `Reload` 功能
4141

site/docs/intro/quickstart.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ To begin with, let's quickly initialize the project by using a scaffold,
1717
which will quickly generate some of the major pieces of the application (`npm >=6.1.0`).
1818

1919
```bash
20-
$ mkdir egg-example && cd egg-example
21-
$ npm init egg --type=simple
22-
$ npm i
20+
mkdir egg-example && cd egg-example
21+
npm init egg --type=simple
22+
npm i
2323
```
2424

2525
Then get up and run by using the following commands.
2626

2727
```bash
28-
$ npm run dev
29-
$ open http://localhost:7001
28+
npm run dev
29+
open http://localhost:7001
3030
```
3131

3232
## Step by Step
@@ -44,11 +44,11 @@ However, in this section, instead of using scaffolds we will build a project cal
4444
First let's create the project directory and initialize its structure.
4545

4646
```bash
47-
$ mkdir egg-example
48-
$ cd egg-example
49-
$ npm init
50-
$ npm i egg --save
51-
$ npm i egg-bin --save-dev
47+
mkdir egg-example
48+
cd egg-example
49+
npm init
50+
npm i egg --save
51+
npm i egg-bin --save-dev
5252
```
5353

5454
Then add `npm scripts` to `package.json`.
@@ -116,8 +116,8 @@ For more information about directory structure, see [Directory Structure](../bas
116116
Now you can start up the Web Server and see your application in action.
117117

118118
```bash
119-
$ npm run dev
120-
$ open http://localhost:7001
119+
npm run dev
120+
open http://localhost:7001
121121
```
122122

123123
> Note:
@@ -159,7 +159,7 @@ In this example, we will use [Nunjucks].
159159
First install the corresponding plugin [egg-view-nunjucks].
160160

161161
```bash
162-
$ npm i egg-view-nunjucks --save
162+
npm i egg-view-nunjucks --save
163163
```
164164

165165
And enable it.
@@ -236,10 +236,10 @@ module.exports = (app) => {
236236
};
237237
```
238238

239-
Open a browser window and navigate to http://localhost:7001/news.
239+
Open a browser window and navigate to <http://localhost:7001/news>.
240240
You should be able to see the rendered page.
241241

242-
**Tip:In development, Egg enables the [development][egg-development] plugin by default, which reloads your worker process when changes are made to your back-end code.**
242+
**Tip:In development, Egg enables the [development][@eggjs/development] plugin by default, which reloads your worker process when changes are made to your back-end code.**
243243

244244
### Create a Service
245245

@@ -331,7 +331,7 @@ For more information, cf. [Extensions](../basics/extend.md).
331331
In the case of view, we can just write a helper as an extension.
332332

333333
```bash
334-
$ npm i moment --save
334+
npm i moment --save
335335
```
336336

337337
```js
@@ -452,13 +452,13 @@ Then add `npm scripts`.
452452
Also install dependencies.
453453

454454
```bash
455-
$ npm i egg-mock --save-dev
455+
npm i egg-mock --save-dev
456456
```
457457

458458
Run it.
459459

460460
```bash
461-
$ npm test
461+
npm test
462462
```
463463

464464
That is all of it, for more detail, see [Unit Testing](../core/unittest.md).
@@ -477,7 +477,6 @@ Where to go from here? read our documentation to better understand the framework
477477
[node.js]: http://nodejs.org
478478
[egg-bin]: https://github.com/eggjs/egg-bin
479479
[egg-static]: https://github.com/eggjs/egg-static
480-
[egg-development]: https://github.com/eggjs/egg-development
480+
[@eggjs/development]: https://github.com/eggjs/development
481481
[egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks
482-
[urllib]: https://www.npmjs.com/package/urllib
483482
[nunjucks]: https://mozilla.github.io/nunjucks/

site/docs/intro/quickstart.zh-CN.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ module.exports = app => {
228228

229229
在浏览器中启动并访问 [http://localhost:7001/news](http://localhost:7001/news) 即可看到渲染后的页面。
230230

231-
**提示:** 开发期默认开启了 [development][egg-development] 插件,修改后端代码后,会自动重启 Worker 进程。
231+
**提示:** 开发期默认开启了 [development][@eggjs/development] 插件,修改后端代码后,会自动重启 Worker 进程。
232+
232233
### 编写 Service
233234

234235
在实际应用中,Controller 一般不会自己产出数据,也不会包含复杂的逻辑,复杂的过程应抽象为业务逻辑层 [Service](../basics/service.md)
@@ -456,7 +457,7 @@ $ npm test
456457
[node.js]: http://nodejs.org
457458
[egg-bin]: https://github.com/eggjs/egg-bin
458459
[egg-static]: https://github.com/eggjs/egg-static
459-
[egg-development]: https://github.com/eggjs/egg-development
460+
[@eggjs/development]: https://github.com/eggjs/development
460461
[egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks
461462
[urllib]: https://www.npmjs.com/package/urllib
462-
[nunjucks]: https://mozilla.github.io/nunjucks/
463+
[nunjucks]: https://mozilla.github.io/nunjucks/

0 commit comments

Comments
 (0)