@midwayjs/mock 3.11.9 → 3.11.10

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.
package/dist/creator.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { IMidwayApplication, IMidwayFramework, MidwayFrameworkType } from '@midwayjs/core';
2
- import { ComponentModule, MockAppConfigurationOptions } from './interface';
1
+ import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
2
+ import { ComponentModule, MockAppConfigurationOptions, IBootstrapAppStarter } from './interface';
3
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
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
8
  } | ComponentModule): Promise<ReturnType<T['getApplication']>>;
9
- export declare function close<T extends IMidwayApplication<any>>(app: T, options?: {
9
+ export declare function close(app: IMidwayApplication<any> | {
10
+ close: (...args: any[]) => void;
11
+ }, options?: {
10
12
  cleanLogsDir?: boolean;
11
13
  cleanTempDir?: boolean;
12
14
  sleep?: number;
@@ -14,18 +16,11 @@ export declare function close<T extends IMidwayApplication<any>>(app: T, options
14
16
  export declare function createFunctionApp<T extends IMidwayFramework<any, any, any, any, any>, Y = ReturnType<T['getApplication']>>(baseDir?: string | MockAppConfigurationOptions, options?: MockAppConfigurationOptions, customFrameworkModule?: {
15
17
  new (...args: any[]): T;
16
18
  } | ComponentModule): Promise<Y>;
17
- declare class BootstrapAppStarter {
18
- getApp(type: MidwayFrameworkType | string): IMidwayApplication<any>;
19
- close(options?: {
20
- sleep?: number;
21
- }): Promise<void>;
22
- }
23
19
  /**
24
20
  * Create a real project but not ready or a virtual project
25
21
  * @param baseDir
26
22
  * @param options
27
23
  */
28
24
  export declare function createLightApp(baseDir?: string, options?: MockAppConfigurationOptions): Promise<IMidwayApplication>;
29
- export declare function createBootstrap(entryFile: string, options?: MockAppConfigurationOptions): Promise<BootstrapAppStarter>;
30
- export {};
25
+ export declare function createBootstrap(entryFile: string, options?: MockAppConfigurationOptions): Promise<IBootstrapAppStarter>;
31
26
  //# sourceMappingURL=creator.d.ts.map
package/dist/creator.js CHANGED
@@ -155,24 +155,31 @@ exports.createApp = createApp;
155
155
  async function close(app, options) {
156
156
  if (!app)
157
157
  return;
158
- debug(`[mock]: Closing app, appDir=${app.getAppDir()}`);
159
- options = options || {};
160
- await (0, core_1.destroyGlobalApplicationContext)(app.getApplicationContext());
161
- if ((0, utils_1.isTestEnvironment)()) {
162
- // clean first
163
- if (options.cleanLogsDir && !(0, utils_1.isWin32)()) {
164
- await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'logs'));
165
- }
166
- if (core_1.MidwayFrameworkType.WEB === app.getFrameworkType()) {
167
- if (options.cleanTempDir && !(0, utils_1.isWin32)()) {
168
- await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'run'));
158
+ if (app instanceof BootstrapAppStarter ||
159
+ (typeof app['close'] === 'function' && !app['getConfig'])) {
160
+ await app['close'](options);
161
+ }
162
+ else {
163
+ app = app;
164
+ debug(`[mock]: Closing app, appDir=${app.getAppDir()}`);
165
+ options = options || {};
166
+ await (0, core_1.destroyGlobalApplicationContext)(app.getApplicationContext());
167
+ if ((0, utils_1.isTestEnvironment)()) {
168
+ // clean first
169
+ if (options.cleanLogsDir && !(0, utils_1.isWin32)()) {
170
+ await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'logs'));
171
+ }
172
+ if (core_1.MidwayFrameworkType.WEB === app.getFrameworkType()) {
173
+ if (options.cleanTempDir && !(0, utils_1.isWin32)()) {
174
+ await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'run'));
175
+ }
176
+ }
177
+ if (options.sleep > 0) {
178
+ await (0, core_1.sleep)(options.sleep);
179
+ }
180
+ else {
181
+ await (0, core_1.sleep)(50);
169
182
  }
170
- }
171
- if (options.sleep > 0) {
172
- await (0, core_1.sleep)(options.sleep);
173
- }
174
- else {
175
- await (0, core_1.sleep)(50);
176
183
  }
177
184
  }
178
185
  }
@@ -431,7 +438,12 @@ exports.createLightApp = createLightApp;
431
438
  async function createBootstrap(entryFile, options = {}) {
432
439
  if ((0, core_1.safeRequire)('@midwayjs/faas')) {
433
440
  options.entryFile = entryFile;
434
- return createFunctionApp(process.cwd(), options);
441
+ const app = await createFunctionApp(process.cwd(), options);
442
+ return {
443
+ close: async () => {
444
+ return close(app);
445
+ },
446
+ };
435
447
  }
436
448
  else {
437
449
  await create(undefined, {
@@ -1,4 +1,4 @@
1
- import { IMidwayBootstrapOptions } from '@midwayjs/core';
1
+ import { IMidwayApplication, IMidwayBootstrapOptions, MidwayFrameworkType } from '@midwayjs/core';
2
2
  export interface MockAppConfigurationOptions extends IMidwayBootstrapOptions {
3
3
  cleanLogsDir?: boolean;
4
4
  cleanTempDir?: boolean;
@@ -8,4 +8,10 @@ export interface MockAppConfigurationOptions extends IMidwayBootstrapOptions {
8
8
  export type ComponentModule = {
9
9
  Configuration: new () => any;
10
10
  };
11
+ export interface IBootstrapAppStarter {
12
+ getApp?(type: MidwayFrameworkType | string): IMidwayApplication<any>;
13
+ close(options?: {
14
+ sleep?: number;
15
+ }): Promise<void>;
16
+ }
11
17
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mock",
3
- "version": "3.11.9",
3
+ "version": "3.11.10",
4
4
  "description": "create your test app from midway framework",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -49,5 +49,5 @@
49
49
  "type": "git",
50
50
  "url": "https://github.com/midwayjs/midway.git"
51
51
  },
52
- "gitHead": "4899f4087aa822370a303c7d076daa6b8a59055b"
52
+ "gitHead": "521c42cc4af8850b77c5cf1f040b7430a74db041"
53
53
  }