@midwayjs/mock 3.0.0-beta.6 → 3.0.0
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/README.md +1 -1
- package/dist/creator.d.ts +5 -0
- package/dist/creator.js +35 -16
- package/package.json +12 -12
- package/CHANGELOG.md +0 -2042
package/README.md
CHANGED
package/dist/creator.d.ts
CHANGED
|
@@ -14,5 +14,10 @@ export declare function close(app: IMidwayApplication, options?: {
|
|
|
14
14
|
export declare function createFunctionApp<T extends IMidwayFramework<any, any, U>, U = T['configurationOptions'], Y = ReturnType<T['getApplication']>>(baseDir?: string, options?: MockAppConfigurationOptions, customFrameworkName?: {
|
|
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);
|
|
@@ -112,8 +119,8 @@ async function createFunctionApp(baseDir = process.cwd(), options, customFramewo
|
|
|
112
119
|
]);
|
|
113
120
|
const framework = await createApp(baseDir, {
|
|
114
121
|
...options,
|
|
115
|
-
|
|
116
|
-
});
|
|
122
|
+
imports: (0, utils_1.transformFrameworkToConfiguration)(customFramework),
|
|
123
|
+
}, customFrameworkName);
|
|
117
124
|
framework.configurationOptions = options;
|
|
118
125
|
return framework;
|
|
119
126
|
}
|
|
@@ -134,13 +141,25 @@ class LightFramework extends core_1.BaseFramework {
|
|
|
134
141
|
return {};
|
|
135
142
|
}
|
|
136
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Create a real project but not ready or a virtual project
|
|
146
|
+
* @param baseDir
|
|
147
|
+
* @param options
|
|
148
|
+
*/
|
|
137
149
|
async function createLightApp(baseDir = '', options = {}) {
|
|
150
|
+
var _a;
|
|
138
151
|
(0, decorator_1.Framework)()(LightFramework);
|
|
152
|
+
options.globalConfig = Object.assign({
|
|
153
|
+
midwayLogger: {
|
|
154
|
+
default: {
|
|
155
|
+
disableFile: true,
|
|
156
|
+
disableError: true,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
}, (_a = options.globalConfig) !== null && _a !== void 0 ? _a : {});
|
|
139
160
|
return createApp(baseDir, {
|
|
140
161
|
...options,
|
|
141
|
-
|
|
142
|
-
(0, utils_1.transformFrameworkToConfiguration)(LightFramework),
|
|
143
|
-
].concat(options === null || options === void 0 ? void 0 : options.configurationModule),
|
|
162
|
+
imports: [(0, utils_1.transformFrameworkToConfiguration)(LightFramework)].concat(options === null || options === void 0 ? void 0 : options.imports),
|
|
144
163
|
});
|
|
145
164
|
}
|
|
146
165
|
exports.createLightApp = createLightApp;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
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,23 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^3.0.0
|
|
30
|
-
"@midwayjs/decorator": "^3.0.0
|
|
31
|
-
"@midwayjs/logger": "
|
|
29
|
+
"@midwayjs/core": "^3.0.0",
|
|
30
|
+
"@midwayjs/decorator": "^3.0.0",
|
|
31
|
+
"@midwayjs/logger": "2.14.0",
|
|
32
32
|
"@types/amqplib": "*",
|
|
33
33
|
"amqplib": "*",
|
|
34
|
-
"socket.io": "
|
|
35
|
-
"socket.io-client": "
|
|
36
|
-
"ws": "
|
|
34
|
+
"socket.io": "4.4.1",
|
|
35
|
+
"socket.io-client": "4.4.1",
|
|
36
|
+
"ws": "8.4.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"fs-extra": "
|
|
40
|
-
"supertest": "
|
|
39
|
+
"fs-extra": "10.0.0",
|
|
40
|
+
"supertest": "6.2.2"
|
|
41
41
|
},
|
|
42
42
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|
|
45
45
|
"url": "http://github.com/midwayjs/midway.git"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
|
|
48
48
|
}
|