midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.4k stars 576 forks source link

写单元测试用例的时候 报错 Error: Can not get main framework, please check your configuration.ts. #3117

Closed mynamexjl closed 1 year ago

mynamexjl commented 1 year ago

configuration.ts 内容如下: import { App, Configuration, Inject } from '@midwayjs/decorator'; import { ILifeCycle, IMidwayContainer, MidwayDecoratorService, } from '@midwayjs/core'; // eslint-disable-next-line node/no-extraneous-import import { Application } from 'egg'; import { join } from 'path'; import as oss from '@midwayjs/oss'; import as redis from '@midwayjs/redis'; import as axios from '@midwayjs/axios'; import as validate from '@midwayjs/validate'; import as midwayAuto from '@ali/midway-auto'; // import as typegoose from '@midwayjs/typegoose'; import as swagger from '@midwayjs/swagger'; import as keycenter from '@ali/midway-keycenter'; import { MethodDecorators } from './decorator'; import as bull from '@midwayjs/bull'; import as bullBoard from '@midwayjs/bull-board'; import as orm from '@midwayjs/typeorm'; import as upload from '@midwayjs/upload'; import * as crossDomain from '@midwayjs/cross-domain'; import { MidwayErrorFilter, OtherErrorFilter, ValidateErrorFilter, } from './filter/error';

@Configuration({ imports: [ upload, midwayAuto, oss, redis, // 导入 redis 组件 axios, // http请求 validate, // 参数校验 keycenter, // 加载 keycenter 组件 // typegoose, // 使用mongodb 数据库需要打开这个 bull, // 任务队列 bullBoard, // bull ui orm, // typeorm crossDomain, // 跨域 { component: swagger, // 加载 swagger 组件 enabledEnvironment: ['local'], }, ], importConfigs: [join(__dirname, './config')], }) export class ContainerLifeCycle implements ILifeCycle { @App() app: Application;

@Inject() decoratorService: MidwayDecoratorService;

/**

describe("test/controller/api.test.ts", () => { let app: Application;

beforeAll(async () => { // create app app = await createApp(); });

afterAll(async () => { await close(app); });

it("should POST /ws/midway-demo/get_user", async () => { // make request const result = await createHttpRequest(app) .post("/ws/midway-demo/get_user") .query({ uid: 123 });

// use expect by jest
expect(result.status).toBe(200);
expect(result.body.message).toBe("OK");

}); });

czy88840616 commented 1 year ago

https://midwayjs.org/docs/req_res_app#main-application

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.