@midwayjs/mock 3.0.0 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  import { IMidwayApplication } from '@midwayjs/core';
2
2
  import * as request from 'supertest';
3
- export declare function createHttpRequest(app: IMidwayApplication): request.SuperTest<request.Test>;
3
+ export declare function createHttpRequest<T extends IMidwayApplication<any>>(app: T): request.SuperTest<request.Test>;
4
4
  //# sourceMappingURL=http.d.ts.map
package/dist/creator.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
2
2
  import { ComponentModule, MockAppConfigurationOptions } from './interface';
3
- export declare function create<T extends IMidwayFramework<any, any, U>, U = T['configurationOptions']>(appDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
3
+ export declare function create<T extends IMidwayFramework<any, any, any, any, any>>(appDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
4
4
  new (...args: any[]): T;
5
5
  } | ComponentModule): Promise<T>;
6
- export declare function createApp<T extends IMidwayFramework<any, any, U>, U = T['configurationOptions'], Y = ReturnType<T['getApplication']>>(baseDir?: string, options?: U & MockAppConfigurationOptions, customFramework?: {
6
+ export declare function createApp<T extends IMidwayFramework<any, any, any, any, any>>(baseDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
7
7
  new (...args: any[]): T;
8
- } | ComponentModule): Promise<IMidwayApplication<any, any>>;
9
- export declare function close(app: IMidwayApplication, options?: {
8
+ } | ComponentModule): Promise<ReturnType<T['getApplication']>>;
9
+ export declare function close<T extends IMidwayApplication<any>>(app: T, options?: {
10
10
  cleanLogsDir?: boolean;
11
11
  cleanTempDir?: boolean;
12
12
  sleep?: number;
13
13
  }): Promise<void>;
14
- export declare function createFunctionApp<T extends IMidwayFramework<any, any, U>, U = T['configurationOptions'], Y = ReturnType<T['getApplication']>>(baseDir?: string, options?: MockAppConfigurationOptions, customFrameworkName?: {
14
+ export declare function createFunctionApp<T extends IMidwayFramework<any, any, any, any, any>, Y = ReturnType<T['getApplication']>>(baseDir?: string, options?: MockAppConfigurationOptions, customFrameworkModule?: {
15
15
  new (...args: any[]): T;
16
16
  } | ComponentModule): Promise<Y>;
17
17
  /**
package/dist/creator.js CHANGED
@@ -111,18 +111,26 @@ async function close(app, options) {
111
111
  }
112
112
  }
113
113
  exports.close = close;
114
- async function createFunctionApp(baseDir = process.cwd(), options, customFrameworkName) {
115
- const customFramework = customFrameworkName !== null && customFrameworkName !== void 0 ? customFrameworkName : (0, utils_1.findFirstExistModule)([
114
+ async function createFunctionApp(baseDir = process.cwd(), options, customFrameworkModule) {
115
+ const customFramework = customFrameworkModule !== null && customFrameworkModule !== void 0 ? customFrameworkModule : (0, utils_1.findFirstExistModule)([
116
116
  process.env.MIDWAY_SERVERLESS_APP_NAME,
117
117
  '@ali/serverless-app',
118
118
  '@midwayjs/serverless-app',
119
119
  ]);
120
- const framework = await createApp(baseDir, {
121
- ...options,
122
- imports: (0, utils_1.transformFrameworkToConfiguration)(customFramework),
123
- }, customFrameworkName);
124
- framework.configurationOptions = options;
125
- return framework;
120
+ const serverlessModule = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
121
+ if (serverlessModule) {
122
+ if (options && options.imports) {
123
+ options.imports.unshift(serverlessModule);
124
+ }
125
+ else {
126
+ options = {};
127
+ options.imports = [serverlessModule];
128
+ }
129
+ }
130
+ const framework = await createApp(baseDir, options);
131
+ const appCtx = framework.getApplicationContext();
132
+ const appManager = appCtx.get(core_1.MidwayApplicationManager);
133
+ return appManager.getApplication(core_1.MidwayFrameworkType.SERVERLESS_APP);
126
134
  }
127
135
  exports.createFunctionApp = createFunctionApp;
128
136
  /**
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { IMidwayFramework } from '@midwayjs/core';
2
+ import { ComponentModule } from './interface';
2
3
  export declare function isTestEnvironment(): boolean;
3
4
  export declare function isWin32(): boolean;
4
- export declare function findFirstExistModule(moduleList: any): string;
5
+ export declare function findFirstExistModule(moduleList: any): ComponentModule;
5
6
  /**
6
7
  * transform a framework component or framework module to configuration class
7
8
  * @param Framework
package/dist/utils.js CHANGED
@@ -27,8 +27,7 @@ function findFirstExistModule(moduleList) {
27
27
  if (!name)
28
28
  continue;
29
29
  try {
30
- require.resolve(name);
31
- return name;
30
+ return require(name);
32
31
  }
33
32
  catch (e) {
34
33
  // ignore
@@ -41,6 +40,8 @@ exports.findFirstExistModule = findFirstExistModule;
41
40
  * @param Framework
42
41
  */
43
42
  function transformFrameworkToConfiguration(Framework) {
43
+ if (!Framework)
44
+ return null;
44
45
  let CustomFramework = Framework;
45
46
  if (typeof Framework === 'string') {
46
47
  Framework = (0, core_1.safeRequire)(Framework);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mock",
3
- "version": "3.0.0",
3
+ "version": "3.0.4",
4
4
  "description": "create your test app from midway framework",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -26,16 +26,17 @@
26
26
  },
27
27
  "license": "MIT",
28
28
  "devDependencies": {
29
- "@midwayjs/core": "^3.0.0",
30
- "@midwayjs/decorator": "^3.0.0",
31
- "@midwayjs/logger": "2.14.0",
32
- "@types/amqplib": "*",
33
- "amqplib": "*",
29
+ "@midwayjs/core": "^3.0.4",
30
+ "@midwayjs/decorator": "^3.0.4",
31
+ "@midwayjs/logger": "^2.15.0",
32
+ "@types/amqplib": "0.8.2",
33
+ "amqplib": "0.8.0",
34
34
  "socket.io": "4.4.1",
35
35
  "socket.io-client": "4.4.1",
36
- "ws": "8.4.0"
36
+ "ws": "8.5.0"
37
37
  },
38
38
  "dependencies": {
39
+ "@types/supertest": "2.0.11",
39
40
  "fs-extra": "10.0.0",
40
41
  "supertest": "6.2.2"
41
42
  },
@@ -44,5 +45,5 @@
44
45
  "type": "git",
45
46
  "url": "http://github.com/midwayjs/midway.git"
46
47
  },
47
- "gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
48
+ "gitHead": "c2a37dd026c7bf3e855f4498691f572ef61396e3"
48
49
  }