@midwayjs/mock 3.19.2 → 4.0.0-alpha.1
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/client/rabbitMQ.d.ts +1 -0
- package/dist/client/socketio.d.ts +5 -5
- package/dist/creator.d.ts +2 -6
- package/dist/creator.js +102 -86
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interface.d.ts +2 -2
- package/dist/legacy.d.ts +6 -0
- package/dist/legacy.js +52 -0
- package/dist/utils.js +5 -3
- package/package.json +5 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { ManagerOptions, SocketOptions
|
|
2
|
+
import type { ManagerOptions, SocketOptions } from 'socket.io-client';
|
|
3
3
|
export interface MidwaySocketIOClientOptions extends Partial<ManagerOptions & SocketOptions> {
|
|
4
4
|
url?: string;
|
|
5
5
|
protocol?: string;
|
|
@@ -11,12 +11,12 @@ export declare class SocketIOWrapperClient {
|
|
|
11
11
|
private readonly socket;
|
|
12
12
|
constructor(socket: any);
|
|
13
13
|
connect(): Promise<unknown>;
|
|
14
|
-
getSocket():
|
|
14
|
+
getSocket(): any;
|
|
15
15
|
send(eventName: string, ...args: any[]): void;
|
|
16
16
|
on(eventName: string, handler: any): void;
|
|
17
|
-
once(eventName: string, handler: any):
|
|
18
|
-
removeListener(event: string, fn?: any):
|
|
19
|
-
emit(eventName: string, ...args: any[]):
|
|
17
|
+
once(eventName: string, handler: any): any;
|
|
18
|
+
removeListener(event: string, fn?: any): any;
|
|
19
|
+
emit(eventName: string, ...args: any[]): any;
|
|
20
20
|
sendWithAck(eventName: string, ...args: any[]): Promise<unknown>;
|
|
21
21
|
close(): void;
|
|
22
22
|
}
|
package/dist/creator.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
|
|
2
2
|
import { ComponentModule, MockAppConfigurationOptions, IBootstrapAppStarter, MockBootstrapOptions } from './interface';
|
|
3
|
-
export declare function create<T extends IMidwayFramework<any, any, any, any, any>>(appDir: string | MockAppConfigurationOptions, options?: MockAppConfigurationOptions
|
|
4
|
-
|
|
5
|
-
} | ComponentModule): Promise<T>;
|
|
6
|
-
export declare function createApp<T extends IMidwayFramework<any, any, any, any, any>>(baseDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
|
|
7
|
-
new (...args: any[]): T;
|
|
8
|
-
} | ComponentModule): Promise<ReturnType<T['getApplication']>>;
|
|
3
|
+
export declare function create<T extends IMidwayFramework<any, any, any, any, any>>(appDir: string | MockAppConfigurationOptions, options?: MockAppConfigurationOptions): Promise<T>;
|
|
4
|
+
export declare function createApp<T extends IMidwayFramework<any, any, any, any, any>>(baseDir: string | MockAppConfigurationOptions, options?: MockAppConfigurationOptions): Promise<ReturnType<T['getApplication']>>;
|
|
9
5
|
export declare function close(app: IMidwayApplication<any> | {
|
|
10
6
|
close: (...args: any[]) => void;
|
|
11
7
|
}, options?: {
|
package/dist/creator.js
CHANGED
|
@@ -9,7 +9,6 @@ const util_1 = require("util");
|
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const yaml = require("js-yaml");
|
|
11
11
|
const getRawBody = require("raw-body");
|
|
12
|
-
const async_hooks_context_manager_1 = require("@midwayjs/async-hooks-context-manager");
|
|
13
12
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
14
13
|
process.setMaxListeners(0);
|
|
15
14
|
function formatPath(baseDir, p) {
|
|
@@ -23,9 +22,55 @@ function formatPath(baseDir, p) {
|
|
|
23
22
|
function getFileNameWithSuffix(fileName) {
|
|
24
23
|
return (0, core_1.isTypeScriptEnvironment)() ? `${fileName}.ts` : `${fileName}.js`;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function createMockWrapApplicationContext() {
|
|
26
|
+
const container = new core_1.MidwayContainer();
|
|
27
|
+
debug(`[mock]: Create mock MidwayContainer, id=${container.id}.`);
|
|
28
|
+
const bindModuleMap = new WeakMap();
|
|
29
|
+
container.onBeforeBind(target => {
|
|
30
|
+
bindModuleMap.set(target, true);
|
|
31
|
+
});
|
|
32
|
+
core_1.DecoratorManager['_bindModuleMap'] = bindModuleMap;
|
|
33
|
+
// 这里设置是因为在 midway 单测中会不断的复用装饰器元信息,又不能清理缓存,所以在这里做一些过滤
|
|
34
|
+
if (!core_1.DecoratorManager['_mocked']) {
|
|
35
|
+
core_1.DecoratorManager['_listModule'] = core_1.DecoratorManager.listModule;
|
|
36
|
+
core_1.DecoratorManager['_saveModule'] = core_1.DecoratorManager.saveModule;
|
|
37
|
+
core_1.DecoratorManager.saveModule = (key, target) => {
|
|
38
|
+
if (key === core_1.CONFIGURATION_KEY) {
|
|
39
|
+
// 防止重复,测试的时候 configuration 会被重复 save
|
|
40
|
+
const modules = core_1.DecoratorManager['_listModule'](key);
|
|
41
|
+
if (modules.some((module) => module.target === target.target)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
core_1.DecoratorManager['_bindModuleMap'].set(target.target, true);
|
|
46
|
+
core_1.DecoratorManager['_saveModule'](key, target);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
core_1.DecoratorManager['_saveModule'](key, target);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
core_1.DecoratorManager.listModule = key => {
|
|
54
|
+
const modules = core_1.DecoratorManager['_listModule'](key);
|
|
55
|
+
return modules.filter((module) => {
|
|
56
|
+
if (key === core_1.CONFIGURATION_KEY) {
|
|
57
|
+
return core_1.DecoratorManager['_bindModuleMap'].has(module.target);
|
|
58
|
+
}
|
|
59
|
+
if (core_1.DecoratorManager['_bindModuleMap'].has(module)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
debug('[mock]: Filter "%o" module without binding when list module %s.', module.name ?? module, key);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
core_1.DecoratorManager['_mocked'] = true;
|
|
69
|
+
}
|
|
70
|
+
return container;
|
|
71
|
+
}
|
|
72
|
+
async function create(appDir, options = {}) {
|
|
73
|
+
process.env.MIDWAY_TS_MODE = process.env.MIDWAY_TS_MODE ?? 'true';
|
|
29
74
|
if (typeof appDir === 'object') {
|
|
30
75
|
options = appDir;
|
|
31
76
|
appDir = options.appDir || '';
|
|
@@ -75,7 +120,7 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
75
120
|
safeLoad: true,
|
|
76
121
|
enableCache: false,
|
|
77
122
|
});
|
|
78
|
-
options.moduleLoadType =
|
|
123
|
+
options.moduleLoadType = pkgJSON?.type === 'module' ? 'esm' : 'commonjs';
|
|
79
124
|
}
|
|
80
125
|
if (options.baseDir) {
|
|
81
126
|
if (!(0, path_1.isAbsolute)(options.baseDir)) {
|
|
@@ -93,13 +138,6 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
93
138
|
loadMode: options.moduleLoadType,
|
|
94
139
|
});
|
|
95
140
|
}
|
|
96
|
-
if (!options.imports && customFramework) {
|
|
97
|
-
options.imports = await (0, utils_1.transformFrameworkToConfiguration)(customFramework, options.moduleLoadType);
|
|
98
|
-
}
|
|
99
|
-
if (customFramework === null || customFramework === void 0 ? void 0 : customFramework['Configuration']) {
|
|
100
|
-
options.imports = customFramework;
|
|
101
|
-
customFramework = customFramework['Framework'];
|
|
102
|
-
}
|
|
103
141
|
if (options.ssl) {
|
|
104
142
|
const sslConfig = {
|
|
105
143
|
koa: {
|
|
@@ -117,54 +155,20 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
117
155
|
};
|
|
118
156
|
options.globalConfig = (0, utils_1.mergeGlobalConfig)(options.globalConfig, sslConfig);
|
|
119
157
|
}
|
|
120
|
-
const container =
|
|
121
|
-
const bindModuleMap = new WeakMap();
|
|
122
|
-
// 这里设置是因为在 midway 单测中会不断的复用装饰器元信息,又不能清理缓存,所以在这里做一些过滤
|
|
123
|
-
container.onBeforeBind(target => {
|
|
124
|
-
bindModuleMap.set(target, true);
|
|
125
|
-
});
|
|
126
|
-
const originMethod = container.listModule;
|
|
127
|
-
container.listModule = key => {
|
|
128
|
-
const modules = originMethod.call(container, key);
|
|
129
|
-
if (key === core_1.CONFIGURATION_KEY) {
|
|
130
|
-
return modules;
|
|
131
|
-
}
|
|
132
|
-
return modules.filter((module) => {
|
|
133
|
-
var _a;
|
|
134
|
-
if (bindModuleMap.has(module)) {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
debug('[mock] Filter "%o" module without binding when list module %s.', (_a = module.name) !== null && _a !== void 0 ? _a : module, key);
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
};
|
|
158
|
+
const container = createMockWrapApplicationContext();
|
|
143
159
|
options.applicationContext = container;
|
|
144
160
|
await (0, core_1.initializeGlobalApplicationContext)({
|
|
145
161
|
...options,
|
|
146
162
|
appDir,
|
|
147
|
-
asyncContextManager: (0, async_hooks_context_manager_1.createContextManager)(),
|
|
148
163
|
loggerFactory: logger_1.loggers,
|
|
149
|
-
imports: [].concat(options.imports).concat(options.baseDir
|
|
150
|
-
? await (0, core_1.loadModule)((0, path_1.join)(options.baseDir, getFileNameWithSuffix('configuration')), {
|
|
151
|
-
safeLoad: true,
|
|
152
|
-
loadMode: options.moduleLoadType,
|
|
153
|
-
})
|
|
154
|
-
: []),
|
|
155
164
|
});
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
const frameworkService = await container.getAsync(core_1.MidwayFrameworkService);
|
|
166
|
+
const mainFramework = frameworkService.getMainFramework();
|
|
167
|
+
if (mainFramework) {
|
|
168
|
+
return mainFramework;
|
|
158
169
|
}
|
|
159
170
|
else {
|
|
160
|
-
|
|
161
|
-
const mainFramework = frameworkService.getMainFramework();
|
|
162
|
-
if (mainFramework) {
|
|
163
|
-
return mainFramework;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw new Error(`Can not get main framework, please check your ${getFileNameWithSuffix('configuration')}.`);
|
|
167
|
-
}
|
|
171
|
+
throw new Error(`Can not get main framework, please check your ${getFileNameWithSuffix('configuration')}.`);
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
catch (err) {
|
|
@@ -176,8 +180,8 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
176
180
|
}
|
|
177
181
|
}
|
|
178
182
|
exports.create = create;
|
|
179
|
-
async function createApp(baseDir
|
|
180
|
-
const framework = await create(baseDir, options
|
|
183
|
+
async function createApp(baseDir, options) {
|
|
184
|
+
const framework = await create(baseDir, options);
|
|
181
185
|
return framework.getApplication();
|
|
182
186
|
}
|
|
183
187
|
exports.createApp = createApp;
|
|
@@ -198,7 +202,7 @@ async function close(app, options) {
|
|
|
198
202
|
if (options.cleanLogsDir && !(0, utils_1.isWin32)()) {
|
|
199
203
|
await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'logs'));
|
|
200
204
|
}
|
|
201
|
-
if (
|
|
205
|
+
if ('egg' === app.getNamespace()) {
|
|
202
206
|
if (options.cleanTempDir && !(0, utils_1.isWin32)()) {
|
|
203
207
|
await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'run'));
|
|
204
208
|
}
|
|
@@ -214,8 +218,7 @@ async function close(app, options) {
|
|
|
214
218
|
}
|
|
215
219
|
exports.close = close;
|
|
216
220
|
async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
217
|
-
|
|
218
|
-
process.env.MIDWAY_TS_MODE = (_a = process.env.MIDWAY_TS_MODE) !== null && _a !== void 0 ? _a : 'true';
|
|
221
|
+
process.env.MIDWAY_TS_MODE = process.env.MIDWAY_TS_MODE ?? 'true';
|
|
219
222
|
if (typeof baseDir === 'object') {
|
|
220
223
|
options = baseDir;
|
|
221
224
|
baseDir = options.appDir || '';
|
|
@@ -234,7 +237,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
234
237
|
// load yaml
|
|
235
238
|
try {
|
|
236
239
|
const doc = yaml.load((0, fs_1.readFileSync)((0, path_1.join)(baseDir, 'f.yml'), 'utf8'));
|
|
237
|
-
starterName =
|
|
240
|
+
starterName = doc?.['provider']?.['starter'];
|
|
238
241
|
if (starterName) {
|
|
239
242
|
const m = await (0, core_1.loadModule)(starterName);
|
|
240
243
|
if (m && m['BootstrapStarter']) {
|
|
@@ -248,6 +251,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
248
251
|
}
|
|
249
252
|
}
|
|
250
253
|
if (options.starter) {
|
|
254
|
+
options.applicationContext = createMockWrapApplicationContext();
|
|
251
255
|
options.appDir = baseDir;
|
|
252
256
|
debug(`[mock]: Create app, appDir="${options.appDir}"`);
|
|
253
257
|
if (options.appDir) {
|
|
@@ -264,8 +268,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
264
268
|
safeLoad: true,
|
|
265
269
|
enableCache: false,
|
|
266
270
|
});
|
|
267
|
-
options.moduleLoadType =
|
|
268
|
-
options = options || {};
|
|
271
|
+
options.moduleLoadType = pkgJSON?.type === 'module' ? 'esm' : 'commonjs';
|
|
269
272
|
if (options.baseDir) {
|
|
270
273
|
await (0, core_1.loadModule)((0, path_1.join)(`${options.baseDir}`, getFileNameWithSuffix('interface')), {
|
|
271
274
|
safeLoad: true,
|
|
@@ -287,9 +290,9 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
287
290
|
const frameworkService = appCtx.get(core_1.MidwayFrameworkService);
|
|
288
291
|
const framework = frameworkService.getMainFramework();
|
|
289
292
|
const appManager = appCtx.get(core_1.MidwayApplicationManager);
|
|
290
|
-
const app = appManager.getApplication(
|
|
291
|
-
const faasConfig =
|
|
292
|
-
const customPort =
|
|
293
|
+
const app = appManager.getApplication('faas');
|
|
294
|
+
const faasConfig = configService.getConfiguration('faas') ?? {};
|
|
295
|
+
const customPort = process.env.MIDWAY_HTTP_PORT ?? faasConfig['port'] ?? options['port'];
|
|
293
296
|
if (options.starter.callback2) {
|
|
294
297
|
app.callback2 = options.starter.callback2.bind(options.starter);
|
|
295
298
|
}
|
|
@@ -310,12 +313,10 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
310
313
|
});
|
|
311
314
|
}
|
|
312
315
|
req.getOriginEvent = () => {
|
|
313
|
-
|
|
314
|
-
return ((_a = options.starter) === null || _a === void 0 ? void 0 : _a.createDefaultMockHttpEvent()) || {};
|
|
316
|
+
return options.starter?.createDefaultMockHttpEvent() || {};
|
|
315
317
|
};
|
|
316
318
|
req.getOriginContext = () => {
|
|
317
|
-
|
|
318
|
-
return ((_a = options.starter) === null || _a === void 0 ? void 0 : _a.createDefaultMockContext()) || {};
|
|
319
|
+
return options.starter?.createDefaultMockContext() || {};
|
|
319
320
|
};
|
|
320
321
|
try {
|
|
321
322
|
const ctx = await framework.wrapHttpRequest(req);
|
|
@@ -363,16 +364,18 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
363
364
|
}
|
|
364
365
|
else {
|
|
365
366
|
funcInfo = Array.from(framework['funMappingStore'].values()).find((item) => {
|
|
366
|
-
return (item.id ===
|
|
367
|
+
return (item.id ===
|
|
368
|
+
core_1.DecoratorManager.getProviderUUId(serviceClass) &&
|
|
367
369
|
item.method === prop);
|
|
368
370
|
});
|
|
369
371
|
}
|
|
370
372
|
if (funcInfo) {
|
|
371
373
|
return async (...args) => {
|
|
372
|
-
var _a, _b, _c, _d, _e;
|
|
373
374
|
const context = app.createAnonymousContext({
|
|
374
|
-
originContext:
|
|
375
|
-
|
|
375
|
+
originContext: customContext ??
|
|
376
|
+
options.starter?.createDefaultMockContext() ??
|
|
377
|
+
{},
|
|
378
|
+
originEvent: args[0] ?? options.starter?.createDefaultMockEvent() ?? {},
|
|
376
379
|
});
|
|
377
380
|
return framework.invokeTriggerFunction(context, funcInfo.funcHandlerName, {
|
|
378
381
|
isHttpFunction: false,
|
|
@@ -404,11 +407,12 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
404
407
|
return app;
|
|
405
408
|
}
|
|
406
409
|
else {
|
|
407
|
-
const customFramework = customFrameworkModule
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
410
|
+
const customFramework = customFrameworkModule ??
|
|
411
|
+
(0, utils_1.findFirstExistModule)([
|
|
412
|
+
process.env.MIDWAY_SERVERLESS_APP_NAME,
|
|
413
|
+
'@ali/serverless-app',
|
|
414
|
+
'@midwayjs/serverless-app',
|
|
415
|
+
]);
|
|
412
416
|
const serverlessModule = await (0, utils_1.transformFrameworkToConfiguration)(customFramework, options.moduleLoadType);
|
|
413
417
|
if (serverlessModule) {
|
|
414
418
|
if (options && options.imports) {
|
|
@@ -422,7 +426,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
422
426
|
const framework = await createApp(baseDir, options);
|
|
423
427
|
const appCtx = framework.getApplicationContext();
|
|
424
428
|
const appManager = appCtx.get(core_1.MidwayApplicationManager);
|
|
425
|
-
return appManager.getApplication(
|
|
429
|
+
return appManager.getApplication('serverless-app');
|
|
426
430
|
}
|
|
427
431
|
}
|
|
428
432
|
exports.createFunctionApp = createFunctionApp;
|
|
@@ -430,9 +434,6 @@ exports.createFunctionApp = createFunctionApp;
|
|
|
430
434
|
* 一个全量的空框架
|
|
431
435
|
*/
|
|
432
436
|
class LightFramework extends core_1.BaseFramework {
|
|
433
|
-
getFrameworkType() {
|
|
434
|
-
return core_1.MidwayFrameworkType.LIGHT;
|
|
435
|
-
}
|
|
436
437
|
async run() { }
|
|
437
438
|
async applicationInitialize(options) {
|
|
438
439
|
this.app = {};
|
|
@@ -460,7 +461,7 @@ class BootstrapAppStarter {
|
|
|
460
461
|
loadMode: this.options.moduleLoadType,
|
|
461
462
|
safeLoad: true,
|
|
462
463
|
});
|
|
463
|
-
if (BootstrapModule
|
|
464
|
+
if (BootstrapModule?.Bootstrap) {
|
|
464
465
|
await BootstrapModule.Bootstrap.stop();
|
|
465
466
|
}
|
|
466
467
|
if (options.sleep > 0) {
|
|
@@ -477,7 +478,6 @@ class BootstrapAppStarter {
|
|
|
477
478
|
* @param options
|
|
478
479
|
*/
|
|
479
480
|
async function createLightApp(baseDirOrOptions, options = {}) {
|
|
480
|
-
var _a;
|
|
481
481
|
if (baseDirOrOptions && typeof baseDirOrOptions === 'object') {
|
|
482
482
|
options = baseDirOrOptions;
|
|
483
483
|
baseDirOrOptions = options.baseDir || '';
|
|
@@ -490,21 +490,37 @@ async function createLightApp(baseDirOrOptions, options = {}) {
|
|
|
490
490
|
disableError: true,
|
|
491
491
|
},
|
|
492
492
|
},
|
|
493
|
-
},
|
|
493
|
+
}, options.globalConfig ?? {});
|
|
494
494
|
if (!options.moduleLoadType) {
|
|
495
495
|
const cwd = process.cwd();
|
|
496
496
|
const pkgJSON = await (0, core_1.loadModule)((0, path_1.join)(cwd, 'package.json'), {
|
|
497
497
|
safeLoad: true,
|
|
498
498
|
enableCache: false,
|
|
499
499
|
});
|
|
500
|
-
options.moduleLoadType =
|
|
500
|
+
options.moduleLoadType = pkgJSON?.type === 'module' ? 'esm' : 'commonjs';
|
|
501
501
|
}
|
|
502
|
-
|
|
502
|
+
const app = await createApp(baseDirOrOptions, {
|
|
503
503
|
...options,
|
|
504
504
|
imports: [
|
|
505
505
|
await (0, utils_1.transformFrameworkToConfiguration)(LightFramework, options.moduleLoadType),
|
|
506
|
-
].concat(options
|
|
506
|
+
].concat(options?.imports),
|
|
507
507
|
});
|
|
508
|
+
const applicationManager = app
|
|
509
|
+
.getApplicationContext()
|
|
510
|
+
.get(core_1.MidwayApplicationManager);
|
|
511
|
+
const apps = applicationManager.getApplications();
|
|
512
|
+
if (apps.length === 1) {
|
|
513
|
+
return app;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
// 如果有多个 app,则重置 main app
|
|
517
|
+
const frameworkService = app
|
|
518
|
+
.getApplicationContext()
|
|
519
|
+
.get(core_1.MidwayFrameworkService);
|
|
520
|
+
// 这里调整是因为 createLightApp 会自动加一个 framework
|
|
521
|
+
frameworkService.setMainApp(apps[0].getNamespace());
|
|
522
|
+
return frameworkService.getMainApp();
|
|
523
|
+
}
|
|
508
524
|
}
|
|
509
525
|
exports.createLightApp = createLightApp;
|
|
510
526
|
async function createBootstrap(entryFile, options = {}) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { create, close, createApp, createFunctionApp, createLightApp, createBootstrap, } from './creator';
|
|
2
|
+
export * from './legacy';
|
|
2
3
|
export * from './client/index';
|
|
3
4
|
export { transformFrameworkToConfiguration, processArgsParser } from './utils';
|
|
4
5
|
export * from './mock';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "createApp", { enumerable: true, get: function ()
|
|
|
22
22
|
Object.defineProperty(exports, "createFunctionApp", { enumerable: true, get: function () { return creator_1.createFunctionApp; } });
|
|
23
23
|
Object.defineProperty(exports, "createLightApp", { enumerable: true, get: function () { return creator_1.createLightApp; } });
|
|
24
24
|
Object.defineProperty(exports, "createBootstrap", { enumerable: true, get: function () { return creator_1.createBootstrap; } });
|
|
25
|
+
__exportStar(require("./legacy"), exports);
|
|
25
26
|
__exportStar(require("./client/index"), exports);
|
|
26
27
|
var utils_1 = require("./utils");
|
|
27
28
|
Object.defineProperty(exports, "transformFrameworkToConfiguration", { enumerable: true, get: function () { return utils_1.transformFrameworkToConfiguration; } });
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMidwayApplication, IMidwayBootstrapOptions
|
|
1
|
+
import { IMidwayApplication, IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
2
|
export interface MockAppConfigurationOptions extends IMidwayBootstrapOptions {
|
|
3
3
|
cleanLogsDir?: boolean;
|
|
4
4
|
cleanTempDir?: boolean;
|
|
@@ -12,7 +12,7 @@ export type ComponentModule = {
|
|
|
12
12
|
Configuration: new () => any;
|
|
13
13
|
};
|
|
14
14
|
export interface IBootstrapAppStarter {
|
|
15
|
-
getApp?(type:
|
|
15
|
+
getApp?(type: string): IMidwayApplication<any>;
|
|
16
16
|
close(options?: {
|
|
17
17
|
sleep?: number;
|
|
18
18
|
}): Promise<void>;
|
package/dist/legacy.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createApp, createFunctionApp } from './creator';
|
|
2
|
+
import { IMidwayFramework } from '@midwayjs/core';
|
|
3
|
+
export declare function createLegacyApp<T extends IMidwayFramework<any, any, any, any, any>>(...args: Parameters<typeof createApp>): Promise<ReturnType<T['getApplication']>>;
|
|
4
|
+
export declare function createLegacyFunctionApp<T extends IMidwayFramework<any, any, any, any, any>>(...args: Parameters<typeof createFunctionApp>): Promise<ReturnType<T['getApplication']>>;
|
|
5
|
+
export declare function createLegacyLightApp(...args: any[]): Promise<import("@midwayjs/core").IMidwayBaseApplication<import("@midwayjs/core").Context>>;
|
|
6
|
+
//# sourceMappingURL=legacy.d.ts.map
|
package/dist/legacy.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLegacyLightApp = exports.createLegacyFunctionApp = exports.createLegacyApp = void 0;
|
|
4
|
+
const creator_1 = require("./creator");
|
|
5
|
+
const core_1 = require("@midwayjs/core");
|
|
6
|
+
const functional_1 = require("@midwayjs/core/functional");
|
|
7
|
+
async function createLegacyApp(...args) {
|
|
8
|
+
const appDir = typeof args[0] === 'string' ? args[0] : (args[0] ?? {}).appDir;
|
|
9
|
+
const options = (typeof args[0] === 'string' ? args[1] : args[0]) ?? {};
|
|
10
|
+
options.imports = [
|
|
11
|
+
...(options.imports ?? []),
|
|
12
|
+
(0, functional_1.defineConfiguration)({
|
|
13
|
+
namespace: 'legacy',
|
|
14
|
+
detector: new core_1.CommonJSFileDetector({
|
|
15
|
+
conflictCheck: true,
|
|
16
|
+
}),
|
|
17
|
+
}),
|
|
18
|
+
];
|
|
19
|
+
return (0, creator_1.createApp)(appDir, options);
|
|
20
|
+
}
|
|
21
|
+
exports.createLegacyApp = createLegacyApp;
|
|
22
|
+
async function createLegacyFunctionApp(...args) {
|
|
23
|
+
const appDir = typeof args[0] === 'string' ? args[0] : (args[0] ?? {}).appDir;
|
|
24
|
+
const options = (typeof args[0] === 'string' ? args[1] : args[0]) ?? {};
|
|
25
|
+
options.imports = [
|
|
26
|
+
...(options.imports ?? []),
|
|
27
|
+
(0, functional_1.defineConfiguration)({
|
|
28
|
+
namespace: 'legacy',
|
|
29
|
+
detector: new core_1.CommonJSFileDetector({
|
|
30
|
+
conflictCheck: true,
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
return (0, creator_1.createFunctionApp)(appDir, options);
|
|
35
|
+
}
|
|
36
|
+
exports.createLegacyFunctionApp = createLegacyFunctionApp;
|
|
37
|
+
async function createLegacyLightApp(...args) {
|
|
38
|
+
const appDir = typeof args[0] === 'string' ? args[0] : (args[0] ?? {}).appDir;
|
|
39
|
+
const options = (typeof args[0] === 'string' ? args[1] : args[0]) ?? {};
|
|
40
|
+
options.imports = [
|
|
41
|
+
...(options.imports ?? []),
|
|
42
|
+
(0, functional_1.defineConfiguration)({
|
|
43
|
+
namespace: 'legacy',
|
|
44
|
+
detector: new core_1.CommonJSFileDetector({
|
|
45
|
+
conflictCheck: true,
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
return (0, creator_1.createLightApp)(appDir, options);
|
|
50
|
+
}
|
|
51
|
+
exports.createLegacyLightApp = createLegacyLightApp;
|
|
52
|
+
//# sourceMappingURL=legacy.js.map
|
package/dist/utils.js
CHANGED
|
@@ -58,7 +58,7 @@ async function transformFrameworkToConfiguration(Framework, loadMode) {
|
|
|
58
58
|
else {
|
|
59
59
|
CustomFramework = Framework;
|
|
60
60
|
}
|
|
61
|
-
assert(CustomFramework, `can't found custom framework ${Framework}`);
|
|
61
|
+
assert.ok(CustomFramework, `can't found custom framework ${Framework}`);
|
|
62
62
|
let CustomConfiguration = class CustomConfiguration {
|
|
63
63
|
async onServerReady(container) {
|
|
64
64
|
const customFramework = (await container.getAsync(CustomFramework));
|
|
@@ -66,7 +66,9 @@ async function transformFrameworkToConfiguration(Framework, loadMode) {
|
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
CustomConfiguration = __decorate([
|
|
69
|
-
(0, core_1.Configuration)(
|
|
69
|
+
(0, core_1.Configuration)({
|
|
70
|
+
namespace: new Framework().getFrameworkName(),
|
|
71
|
+
})
|
|
70
72
|
], CustomConfiguration);
|
|
71
73
|
return {
|
|
72
74
|
Configuration: CustomConfiguration,
|
|
@@ -79,7 +81,7 @@ async function removeFile(file) {
|
|
|
79
81
|
await fs.promises.access(file, fs.constants.W_OK);
|
|
80
82
|
await fs.promises.unlink(file);
|
|
81
83
|
}
|
|
82
|
-
catch
|
|
84
|
+
catch {
|
|
83
85
|
// ignore
|
|
84
86
|
}
|
|
85
87
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"link": "npm link"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@midwayjs/core": "^
|
|
32
|
+
"@midwayjs/core": "^4.0.0-alpha.1",
|
|
33
33
|
"@midwayjs/logger": "^3.0.0",
|
|
34
34
|
"@types/amqplib": "0.10.6",
|
|
35
35
|
"amqplib": "0.10.5",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"ws": "8.18.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@midwayjs/async-hooks-context-manager": "^3.19.0",
|
|
43
42
|
"@types/superagent": "4.1.14",
|
|
44
43
|
"@types/supertest": "2.0.16",
|
|
45
44
|
"js-yaml": "4.1.0",
|
|
@@ -51,5 +50,5 @@
|
|
|
51
50
|
"type": "git",
|
|
52
51
|
"url": "https://github.com/midwayjs/midway.git"
|
|
53
52
|
},
|
|
54
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
55
54
|
}
|