Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert more tests to typescript #5379

Merged
merged 18 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master, next ]
pull_request:
branches: [ master ]
branches: [ master, next ]

jobs:
Job:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: [ skip-releases ]
branches: [ next ]

jobs:
release:
Expand Down
60 changes: 0 additions & 60 deletions index-old.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
// import 'egg-onerror';
// import 'egg-session';
// import 'egg-i18n';
// import '@eggjs/watcher';
// import 'egg-multipart';
// import 'egg-security';
// import 'egg-development';
// import 'egg-logrotator';
// import '@eggjs/schedule';
// import 'egg-static';
Expand Down Expand Up @@ -218,30 +216,6 @@

// export type LoggerLevel = EggLoggerLevel;


// /**
// * egg app info
// * @example
// * ```js
// * // config/config.default.ts
// * import { EggAppInfo } from 'egg';
// *
// * export default (appInfo: EggAppInfo) => {
// * return {
// * keys: appInfo.name + '123456',
// * };
// * }
// * ```
// */
// export interface EggAppInfo {
// pkg: any; // package.json
// name: string; // the application name from package.json
// baseDir: string; // current directory of application
// env: EggEnvType; // equals to serverEnv
// HOME: string; // home directory of the OS
// root: string; // baseDir when local and unittest, HOME when other environment
// }

// type IgnoreItem = string | RegExp | ((ctx: Context) => boolean);
// type IgnoreOrMatch = IgnoreItem | IgnoreItem[];

Expand Down Expand Up @@ -1082,40 +1056,6 @@
// urlFor(name: string, params?: PlainObject): string;
// }

// // egg env type
// export type EggEnvType = 'local' | 'unittest' | 'prod' | string;

// /**
// * plugin config item interface
// */
// export interface IEggPluginItem {
// env?: EggEnvType[];
// path?: string;
// package?: string;
// enable?: boolean;
// }

// export type EggPluginItem = IEggPluginItem | boolean;

// /**
// * build-in plugin list
// */
// export interface EggPlugin {
// [key: string]: EggPluginItem | undefined;
// onerror?: EggPluginItem;
// session?: EggPluginItem;
// i18n?: EggPluginItem;
// watcher?: EggPluginItem;
// multipart?: EggPluginItem;
// security?: EggPluginItem;
// development?: EggPluginItem;
// logrotator?: EggPluginItem;
// schedule?: EggPluginItem;
// static?: EggPluginItem;
// jsonp?: EggPluginItem;
// view?: EggPluginItem;
// }

