https://github.com/midwayjs/egg-mock-util
mock egg app for midway component
https://github.com/midwayjs/egg-mock-util
Last synced: over 1 year ago
JSON representation
mock egg app for midway component
- Host: GitHub
- URL: https://github.com/midwayjs/egg-mock-util
- Owner: midwayjs
- Created: 2021-09-26T03:31:21.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T03:54:49.000Z (over 3 years ago)
- Last Synced: 2024-04-25T15:44:34.977Z (about 2 years ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
# egg mock util
将 egg 插件变为 midway 组件的工具包,包含两个方法。
使用方式如下,比如在 configuration 里,由于 egg 的目录是固定的,所以使用文件加载的形式直接执行即可。
```ts
import { completeAssign, createMockApp } from '@midwayjs/mw-util';
export class AutConfiguration {
@App()
app;
async onReady() {
// 创建一个 egg 认识的模拟 app
const mockApp = createMockApp(this.app);
// 执行 egg 的 app.js 中的方法
require('@ali/egg-********/app')(mockApp);
// 执行 beforeStart 方法
await Promise.all(mockApp.getBeforeStartList());
// 可选:将 egg 赋到 app 上的对象拿到,比如赋给 midway 的 app
this.app.changefree = mockApp.changefree;
// 用于合并 egg 的 context 方法,这样就有 ctx.xxx 方法了
completeAssign(
this.app.context,
require('@ali/egg--********//app/extend/context')
);
}
}
```