@midwayjs/mock 3.11.9 → 3.11.11
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 +6 -11
- package/dist/creator.js +30 -18
- package/dist/interface.d.ts +7 -1
- package/package.json +6 -6
package/dist/creator.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { IMidwayApplication, IMidwayFramework
|
|
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
|
|
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<
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
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, {
|
package/dist/interface.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "3.11.11",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/core": "^3.11.
|
|
30
|
+
"@midwayjs/core": "^3.11.11",
|
|
31
31
|
"@midwayjs/logger": "^2.15.0",
|
|
32
32
|
"@types/amqplib": "0.10.1",
|
|
33
33
|
"amqplib": "0.10.3",
|
|
34
34
|
"kafkajs": "2.2.4",
|
|
35
|
-
"socket.io": "4.6.
|
|
36
|
-
"socket.io-client": "4.6.
|
|
35
|
+
"socket.io": "4.6.2",
|
|
36
|
+
"socket.io-client": "4.6.2",
|
|
37
37
|
"ws": "8.13.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@midwayjs/async-hooks-context-manager": "^3.11.
|
|
40
|
+
"@midwayjs/async-hooks-context-manager": "^3.11.11",
|
|
41
41
|
"@types/superagent": "4.1.14",
|
|
42
42
|
"@types/supertest": "2.0.12",
|
|
43
43
|
"js-yaml": "4.1.0",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"type": "git",
|
|
50
50
|
"url": "https://github.com/midwayjs/midway.git"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "3d2e85a212cfecb5cecb8ab45134fa361fe6cba2"
|
|
53
53
|
}
|