// /**
// * Singleton instance in Agent Worker, extend {@link EggApplication}
// */
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg",
"version": "4.0.0-beta.11",
"version": "4.0.0-beta.15",
"engines": {
"node": ">= 18.19.0"
},
Expand All @@ -21,14 +21,13 @@
"dependencies": {
"@eggjs/cluster": "^3.0.0",
"@eggjs/cookies": "^3.0.0",
"@eggjs/core": "^6.2.5",
"@eggjs/core": "^6.2.13",
"@eggjs/development": "^4.0.0",
"@eggjs/schedule": "^5.0.2",
"@eggjs/utils": "^4.1.5",
"@eggjs/watcher": "^4.0.1",
"@eggjs/utils": "^4.2.4",
"@eggjs/watcher": "^4.0.3",
"circular-json-for-egg": "^1.0.0",
"cluster-client": "^3.7.0",
"delegates": "^1.0.0",
"egg-development": "^3.0.0",
"egg-errors": "^2.3.1",
"egg-i18n": "^2.1.1",
"egg-jsonp": "^2.0.0",
Expand All @@ -46,7 +45,7 @@
"is-type-of": "^2.1.0",
"koa-bodyparser": "^4.4.1",
"koa-override": "^4.0.0",
"onelogger": "^1.0.0",
"onelogger": "^1.0.1",
"performance-ms": "^1.1.0",
"sendmessage": "^3.0.1",
"urllib": "^4.6.11",
Expand All @@ -57,10 +56,9 @@
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/bin": "^7.0.0",
"@eggjs/koa": "^2.19.1",
"@eggjs/mock": "^6.0.3",
"@eggjs/mock": "^6.0.5",
"@eggjs/supertest": "^8.1.1",
"@eggjs/tsconfig": "1",
"@types/delegates": "^1.0.3",
"@types/koa-bodyparser": "^4.3.12",
"@types/mocha": "^10.0.7",
"@types/ms": "^0.7.34",
Expand All @@ -78,7 +76,7 @@
"formstream": "^1.5.1",
"koa-static": "^5.0.0",
"mm": "^3.4.0",
"pedding": "^1.1.0",
"pedding": "^2.0.1",
"prettier": "^2.7.1",
"rimraf": "6",
"runscript": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion site/docs/advanced/loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ All the methods mounted on `beforeClose` are called in an inverted order after `

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

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

### File-Loading Rules

Expand Down
4 changes: 2 additions & 2 deletions site/docs/advanced/loader.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module.exports = AppBootHook;

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

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

### 文件加载规则

Expand Down Expand Up @@ -537,4 +537,4 @@ module.exports = {
参考链接:
- [loader](https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js)
- [appworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/app_worker_loader.js)
- [agentworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/agent_worker_loader.js)
- [agentworkerloader](https://github.com/eggjs/egg/blob/master/lib/loader/agent_worker_loader.js)
4 changes: 2 additions & 2 deletions site/docs/basics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ Specific consolidation rules can be found in [Configuration](./config.md).
  - [onerror](https://github.com/eggjs/egg-onerror) Uniform Exception Handling
  - [Session](https://github.com/eggjs/egg-session) Session implementation
  - [i18n](https://github.com/eggjs/egg-i18n) Multilingual
  - [watcher](https://github.com/eggjs/egg-watcher) File and folder monitoring
  - [watcher](https://github.com/eggjs/watcher) File and folder monitoring
  - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload
  - [security](https://github.com/eggjs/egg-security) Security
  - [development](https://github.com/eggjs/egg-development) Development Environment Configuration
  - [development](https://github.com/eggjs/development) Development Environment Configuration
  - [logrotator](https://github.com/eggjs/egg-logrotator) Log segmentation
  - [schedule](https://github.com/eggjs/egg-schedule) Timing tasks
  - [static](https://github.com/eggjs/egg-static) Static server
Expand Down
4 changes: 2 additions & 2 deletions site/docs/basics/plugin.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ exports.mysql = {
- [onerror](https://github.com/eggjs/egg-onerror) 统一异常处理
- [Session](https://github.com/eggjs/egg-session) Session 实现
- [i18n](https://github.com/eggjs/egg-i18n) 多语言
- [watcher](https://github.com/eggjs/egg-watcher) 文件和文件夹监控
- [watcher](https://github.com/eggjs/watcher) 文件和文件夹监控
- [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传
- [security](https://github.com/eggjs/egg-security) 安全
- [development](https://github.com/eggjs/egg-development) 开发环境配置
- [development](https://github.com/eggjs/development) 开发环境配置
- [logrotator](https://github.com/eggjs/egg-logrotator) 日志切分
- [schedule](https://github.com/eggjs/egg-schedule) 定时任务
- [static](https://github.com/eggjs/egg-static) 静态服务器
Expand Down
2 changes: 1 addition & 1 deletion site/docs/core/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ And then we may start app by `npm run dev`.

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`.

> 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)
> 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)
### About `Reload`

Expand Down
2 changes: 1 addition & 1 deletion site/docs/core/development.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $ npm i egg-bin --save-dev

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

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

Expand Down
39 changes: 19 additions & 20 deletions site/docs/intro/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ To begin with, let's quickly initialize the project by using a scaffold,
which will quickly generate some of the major pieces of the application (`npm >=6.1.0`).

```bash
$ mkdir egg-example && cd egg-example
$ npm init egg --type=simple
$ npm i
mkdir egg-example && cd egg-example
npm init egg --type=simple
npm i
```

Then get up and run by using the following commands.

```bash
$ npm run dev
$ open http://localhost:7001
npm run dev
open http://localhost:7001
```

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

```bash
$ mkdir egg-example
$ cd egg-example
$ npm init
$ npm i egg --save
$ npm i egg-bin --save-dev
mkdir egg-example
cd egg-example
npm init
npm i egg --save
npm i egg-bin --save-dev
```

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

```bash
$ npm run dev
$ open http://localhost:7001
npm run dev
open http://localhost:7001
```

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

```bash
$ npm i egg-view-nunjucks --save
npm i egg-view-nunjucks --save
```

And enable it.
Expand Down Expand Up @@ -236,10 +236,10 @@ module.exports = (app) => {
};
```

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

**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.**
**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.**

### Create a Service

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

```bash
$ npm i moment --save
npm i moment --save
```

```js
Expand Down Expand Up @@ -452,13 +452,13 @@ Then add `npm scripts`.
Also install dependencies.

```bash
$ npm i egg-mock --save-dev
npm i egg-mock --save-dev
```

Run it.

```bash
$ npm test
npm test
```

That is all of it, for more detail, see [Unit Testing](../core/unittest.md).
Expand All @@ -477,7 +477,6 @@ Where to go from here? read our documentation to better understand the framework
[node.js]: http://nodejs.org
[egg-bin]: https://github.com/eggjs/egg-bin
[egg-static]: https://github.com/eggjs/egg-static
[egg-development]: https://github.com/eggjs/egg-development
[@eggjs/development]: https://github.com/eggjs/development
[egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks
[urllib]: https://www.npmjs.com/package/urllib
[nunjucks]: https://mozilla.github.io/nunjucks/
7 changes: 4 additions & 3 deletions site/docs/intro/quickstart.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ module.exports = app => {

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

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

### 编写 Service

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