@midwayjs/mock 3.2.0 → 3.3.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/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/{ws.d.ts → ws.client.d.ts} +1 -1
- package/dist/client/{ws.js → ws.client.js} +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mock.d.ts +8 -0
- package/dist/mock.js +74 -0
- package/package.json +3 -3
package/dist/client/index.d.ts
CHANGED
package/dist/client/index.js
CHANGED
|
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./http"), exports);
|
|
18
18
|
__exportStar(require("./rabbitMQ"), exports);
|
|
19
19
|
__exportStar(require("./socketio"), exports);
|
|
20
|
-
__exportStar(require("./ws"), exports);
|
|
20
|
+
__exportStar(require("./ws.client"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,4 +3,4 @@ import * as WebSocket from 'ws';
|
|
|
3
3
|
import * as http from 'http';
|
|
4
4
|
import * as url from 'url';
|
|
5
5
|
export declare function createWebSocketClient(address: string | url.URL, options?: WebSocket.ClientOptions | http.ClientRequestArgs): Promise<WebSocket>;
|
|
6
|
-
//# sourceMappingURL=ws.d.ts.map
|
|
6
|
+
//# sourceMappingURL=ws.client.d.ts.map
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,4 +24,5 @@ Object.defineProperty(exports, "createLightApp", { enumerable: true, get: functi
|
|
|
24
24
|
__exportStar(require("./client/index"), exports);
|
|
25
25
|
var utils_1 = require("./utils");
|
|
26
26
|
Object.defineProperty(exports, "transformFrameworkToConfiguration", { enumerable: true, get: function () { return utils_1.transformFrameworkToConfiguration; } });
|
|
27
|
+
__exportStar(require("./mock"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
2
|
+
export declare function mockSession(app: IMidwayApplication, key: string, value: any): void;
|
|
3
|
+
export declare function mockHeader(app: IMidwayApplication, headerKey: string, headerValue: string): void;
|
|
4
|
+
export declare function mockClassProperty(clzz: new (...args: any[]) => any, propertyName: string, value: any): void;
|
|
5
|
+
export declare function mockProperty(obj: any, key: string, value: any): void;
|
|
6
|
+
export declare function restoreAllMocks(): void;
|
|
7
|
+
export declare function mockContext(app: IMidwayApplication, key: string | ((ctx: IMidwayContext) => void), value?: PropertyDescriptor | any): void;
|
|
8
|
+
//# sourceMappingURL=mock.d.ts.map
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockContext = exports.restoreAllMocks = exports.mockProperty = exports.mockClassProperty = exports.mockHeader = exports.mockSession = void 0;
|
|
4
|
+
const core_1 = require("@midwayjs/core");
|
|
5
|
+
function getMockService(app) {
|
|
6
|
+
if (!app) {
|
|
7
|
+
app = (0, core_1.getCurrentMainApp)();
|
|
8
|
+
}
|
|
9
|
+
if (!app) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (!app.getApplicationContext) {
|
|
13
|
+
throw new Error('[mock]: app.getApplicationContext is undefined.');
|
|
14
|
+
}
|
|
15
|
+
const applicationContext = app.getApplicationContext();
|
|
16
|
+
const mockService = applicationContext.get(core_1.MidwayMockService);
|
|
17
|
+
if (!mockService) {
|
|
18
|
+
throw new Error('[mock]: MidwayMockService is undefined.');
|
|
19
|
+
}
|
|
20
|
+
return mockService;
|
|
21
|
+
}
|
|
22
|
+
function mockSession(app, key, value) {
|
|
23
|
+
const mockService = getMockService(app);
|
|
24
|
+
mockService.mockContext(app, (ctx) => {
|
|
25
|
+
if (!ctx.session) {
|
|
26
|
+
ctx.session = {};
|
|
27
|
+
}
|
|
28
|
+
ctx.session[key] = value;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.mockSession = mockSession;
|
|
32
|
+
function mockHeader(app, headerKey, headerValue) {
|
|
33
|
+
const mockService = getMockService(app);
|
|
34
|
+
mockService.mockContext(app, (ctx) => {
|
|
35
|
+
ctx.headers[headerKey] = headerValue;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.mockHeader = mockHeader;
|
|
39
|
+
function mockClassProperty(clzz, propertyName, value) {
|
|
40
|
+
const mockService = getMockService();
|
|
41
|
+
if (!mockService) {
|
|
42
|
+
return core_1.MidwayMockService.mockClassProperty(clzz, propertyName, value);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return mockService.mockClassProperty(clzz, propertyName, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.mockClassProperty = mockClassProperty;
|
|
49
|
+
function mockProperty(obj, key, value) {
|
|
50
|
+
const mockService = getMockService();
|
|
51
|
+
if (!mockService) {
|
|
52
|
+
return core_1.MidwayMockService.mockProperty(obj, key, value);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return mockService.mockProperty(obj, key, value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.mockProperty = mockProperty;
|
|
59
|
+
function restoreAllMocks() {
|
|
60
|
+
const mockService = getMockService();
|
|
61
|
+
if (mockService) {
|
|
62
|
+
mockService.restore();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
core_1.MidwayMockService.prepareMocks = [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.restoreAllMocks = restoreAllMocks;
|
|
69
|
+
function mockContext(app, key, value) {
|
|
70
|
+
const mockService = getMockService(app);
|
|
71
|
+
mockService.mockContext(app, key, value);
|
|
72
|
+
}
|
|
73
|
+
exports.mockContext = mockContext;
|
|
74
|
+
//# sourceMappingURL=mock.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@midwayjs/core": "^3.
|
|
29
|
+
"@midwayjs/core": "^3.3.1",
|
|
30
30
|
"@midwayjs/decorator": "^3.1.6",
|
|
31
31
|
"@midwayjs/logger": "^2.15.0",
|
|
32
32
|
"@types/amqplib": "0.8.2",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"type": "git",
|
|
46
46
|
"url": "http://github.com/midwayjs/midway.git"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f603b622b205ec126de628eeab59f90045a75dd2"
|
|
49
49
|
}
|