@midwayjs/mock 3.0.0-beta.9 → 3.0.4-beta.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/http.d.ts +1 -1
- package/dist/creator.d.ts +10 -5
- package/dist/creator.js +49 -22
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +3 -2
- package/package.json +15 -14
- package/CHANGELOG.md +0 -2069
package/dist/client/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IMidwayApplication } from '@midwayjs/core';
|
|
2
2
|
import * as request from 'supertest';
|
|
3
|
-
export declare function createHttpRequest(app:
|
|
3
|
+
export declare function createHttpRequest<T extends IMidwayApplication<any>>(app: T): request.SuperTest<request.Test>;
|
|
4
4
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/creator.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
|
|
2
2
|
import { ComponentModule, MockAppConfigurationOptions } from './interface';
|
|
3
|
-
export declare function create<T extends IMidwayFramework<any, any,
|
|
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
|
-
export declare function createApp<T extends IMidwayFramework<any, any,
|
|
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
|
-
} | ComponentModule): Promise<
|
|
9
|
-
export declare function close(app:
|
|
8
|
+
} | ComponentModule): Promise<ReturnType<T['getApplication']>>;
|
|
9
|
+
export declare function close<T extends IMidwayApplication<any>>(app: T, options?: {
|
|
10
10
|
cleanLogsDir?: boolean;
|
|
11
11
|
cleanTempDir?: boolean;
|
|
12
12
|
sleep?: number;
|
|
13
13
|
}): Promise<void>;
|
|
14
|
-
export declare function createFunctionApp<T extends IMidwayFramework<any, any,
|
|
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
|
+
/**
|
|
18
|
+
* Create a real project but not ready or a virtual project
|
|
19
|
+
* @param baseDir
|
|
20
|
+
* @param options
|
|
21
|
+
*/
|
|
17
22
|
export declare function createLightApp(baseDir?: string, options?: MockAppConfigurationOptions): Promise<IMidwayApplication>;
|
|
18
23
|
//# sourceMappingURL=creator.d.ts.map
|
package/dist/creator.js
CHANGED
|
@@ -8,30 +8,35 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
8
8
|
const logger_1 = require("@midwayjs/logger");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const util_1 = require("util");
|
|
11
|
+
const fs_1 = require("fs");
|
|
11
12
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
12
13
|
process.setMaxListeners(0);
|
|
13
14
|
async function create(appDir = process.cwd(), options, customFramework) {
|
|
14
15
|
debug(`[mock]: Create app, appDir="${appDir}"`);
|
|
15
16
|
process.env.MIDWAY_TS_MODE = 'true';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (appDir) {
|
|
18
|
+
// 处理测试的 fixtures
|
|
19
|
+
if (!(0, path_1.isAbsolute)(appDir)) {
|
|
20
|
+
appDir = (0, path_1.join)(process.cwd(), 'test', 'fixtures', appDir);
|
|
21
|
+
}
|
|
22
|
+
if (!(0, fs_1.existsSync)(appDir)) {
|
|
23
|
+
throw new core_1.MidwayCommonError(`Path "${appDir}" not exists, please check it.`);
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
(0, logger_1.clearAllLoggers)();
|
|
21
27
|
options = options || {};
|
|
22
28
|
if (options.baseDir) {
|
|
23
29
|
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
24
30
|
}
|
|
25
|
-
else {
|
|
31
|
+
else if (appDir) {
|
|
26
32
|
options.baseDir = `${appDir}/src`;
|
|
27
33
|
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
28
34
|
}
|
|
29
|
-
if (!options.
|
|
30
|
-
options.
|
|
31
|
-
(0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
35
|
+
if (!options.imports && customFramework) {
|
|
36
|
+
options.imports = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
32
37
|
}
|
|
33
38
|
if (customFramework === null || customFramework === void 0 ? void 0 : customFramework['Configuration']) {
|
|
34
|
-
options.
|
|
39
|
+
options.imports = customFramework;
|
|
35
40
|
customFramework = customFramework['Framework'];
|
|
36
41
|
}
|
|
37
42
|
const container = new core_1.MidwayContainer();
|
|
@@ -61,9 +66,11 @@ async function create(appDir = process.cwd(), options, customFramework) {
|
|
|
61
66
|
await (0, core_1.initializeGlobalApplicationContext)({
|
|
62
67
|
...options,
|
|
63
68
|
appDir,
|
|
64
|
-
|
|
65
|
-
.concat(options.
|
|
66
|
-
.concat(
|
|
69
|
+
imports: []
|
|
70
|
+
.concat(options.imports)
|
|
71
|
+
.concat(options.baseDir
|
|
72
|
+
? (0, core_1.safeRequire)((0, path_1.join)(options.baseDir, 'configuration'))
|
|
73
|
+
: []),
|
|
67
74
|
});
|
|
68
75
|
if (customFramework) {
|
|
69
76
|
return container.getAsync(customFramework);
|
|
@@ -104,18 +111,26 @@ async function close(app, options) {
|
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
exports.close = close;
|
|
107
|
-
async function createFunctionApp(baseDir = process.cwd(), options,
|
|
108
|
-
const customFramework =
|
|
114
|
+
async function createFunctionApp(baseDir = process.cwd(), options, customFrameworkModule) {
|
|
115
|
+
const customFramework = customFrameworkModule !== null && customFrameworkModule !== void 0 ? customFrameworkModule : (0, utils_1.findFirstExistModule)([
|
|
109
116
|
process.env.MIDWAY_SERVERLESS_APP_NAME,
|
|
110
117
|
'@ali/serverless-app',
|
|
111
118
|
'@midwayjs/serverless-app',
|
|
112
119
|
]);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
const serverlessModule = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
121
|
+
if (serverlessModule) {
|
|
122
|
+
if (options && options.imports) {
|
|
123
|
+
options.imports.unshift(serverlessModule);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
options = {};
|
|
127
|
+
options.imports = [serverlessModule];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const framework = await createApp(baseDir, options);
|
|
131
|
+
const appCtx = framework.getApplicationContext();
|
|
132
|
+
const appManager = appCtx.get(core_1.MidwayApplicationManager);
|
|
133
|
+
return appManager.getApplication(core_1.MidwayFrameworkType.SERVERLESS_APP);
|
|
119
134
|
}
|
|
120
135
|
exports.createFunctionApp = createFunctionApp;
|
|
121
136
|
/**
|
|
@@ -134,13 +149,25 @@ class LightFramework extends core_1.BaseFramework {
|
|
|
134
149
|
return {};
|
|
135
150
|
}
|
|
136
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Create a real project but not ready or a virtual project
|
|
154
|
+
* @param baseDir
|
|
155
|
+
* @param options
|
|
156
|
+
*/
|
|
137
157
|
async function createLightApp(baseDir = '', options = {}) {
|
|
158
|
+
var _a;
|
|
138
159
|
(0, decorator_1.Framework)()(LightFramework);
|
|
160
|
+
options.globalConfig = Object.assign({
|
|
161
|
+
midwayLogger: {
|
|
162
|
+
default: {
|
|
163
|
+
disableFile: true,
|
|
164
|
+
disableError: true,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}, (_a = options.globalConfig) !== null && _a !== void 0 ? _a : {});
|
|
139
168
|
return createApp(baseDir, {
|
|
140
169
|
...options,
|
|
141
|
-
|
|
142
|
-
(0, utils_1.transformFrameworkToConfiguration)(LightFramework),
|
|
143
|
-
].concat(options === null || options === void 0 ? void 0 : options.configurationModule),
|
|
170
|
+
imports: [(0, utils_1.transformFrameworkToConfiguration)(LightFramework)].concat(options === null || options === void 0 ? void 0 : options.imports),
|
|
144
171
|
});
|
|
145
172
|
}
|
|
146
173
|
exports.createLightApp = createLightApp;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IMidwayFramework } from '@midwayjs/core';
|
|
2
|
+
import { ComponentModule } from './interface';
|
|
2
3
|
export declare function isTestEnvironment(): boolean;
|
|
3
4
|
export declare function isWin32(): boolean;
|
|
4
|
-
export declare function findFirstExistModule(moduleList: any):
|
|
5
|
+
export declare function findFirstExistModule(moduleList: any): ComponentModule;
|
|
5
6
|
/**
|
|
6
7
|
* transform a framework component or framework module to configuration class
|
|
7
8
|
* @param Framework
|
package/dist/utils.js
CHANGED
|
@@ -27,8 +27,7 @@ function findFirstExistModule(moduleList) {
|
|
|
27
27
|
if (!name)
|
|
28
28
|
continue;
|
|
29
29
|
try {
|
|
30
|
-
require
|
|
31
|
-
return name;
|
|
30
|
+
return require(name);
|
|
32
31
|
}
|
|
33
32
|
catch (e) {
|
|
34
33
|
// ignore
|
|
@@ -41,6 +40,8 @@ exports.findFirstExistModule = findFirstExistModule;
|
|
|
41
40
|
* @param Framework
|
|
42
41
|
*/
|
|
43
42
|
function transformFrameworkToConfiguration(Framework) {
|
|
43
|
+
if (!Framework)
|
|
44
|
+
return null;
|
|
44
45
|
let CustomFramework = Framework;
|
|
45
46
|
if (typeof Framework === 'string') {
|
|
46
47
|
Framework = (0, core_1.safeRequire)(Framework);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4-beta.1",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node --require=ts-node/register ../../node_modules/.bin/jest",
|
|
10
|
-
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
|
|
9
|
+
"test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
|
|
10
|
+
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
|
|
11
11
|
"link": "npm link"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -26,23 +26,24 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^3.0.
|
|
30
|
-
"@midwayjs/decorator": "^3.0.
|
|
31
|
-
"@midwayjs/logger": "^
|
|
32
|
-
"@types/amqplib": "
|
|
33
|
-
"amqplib": "
|
|
34
|
-
"socket.io": "
|
|
35
|
-
"socket.io-client": "
|
|
36
|
-
"ws": "
|
|
29
|
+
"@midwayjs/core": "^3.0.4-beta.1",
|
|
30
|
+
"@midwayjs/decorator": "^3.0.4-beta.1",
|
|
31
|
+
"@midwayjs/logger": "^2.14.0",
|
|
32
|
+
"@types/amqplib": "0.8.2",
|
|
33
|
+
"amqplib": "0.8.0",
|
|
34
|
+
"socket.io": "4.4.1",
|
|
35
|
+
"socket.io-client": "4.4.1",
|
|
36
|
+
"ws": "8.4.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"@types/supertest": "2.0.11",
|
|
40
|
+
"fs-extra": "10.0.0",
|
|
41
|
+
"supertest": "6.2.2"
|
|
41
42
|
},
|
|
42
43
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
43
44
|
"repository": {
|
|
44
45
|
"type": "git",
|
|
45
46
|
"url": "http://github.com/midwayjs/midway.git"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "52bc37e7a570806c121b33a0e8ac1cd084445f5d"
|
|
48
49
|
}
|