@midwayjs/mock 3.4.0-beta.6 → 3.4.0-beta.7
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 -1
- package/dist/creator.d.ts +9 -1
- package/dist/creator.js +70 -3
- package/package.json +6 -5
- package/ssl/ssl.key +27 -0
- package/ssl/ssl.pem +23 -0
package/dist/creator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
|
|
1
|
+
import { IMidwayApplication, IMidwayFramework, MidwayFrameworkType } from '@midwayjs/core';
|
|
2
2
|
import { ComponentModule, MockAppConfigurationOptions } 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;
|
|
@@ -14,10 +14,18 @@ export declare function close<T extends IMidwayApplication<any>>(app: T, options
|
|
|
14
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
|
+
declare class BootstrapAppStarter {
|
|
18
|
+
getApp(type: MidwayFrameworkType | string): IMidwayApplication<any>;
|
|
19
|
+
close(options?: {
|
|
20
|
+
sleep?: number;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* Create a real project but not ready or a virtual project
|
|
19
25
|
* @param baseDir
|
|
20
26
|
* @param options
|
|
21
27
|
*/
|
|
22
28
|
export declare function createLightApp(baseDir?: string, options?: MockAppConfigurationOptions): Promise<IMidwayApplication>;
|
|
29
|
+
export declare function createBootstrap(entryFile: string): Promise<BootstrapAppStarter>;
|
|
30
|
+
export {};
|
|
23
31
|
//# sourceMappingURL=creator.d.ts.map
|
package/dist/creator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLightApp = exports.createFunctionApp = exports.close = exports.createApp = exports.create = void 0;
|
|
3
|
+
exports.createBootstrap = exports.createLightApp = exports.createFunctionApp = exports.close = exports.createApp = exports.create = void 0;
|
|
4
4
|
const core_1 = require("@midwayjs/core");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -9,11 +9,18 @@ const logger_1 = require("@midwayjs/logger");
|
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const util_1 = require("util");
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
|
-
const http = require("http");
|
|
13
12
|
const yaml = require("js-yaml");
|
|
14
13
|
const getRawBody = require("raw-body");
|
|
15
14
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
15
|
process.setMaxListeners(0);
|
|
16
|
+
function formatPath(baseDir, p) {
|
|
17
|
+
if ((0, path_1.isAbsolute)(p)) {
|
|
18
|
+
return p;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return (0, path_1.resolve)(baseDir, p);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
17
24
|
async function create(appDir = process.cwd(), options, customFramework) {
|
|
18
25
|
debug(`[mock]: Create app, appDir="${appDir}"`);
|
|
19
26
|
process.env.MIDWAY_TS_MODE = 'true';
|
|
@@ -35,6 +42,30 @@ async function create(appDir = process.cwd(), options, customFramework) {
|
|
|
35
42
|
options.baseDir = `${appDir}/src`;
|
|
36
43
|
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
37
44
|
}
|
|
45
|
+
if (options.entryFile) {
|
|
46
|
+
// start from entry file, like bootstrap.js
|
|
47
|
+
options.entryFile = formatPath(appDir, options.entryFile);
|
|
48
|
+
global['MIDWAY_BOOTSTRAP_APP_READY'] = false;
|
|
49
|
+
// set app in @midwayjs/bootstrap
|
|
50
|
+
require(options.entryFile);
|
|
51
|
+
await new Promise((resolve, reject) => {
|
|
52
|
+
const timeoutHandler = setTimeout(() => {
|
|
53
|
+
clearInterval(internalHandler);
|
|
54
|
+
reject(new Error('[midway]: bootstrap timeout'));
|
|
55
|
+
}, options.bootstrapTimeout || 30 * 1000);
|
|
56
|
+
const internalHandler = setInterval(() => {
|
|
57
|
+
if (global['MIDWAY_BOOTSTRAP_APP_READY'] === true) {
|
|
58
|
+
clearInterval(internalHandler);
|
|
59
|
+
clearTimeout(timeoutHandler);
|
|
60
|
+
resolve();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
debug('[mock]: bootstrap not ready and wait next check');
|
|
64
|
+
}
|
|
65
|
+
}, 200);
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
38
69
|
if (!options.imports && customFramework) {
|
|
39
70
|
options.imports = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
40
71
|
}
|
|
@@ -204,7 +235,16 @@ async function createFunctionApp(baseDir = process.cwd(), options, customFramewo
|
|
|
204
235
|
};
|
|
205
236
|
if (customPort) {
|
|
206
237
|
await new Promise(resolve => {
|
|
207
|
-
|
|
238
|
+
let server;
|
|
239
|
+
if (this.configurationOptions.ssl) {
|
|
240
|
+
server = require('https').createServer({
|
|
241
|
+
key: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../ssl/ssl.key'), 'utf8'),
|
|
242
|
+
cert: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../ssl/ssl.pem'), 'utf8'),
|
|
243
|
+
}, app.callback2());
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
server = require('http').createServer(app.callback2());
|
|
247
|
+
}
|
|
208
248
|
server.listen(customPort);
|
|
209
249
|
process.env.MIDWAY_HTTP_PORT = String(customPort);
|
|
210
250
|
app.server = server;
|
|
@@ -255,6 +295,26 @@ class LightFramework extends core_1.BaseFramework {
|
|
|
255
295
|
return 'lightFramework';
|
|
256
296
|
}
|
|
257
297
|
}
|
|
298
|
+
class BootstrapAppStarter {
|
|
299
|
+
getApp(type) {
|
|
300
|
+
const applicationContext = (0, core_1.getCurrentApplicationContext)();
|
|
301
|
+
const applicationManager = applicationContext.get(core_1.MidwayApplicationManager);
|
|
302
|
+
return applicationManager.getApplication(type);
|
|
303
|
+
}
|
|
304
|
+
async close(options = {}) {
|
|
305
|
+
// eslint-disable-next-line node/no-extraneous-require
|
|
306
|
+
const BootstrapModule = (0, core_1.safeRequire)('@midwayjs/bootstrap');
|
|
307
|
+
if (BootstrapModule === null || BootstrapModule === void 0 ? void 0 : BootstrapModule.Bootstrap) {
|
|
308
|
+
await BootstrapModule.Bootstrap.stop();
|
|
309
|
+
}
|
|
310
|
+
if (options.sleep > 0) {
|
|
311
|
+
await (0, decorator_1.sleep)(options.sleep);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
await (0, decorator_1.sleep)(50);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
258
318
|
/**
|
|
259
319
|
* Create a real project but not ready or a virtual project
|
|
260
320
|
* @param baseDir
|
|
@@ -277,4 +337,11 @@ async function createLightApp(baseDir = '', options = {}) {
|
|
|
277
337
|
});
|
|
278
338
|
}
|
|
279
339
|
exports.createLightApp = createLightApp;
|
|
340
|
+
async function createBootstrap(entryFile) {
|
|
341
|
+
await create(undefined, {
|
|
342
|
+
entryFile,
|
|
343
|
+
});
|
|
344
|
+
return new BootstrapAppStarter();
|
|
345
|
+
}
|
|
346
|
+
exports.createBootstrap = createBootstrap;
|
|
280
347
|
//# sourceMappingURL=creator.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.4.0-beta.
|
|
3
|
+
"version": "3.4.0-beta.7",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,15 +19,16 @@
|
|
|
19
19
|
],
|
|
20
20
|
"files": [
|
|
21
21
|
"dist/**/*.js",
|
|
22
|
-
"dist/**/*.d.ts"
|
|
22
|
+
"dist/**/*.d.ts",
|
|
23
|
+
"ssl"
|
|
23
24
|
],
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=12"
|
|
26
27
|
},
|
|
27
28
|
"license": "MIT",
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^3.4.0-beta.
|
|
30
|
-
"@midwayjs/decorator": "^3.4.0-beta.
|
|
30
|
+
"@midwayjs/core": "^3.4.0-beta.7",
|
|
31
|
+
"@midwayjs/decorator": "^3.4.0-beta.7",
|
|
31
32
|
"@midwayjs/logger": "^2.15.0",
|
|
32
33
|
"@types/amqplib": "0.8.2",
|
|
33
34
|
"amqplib": "0.10.0",
|
|
@@ -48,5 +49,5 @@
|
|
|
48
49
|
"type": "git",
|
|
49
50
|
"url": "http://github.com/midwayjs/midway.git"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "4d5cc59a7a33e49beeaf20fcfaf766438649959c"
|
|
52
53
|
}
|
package/ssl/ssl.key
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
|
2
|
+
MIIEpAIBAAKCAQEAwYgqylPquhc3d5E75sLxUs7jhxuIfMztx3H449KC7kT9+ukS
|
|
3
|
+
bdB/IqwRcLgB/n2V4+pkEjOHG2K/ErHkaOdw7L4tf8wNLMSUbCNlppYcZ6EGuSWN
|
|
4
|
+
V80GZREFifKu+Q3jMEX3K96lS5pmBoYQHr2iqejtb1bmN9yeeI4FuOlm+hHc6zBD
|
|
5
|
+
87rABjxgITybxDt+wffbfqSkjBrQCDjqeNn6m5n5OmO1lBdn6fAOJe7krp9bG4Mq
|
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