@midwayjs/mock 3.2.2 → 3.3.2

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.
@@ -1,5 +1,5 @@
1
1
  export * from './http';
2
2
  export * from './rabbitMQ';
3
3
  export * from './socketio';
4
- export * from './ws';
4
+ export * from './ws.client';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -11,4 +11,4 @@ async function createWebSocketClient(address, options) {
11
11
  });
12
12
  }
13
13
  exports.createWebSocketClient = createWebSocketClient;
14
- //# sourceMappingURL=ws.js.map
14
+ //# sourceMappingURL=ws.client.js.map
package/dist/mock.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IMidwayApplication, IMidwayContext } from '@midwayjs/core';
2
- export declare function mockSession(app: IMidwayApplication, key: string, value: string): void;
2
+ export declare function mockSession(app: IMidwayApplication, key: string, value: any): void;
3
3
  export declare function mockHeader(app: IMidwayApplication, headerKey: string, headerValue: string): void;
4
4
  export declare function mockClassProperty(clzz: new (...args: any[]) => any, propertyName: string, value: any): void;
5
5
  export declare function mockProperty(obj: any, key: string, value: any): void;
package/dist/mock.js CHANGED
@@ -6,6 +6,9 @@ function getMockService(app) {
6
6
  if (!app) {
7
7
  app = (0, core_1.getCurrentMainApp)();
8
8
  }
9
+ if (!app) {
10
+ return null;
11
+ }
9
12
  if (!app.getApplicationContext) {
10
13
  throw new Error('[mock]: app.getApplicationContext is undefined.');
11
14
  }
@@ -35,17 +38,32 @@ function mockHeader(app, headerKey, headerValue) {
35
38
  exports.mockHeader = mockHeader;
36
39
  function mockClassProperty(clzz, propertyName, value) {
37
40
  const mockService = getMockService();
38
- return mockService.mockClassProperty(clzz, propertyName, value);
41
+ if (!mockService) {
42
+ return core_1.MidwayMockService.mockClassProperty(clzz, propertyName, value);
43
+ }
44
+ else {
45
+ return mockService.mockClassProperty(clzz, propertyName, value);
46
+ }
39
47
  }
40
48
  exports.mockClassProperty = mockClassProperty;
41
49
  function mockProperty(obj, key, value) {
42
50
  const mockService = getMockService();
43
- return mockService.mockProperty(obj, key, value);
51
+ if (!mockService) {
52
+ return core_1.MidwayMockService.mockProperty(obj, key, value);
53
+ }
54
+ else {
55
+ return mockService.mockProperty(obj, key, value);
56
+ }
44
57
  }
45
58
  exports.mockProperty = mockProperty;
46
59
  function restoreAllMocks() {
47
60
  const mockService = getMockService();
48
- mockService.restore();
61
+ if (mockService) {
62
+ mockService.restore();
63
+ }
64
+ else {
65
+ core_1.MidwayMockService.prepareMocks = [];
66
+ }
49
67
  }
50
68
  exports.restoreAllMocks = restoreAllMocks;
51
69
  function mockContext(app, key, value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mock",
3
- "version": "3.2.2",
3
+ "version": "3.3.2",
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.2.2",
29
+ "@midwayjs/core": "^3.3.2",
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": "6bc097035302d01ae901d76a10e080db8554a864"
48
+ "gitHead": "2c7c235421ba904f8943efe31a71f452089d5d53"
49
49
  }