Giter Site home page Giter Site logo

egg-mock-util's Introduction

egg mock util

将 egg 插件变为 midway 组件的工具包,包含两个方法。

使用方式如下,比如在 configuration 里,由于 egg 的目录是固定的,所以使用文件加载的形式直接执行即可。

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')
    );
  }
}

egg-mock-util's People

Contributors

czy88840616 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.