@midwayjs/mock 3.4.0-beta.6 → 3.4.0-beta.9
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 +72 -4
- package/package.json +7 -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,19 @@ 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");
|
|
14
|
+
const async_hooks_context_manager_1 = require("@midwayjs/async-hooks-context-manager");
|
|
15
15
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
16
|
process.setMaxListeners(0);
|
|
17
|
+
function formatPath(baseDir, p) {
|
|
18
|
+
if ((0, path_1.isAbsolute)(p)) {
|
|
19
|
+
return p;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return (0, path_1.resolve)(baseDir, p);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
17
25
|
async function create(appDir = process.cwd(), options, customFramework) {
|
|
18
26
|
debug(`[mock]: Create app, appDir="${appDir}"`);
|
|
19
27
|
process.env.MIDWAY_TS_MODE = 'true';
|
|
@@ -35,6 +43,30 @@ async function create(appDir = process.cwd(), options, customFramework) {
|
|
|
35
43
|
options.baseDir = `${appDir}/src`;
|
|
36
44
|
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
37
45
|
}
|
|
46
|
+
if (options.entryFile) {
|
|
47
|
+
// start from entry file, like bootstrap.js
|
|
48
|
+
options.entryFile = formatPath(appDir, options.entryFile);
|
|
49
|
+
global['MIDWAY_BOOTSTRAP_APP_READY'] = false;
|
|
50
|
+
// set app in @midwayjs/bootstrap
|
|
51
|
+
require(options.entryFile);
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
const timeoutHandler = setTimeout(() => {
|
|
54
|
+
clearInterval(internalHandler);
|
|
55
|
+
reject(new Error('[midway]: bootstrap timeout'));
|
|
56
|
+
}, options.bootstrapTimeout || 30 * 1000);
|
|
57
|
+
const internalHandler = setInterval(() => {
|
|
58
|
+
if (global['MIDWAY_BOOTSTRAP_APP_READY'] === true) {
|
|
59
|
+
clearInterval(internalHandler);
|
|
60
|
+
clearTimeout(timeoutHandler);
|
|
61
|
+
resolve();
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
debug('[mock]: bootstrap not ready and wait next check');
|
|
65
|
+
}
|
|
66
|
+
}, 200);
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
38
70
|
if (!options.imports && customFramework) {
|
|
39
71
|
options.imports = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
40
72
|
}
|
|
@@ -69,6 +101,7 @@ async function create(appDir = process.cwd(), options, customFramework) {
|
|
|
69
101
|
await (0, core_1.initializeGlobalApplicationContext)({
|
|
70
102
|
...options,
|
|
71
103
|
appDir,
|
|
104
|
+
asyncContextManager: (0, async_hooks_context_manager_1.createContextManager)(),
|
|
72
105
|
imports: []
|
|
73
106
|
.concat(options.imports)
|
|
74
107
|
.concat(options.baseDir
|
|
@@ -135,7 +168,6 @@ async function createFunctionApp(baseDir = process.cwd(), options, customFramewo
|
|
|
135
168
|
}
|
|
136
169
|
}
|
|
137
170
|
if (options.starter) {
|
|
138
|
-
options.exportAllHandler = true;
|
|
139
171
|
options.appDir = baseDir;
|
|
140
172
|
debug(`[mock]: Create app, appDir="${options.appDir}"`);
|
|
141
173
|
process.env.MIDWAY_TS_MODE = 'true';
|
|
@@ -204,7 +236,16 @@ async function createFunctionApp(baseDir = process.cwd(), options, customFramewo
|
|
|
204
236
|
};
|
|
205
237
|
if (customPort) {
|
|
206
238
|
await new Promise(resolve => {
|
|
207
|
-
|
|
239
|
+
let server;
|
|
240
|
+
if (options.ssl) {
|
|
241
|
+
server = require('https').createServer({
|
|
242
|
+
key: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../ssl/ssl.key'), 'utf8'),
|
|
243
|
+
cert: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../ssl/ssl.pem'), 'utf8'),
|
|
244
|
+
}, app.callback2());
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
server = require('http').createServer(app.callback2());
|
|
248
|
+
}
|
|
208
249
|
server.listen(customPort);
|
|
209
250
|
process.env.MIDWAY_HTTP_PORT = String(customPort);
|
|
210
251
|
app.server = server;
|
|
@@ -255,6 +296,26 @@ class LightFramework extends core_1.BaseFramework {
|
|
|
255
296
|
return 'lightFramework';
|
|
256
297
|
}
|
|
257
298
|
}
|
|
299
|
+
class BootstrapAppStarter {
|
|
300
|
+
getApp(type) {
|
|
301
|
+
const applicationContext = (0, core_1.getCurrentApplicationContext)();
|
|
302
|
+
const applicationManager = applicationContext.get(core_1.MidwayApplicationManager);
|
|
303
|
+
return applicationManager.getApplication(type);
|
|
304
|
+
}
|
|
305
|
+
async close(options = {}) {
|
|
306
|
+
// eslint-disable-next-line node/no-extraneous-require
|
|
307
|
+
const BootstrapModule = (0, core_1.safeRequire)('@midwayjs/bootstrap');
|
|
308
|
+
if (BootstrapModule === null || BootstrapModule === void 0 ? void 0 : BootstrapModule.Bootstrap) {
|
|
309
|
+
await BootstrapModule.Bootstrap.stop();
|
|
310
|
+
}
|
|
311
|
+
if (options.sleep > 0) {
|
|
312
|
+
await (0, decorator_1.sleep)(options.sleep);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
await (0, decorator_1.sleep)(50);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
258
319
|
/**
|
|
259
320
|
* Create a real project but not ready or a virtual project
|
|
260
321
|
* @param baseDir
|
|
@@ -277,4 +338,11 @@ async function createLightApp(baseDir = '', options = {}) {
|
|
|
277
338
|
});
|
|
278
339
|
}
|
|
279
340
|
exports.createLightApp = createLightApp;
|
|
341
|
+
async function createBootstrap(entryFile) {
|
|
342
|
+
await create(undefined, {
|
|
343
|
+
entryFile,
|
|
344
|
+
});
|
|
345
|
+
return new BootstrapAppStarter();
|
|
346
|
+
}
|
|
347
|
+
exports.createBootstrap = createBootstrap;
|
|
280
348
|
//# 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.9",
|
|
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.9",
|
|
31
|
+
"@midwayjs/decorator": "^3.4.0-beta.9",
|
|
31
32
|
"@midwayjs/logger": "^2.15.0",
|
|
32
33
|
"@types/amqplib": "0.8.2",
|
|
33
34
|
"amqplib": "0.10.0",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"ws": "8.8.0"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
41
|
+
"@midwayjs/async-hooks-context-manager": "^3.4.0-beta.9",
|
|
40
42
|
"@types/supertest": "2.0.12",
|
|
41
43
|
"fs-extra": "10.0.1",
|
|
42
44
|
"js-yaml": "4.1.0",
|
|
@@ -48,5 +50,5 @@
|
|
|
48
50
|
"type": "git",
|
|
49
51
|
"url": "http://github.com/midwayjs/midway.git"
|
|
50
52
|
},
|
|
51
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "41e82a0fba386c6ec42c2eefd1dff4795a81b389"
|
|
52
54
|
}
|
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
|
|
6
|
+
Z32Zo/anqEq60KjfuCFvp03CU8MOBbEYGxMtfUMooEQatEuiTTx03vkYbmg6ymGq
|
|
7
|
+
9g8YQCHcL0nel/+aCx0CU7ALo4OCX8k+Wxk76QIDAQABAoIBAAKy9XXQ6csim8Ft
|
|
8
|
+
Ixq6yUbQX9f4iFTFPuOzMTdsLitIhwpCyeECMWO4Zp3d0xlLgxWkpTSjx1SYcfW+
|
|
9
|
+
yWK1J5wFovjPTbe8Hh3L+JT0Lv06/68BWRFKaLZsIFmmKs6KZQq9Tw8rkb6WLqoU
|
|
10
|
+
oJDtMCGSgA03dwp8ZzFjOa00hB0ksF8LFJtf1kDAbUu9NF6hI738pKhZ/nmdglpy
|
|
11
|
+
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