@bigtyphoon/melo 1.7.6
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/LICENSE +22 -0
- package/README.md +55 -0
- package/bin/commadtest.ts +10 -0
- package/bin/commands/add.ts +43 -0
- package/bin/commands/init.ts +292 -0
- package/bin/commands/kill.ts +21 -0
- package/bin/commands/list.ts +60 -0
- package/bin/commands/masterha.ts +40 -0
- package/bin/commands/restart.ts +48 -0
- package/bin/commands/start.ts +65 -0
- package/bin/commands/stop.ts +26 -0
- package/bin/melo.ts +30 -0
- package/bin/utils/constants.ts +27 -0
- package/bin/utils/utils.ts +130 -0
- package/dist/bin/commadtest.js +9 -0
- package/dist/bin/commands/add.js +40 -0
- package/dist/bin/commands/init.js +279 -0
- package/dist/bin/commands/kill.js +21 -0
- package/dist/bin/commands/list.js +65 -0
- package/dist/bin/commands/masterha.js +36 -0
- package/dist/bin/commands/restart.js +45 -0
- package/dist/bin/commands/start.js +58 -0
- package/dist/bin/commands/stop.js +20 -0
- package/dist/bin/melo.js +26 -0
- package/dist/bin/utils/constants.js +28 -0
- package/dist/bin/utils/utils.js +134 -0
- package/dist/lib/application.js +888 -0
- package/dist/lib/common/manager/appManager.js +112 -0
- package/dist/lib/common/manager/taskManager.js +39 -0
- package/dist/lib/common/remote/backend/msgRemote.js +63 -0
- package/dist/lib/common/remote/frontend/channelRemote.js +78 -0
- package/dist/lib/common/remote/frontend/sessionRemote.js +76 -0
- package/dist/lib/common/service/backendSessionService.js +337 -0
- package/dist/lib/common/service/channelService.js +514 -0
- package/dist/lib/common/service/connectionService.js +95 -0
- package/dist/lib/common/service/filterService.js +112 -0
- package/dist/lib/common/service/handlerService.js +187 -0
- package/dist/lib/common/service/sessionService.js +610 -0
- package/dist/lib/components/backendSession.js +14 -0
- package/dist/lib/components/channel.js +13 -0
- package/dist/lib/components/connection.js +12 -0
- package/dist/lib/components/connector.js +437 -0
- package/dist/lib/components/dictionary.js +93 -0
- package/dist/lib/components/master.js +39 -0
- package/dist/lib/components/monitor.js +25 -0
- package/dist/lib/components/protobuf.js +156 -0
- package/dist/lib/components/proxy.js +236 -0
- package/dist/lib/components/pushScheduler.js +62 -0
- package/dist/lib/components/remote.js +127 -0
- package/dist/lib/components/server.js +63 -0
- package/dist/lib/components/session.js +20 -0
- package/dist/lib/connectors/commands/handshake.js +119 -0
- package/dist/lib/connectors/commands/heartbeat.js +67 -0
- package/dist/lib/connectors/commands/kick.js +15 -0
- package/dist/lib/connectors/common/coder.js +90 -0
- package/dist/lib/connectors/common/handler.js +57 -0
- package/dist/lib/connectors/hybrid/IHybridSocket.js +3 -0
- package/dist/lib/connectors/hybrid/switcher.js +100 -0
- package/dist/lib/connectors/hybrid/tcpprocessor.js +40 -0
- package/dist/lib/connectors/hybrid/tcpsocket.js +171 -0
- package/dist/lib/connectors/hybrid/wsprocessor.js +49 -0
- package/dist/lib/connectors/hybridconnector.js +89 -0
- package/dist/lib/connectors/hybridsocket.js +139 -0
- package/dist/lib/connectors/mqtt/generate.js +113 -0
- package/dist/lib/connectors/mqtt/mqttadaptor.js +81 -0
- package/dist/lib/connectors/mqtt/protocol.js +48 -0
- package/dist/lib/connectors/mqttconnector.js +107 -0
- package/dist/lib/connectors/mqttsocket.js +59 -0
- package/dist/lib/connectors/sioconnector.js +135 -0
- package/dist/lib/connectors/siosocket.js +69 -0
- package/dist/lib/connectors/udpconnector.js +76 -0
- package/dist/lib/connectors/udpsocket.js +93 -0
- package/dist/lib/filters/handler/serial.js +44 -0
- package/dist/lib/filters/handler/time.js +32 -0
- package/dist/lib/filters/handler/timeout.js +45 -0
- package/dist/lib/filters/handler/toobusy.js +36 -0
- package/dist/lib/filters/rpc/rpcLog.js +43 -0
- package/dist/lib/filters/rpc/toobusy.js +41 -0
- package/dist/lib/index.js +81 -0
- package/dist/lib/interfaces/IComponent.js +3 -0
- package/dist/lib/interfaces/IConnector.js +3 -0
- package/dist/lib/interfaces/IHandlerFilter.js +3 -0
- package/dist/lib/interfaces/ILifeCycle.js +3 -0
- package/dist/lib/interfaces/IPlugin.js +3 -0
- package/dist/lib/interfaces/IPushScheduler.js +3 -0
- package/dist/lib/interfaces/ISocket.js +3 -0
- package/dist/lib/interfaces/IStore.js +3 -0
- package/dist/lib/interfaces/define.js +3 -0
- package/dist/lib/master/master.js +129 -0
- package/dist/lib/master/starter.js +236 -0
- package/dist/lib/master/watchdog.js +120 -0
- package/dist/lib/melo.js +125 -0
- package/dist/lib/modules/console.js +436 -0
- package/dist/lib/modules/masterwatcher.js +98 -0
- package/dist/lib/modules/monitorwatcher.js +124 -0
- package/dist/lib/modules/onlineUser.js +69 -0
- package/dist/lib/modules/restartNotifyModule.js +107 -0
- package/dist/lib/modules/watchServer.js +737 -0
- package/dist/lib/monitor/monitor.js +80 -0
- package/dist/lib/pushSchedulers/buffer.js +96 -0
- package/dist/lib/pushSchedulers/direct.js +58 -0
- package/dist/lib/pushSchedulers/multi.js +80 -0
- package/dist/lib/server/server.js +500 -0
- package/dist/lib/util/appUtil.js +306 -0
- package/dist/lib/util/constants.js +117 -0
- package/dist/lib/util/countDownLatch.js +51 -0
- package/dist/lib/util/events.js +20 -0
- package/dist/lib/util/handlerHelper.js +8 -0
- package/dist/lib/util/log.js +14 -0
- package/dist/lib/util/moduleUtil.js +101 -0
- package/dist/lib/util/pathUtil.js +134 -0
- package/dist/lib/util/remoterHelper.js +8 -0
- package/dist/lib/util/utils.js +358 -0
- package/dist/test/application.js +522 -0
- package/dist/test/config/log4js.json +28 -0
- package/dist/test/config/master.json +9 -0
- package/dist/test/config/servers.json +6 -0
- package/dist/test/filters/handler/serial.js +41 -0
- package/dist/test/filters/handler/time.js +41 -0
- package/dist/test/filters/handler/timeout.js +41 -0
- package/dist/test/filters/handler/toobusy.js +57 -0
- package/dist/test/filters/rpc/rpcLog.js +22 -0
- package/dist/test/filters/rpc/toobusy.js +39 -0
- package/dist/test/manager/mockChannelManager.js +77 -0
- package/dist/test/manager/taskManager.js +68 -0
- package/dist/test/mock-base/app/servers/other-file +0 -0
- package/dist/test/mock-plugin/components/mockPlugin.js +10 -0
- package/dist/test/mock-plugin/events/mockEvent.js +12 -0
- package/dist/test/modules/console.js +242 -0
- package/dist/test/pomelo.js +19 -0
- package/dist/test/remote/channelRemote.js +159 -0
- package/dist/test/service/channel.js +134 -0
- package/dist/test/service/channelService.js +216 -0
- package/dist/test/service/connectionService.js +114 -0
- package/dist/test/service/filterService.js +144 -0
- package/dist/test/service/handlerService.js +65 -0
- package/dist/test/service/sessionService.js +387 -0
- package/dist/test/util/countDownLatch.js +70 -0
- package/dist/test/util/pathUtil.js +108 -0
- package/dist/test/util/utils.js +140 -0
- package/lib/application.ts +1240 -0
- package/lib/common/manager/appManager.ts +118 -0
- package/lib/common/manager/taskManager.ts +50 -0
- package/lib/common/remote/backend/msgRemote.ts +134 -0
- package/lib/common/remote/frontend/channelRemote.ts +91 -0
- package/lib/common/remote/frontend/sessionRemote.ts +91 -0
- package/lib/common/service/backendSessionService.ts +388 -0
- package/lib/common/service/channelService.ts +609 -0
- package/lib/common/service/connectionService.ts +112 -0
- package/lib/common/service/filterService.ts +118 -0
- package/lib/common/service/handlerService.ts +224 -0
- package/lib/common/service/sessionService.ts +731 -0
- package/lib/components/backendSession.ts +14 -0
- package/lib/components/channel.ts +11 -0
- package/lib/components/connection.ts +13 -0
- package/lib/components/connector.ts +533 -0
- package/lib/components/dictionary.ts +121 -0
- package/lib/components/master.ts +41 -0
- package/lib/components/monitor.ts +30 -0
- package/lib/components/protobuf.ts +208 -0
- package/lib/components/proxy.ts +282 -0
- package/lib/components/pushScheduler.ts +70 -0
- package/lib/components/remote.ts +166 -0
- package/lib/components/server.ts +71 -0
- package/lib/components/session.ts +22 -0
- package/lib/connectors/commands/handshake.ts +155 -0
- package/lib/connectors/commands/heartbeat.ts +83 -0
- package/lib/connectors/commands/kick.ts +11 -0
- package/lib/connectors/common/coder.ts +93 -0
- package/lib/connectors/common/handler.ts +62 -0
- package/lib/connectors/hybrid/IHybridSocket.ts +9 -0
- package/lib/connectors/hybrid/switcher.ts +142 -0
- package/lib/connectors/hybrid/tcpprocessor.ts +43 -0
- package/lib/connectors/hybrid/tcpsocket.ts +223 -0
- package/lib/connectors/hybrid/wsprocessor.ts +57 -0
- package/lib/connectors/hybridconnector.ts +134 -0
- package/lib/connectors/hybridsocket.ts +168 -0
- package/lib/connectors/mqtt/generate.ts +103 -0
- package/lib/connectors/mqtt/mqttadaptor.ts +114 -0
- package/lib/connectors/mqtt/protocol.ts +49 -0
- package/lib/connectors/mqttconnector.ts +134 -0
- package/lib/connectors/mqttsocket.ts +79 -0
- package/lib/connectors/sioconnector.ts +161 -0
- package/lib/connectors/siosocket.ts +85 -0
- package/lib/connectors/udpconnector.ts +113 -0
- package/lib/connectors/udpsocket.ts +110 -0
- package/lib/filters/handler/serial.ts +46 -0
- package/lib/filters/handler/time.ts +35 -0
- package/lib/filters/handler/timeout.ts +50 -0
- package/lib/filters/handler/toobusy.ts +37 -0
- package/lib/filters/rpc/rpcLog.ts +42 -0
- package/lib/filters/rpc/toobusy.ts +41 -0
- package/lib/index.ts +74 -0
- package/lib/interfaces/IComponent.ts +47 -0
- package/lib/interfaces/IConnector.ts +20 -0
- package/lib/interfaces/IHandlerFilter.ts +15 -0
- package/lib/interfaces/ILifeCycle.ts +16 -0
- package/lib/interfaces/IPlugin.ts +65 -0
- package/lib/interfaces/IPushScheduler.ts +52 -0
- package/lib/interfaces/ISocket.ts +26 -0
- package/lib/interfaces/IStore.ts +10 -0
- package/lib/interfaces/define.ts +15 -0
- package/lib/master/master.ts +148 -0
- package/lib/master/starter.ts +234 -0
- package/lib/master/watchdog.ts +135 -0
- package/lib/melo.ts +152 -0
- package/lib/modules/console.ts +465 -0
- package/lib/modules/masterwatcher.ts +120 -0
- package/lib/modules/monitorwatcher.ts +151 -0
- package/lib/modules/onlineUser.ts +78 -0
- package/lib/modules/restartNotifyModule.ts +128 -0
- package/lib/modules/watchServer.ts +766 -0
- package/lib/monitor/monitor.ts +99 -0
- package/lib/pushSchedulers/buffer.ts +117 -0
- package/lib/pushSchedulers/direct.ts +65 -0
- package/lib/pushSchedulers/multi.ts +94 -0
- package/lib/server/server.ts +554 -0
- package/lib/util/appUtil.ts +313 -0
- package/lib/util/constants.ts +154 -0
- package/lib/util/countDownLatch.ts +72 -0
- package/lib/util/events.ts +15 -0
- package/lib/util/handlerHelper.ts +5 -0
- package/lib/util/log.ts +11 -0
- package/lib/util/moduleUtil.ts +110 -0
- package/lib/util/pathUtil.ts +132 -0
- package/lib/util/remoterHelper.ts +68 -0
- package/lib/util/utils.ts +365 -0
- package/package.json +93 -0
- package/template/game-server/.vscode/launch.json +27 -0
- package/template/game-server/app/servers/connector/handler/entryHandler.ts +50 -0
- package/template/game-server/app/servers/connector/remote/authRemoter.ts +36 -0
- package/template/game-server/app.ts +30 -0
- package/template/game-server/app.ts.mqtt +32 -0
- package/template/game-server/app.ts.sio +36 -0
- package/template/game-server/app.ts.sio.wss +34 -0
- package/template/game-server/app.ts.udp +31 -0
- package/template/game-server/app.ts.wss +40 -0
- package/template/game-server/config/adminServer.json +5 -0
- package/template/game-server/config/adminUser.json +22 -0
- package/template/game-server/config/clientProtos.json +1 -0
- package/template/game-server/config/dictionary.json +1 -0
- package/template/game-server/config/log4js.json +150 -0
- package/template/game-server/config/master.json +8 -0
- package/template/game-server/config/serverProtos.json +1 -0
- package/template/game-server/config/servers.json +12 -0
- package/template/game-server/copy.js +5 -0
- package/template/game-server/package.json +28 -0
- package/template/game-server/preload.ts +40 -0
- package/template/game-server/tsconfig.json +36 -0
- package/template/npm-install.bat +4 -0
- package/template/npm-install.sh +5 -0
- package/template/readme.md +31 -0
- package/template/shared/server.crt +15 -0
- package/template/shared/server.key +15 -0
- package/template/web-server/app.js +25 -0
- package/template/web-server/app.js.https +36 -0
- package/template/web-server/bin/component.bat +1 -0
- package/template/web-server/bin/component.sh +1 -0
- package/template/web-server/package.json +10 -0
- package/template/web-server/public/css/base.css +76 -0
- package/template/web-server/public/image/logo.png +0 -0
- package/template/web-server/public/image/sp.png +0 -0
- package/template/web-server/public/index.html +57 -0
- package/template/web-server/public/index.html.sio +58 -0
- package/template/web-server/public/js/lib/build/build.js +1730 -0
- package/template/web-server/public/js/lib/build/build.js.wss +1721 -0
- package/template/web-server/public/js/lib/component.json +6 -0
- package/template/web-server/public/js/lib/local/boot/component.json +11 -0
- package/template/web-server/public/js/lib/local/boot/index.js +11 -0
- package/template/web-server/public/js/lib/meloclient.js +456 -0
- package/template/web-server/public/js/lib/meloclient.js.wss +456 -0
- package/template/web-server/public/js/lib/socket.io.js +3 -0
- package/test/application.ts +607 -0
- package/test/filters/handler/serial.ts +47 -0
- package/test/filters/handler/time.ts +47 -0
- package/test/filters/handler/timeout.ts +46 -0
- package/test/filters/handler/toobusy.ts +59 -0
- package/test/filters/rpc/rpcLog.ts +20 -0
- package/test/filters/rpc/toobusy.ts +40 -0
- package/test/manager/mockChannelManager.ts +92 -0
- package/test/manager/taskManager.ts +78 -0
- package/test/mock-base/app/servers/other-file +0 -0
- package/test/mock-plugin/components/mockPlugin.ts +8 -0
- package/test/mock-plugin/events/mockEvent.ts +12 -0
- package/test/modules/console.ts +264 -0
- package/test/pomelo.ts +18 -0
- package/test/remote/channelRemote.ts +176 -0
- package/test/service/channel.ts +161 -0
- package/test/service/channelService.ts +243 -0
- package/test/service/connectionService.ts +142 -0
- package/test/service/filterService.ts +165 -0
- package/test/service/handlerService.ts +77 -0
- package/test/service/sessionService.ts +464 -0
- package/test/util/countDownLatch.ts +81 -0
- package/test/util/pathUtil.ts +122 -0
- package/test/util/utils.ts +165 -0
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import { Application, IComponent, events } from '../lib/index';
|
|
2
|
+
import * as should from 'should';
|
|
3
|
+
import { MockPlugin } from './mock-plugin/components/mockPlugin';
|
|
4
|
+
import { MockEvent } from './mock-plugin/events/mockEvent';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
declare var afterEach: any;
|
|
8
|
+
let WAIT_TIME = 1000;
|
|
9
|
+
let mockBase = process.cwd() + '/test';
|
|
10
|
+
|
|
11
|
+
let app = new Application();
|
|
12
|
+
|
|
13
|
+
describe('application test', function () {
|
|
14
|
+
afterEach(function () {
|
|
15
|
+
app.state = 0;
|
|
16
|
+
app.settings = {};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('#init', function () {
|
|
20
|
+
it('should init the app instance', function () {
|
|
21
|
+
app.init({ base: mockBase });
|
|
22
|
+
app.state.should.equal(1); // magic number from application.js
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('#set and get', function () {
|
|
27
|
+
it('should play the role of normal set and get', function () {
|
|
28
|
+
should.not.exist(app.get('some undefined key'));
|
|
29
|
+
|
|
30
|
+
let key = 'some defined key', value = 'some value';
|
|
31
|
+
app.set(key, value);
|
|
32
|
+
value.should.equal(app.get(key));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should return the value if pass just one parameter to the set method', function () {
|
|
36
|
+
let key = 'some defined key', value = 'some value';
|
|
37
|
+
should.not.exist(app.get(key));
|
|
38
|
+
app.set(key, value);
|
|
39
|
+
value.should.equal(app.get(key));
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('#enable and disable', function () {
|
|
44
|
+
it('should play the role of enable and disable', function () {
|
|
45
|
+
let key = 'some enable key';
|
|
46
|
+
app.enabled(key).should.be.false;
|
|
47
|
+
app.disabled(key).should.be.true;
|
|
48
|
+
|
|
49
|
+
app.enable(key);
|
|
50
|
+
app.enabled(key).should.be.true;
|
|
51
|
+
app.disabled(key).should.be.false;
|
|
52
|
+
|
|
53
|
+
app.disable(key);
|
|
54
|
+
app.enabled(key).should.be.false;
|
|
55
|
+
app.disabled(key).should.be.true;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('#compoent', function () {
|
|
60
|
+
it('should load the component and fire their lifecircle callback by app.start, app.afterStart, app.stop', function (done: Mocha.Done) {
|
|
61
|
+
let startCount = 0, afterStartCount = 0, stopCount = 0;
|
|
62
|
+
if(require('os').platform() === 'linux') {
|
|
63
|
+
done();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.timeout(8000)
|
|
67
|
+
let mockComponent = {
|
|
68
|
+
name : 'mockComponent',
|
|
69
|
+
start: function (cb: Function) {
|
|
70
|
+
console.log('start invoked');
|
|
71
|
+
startCount++;
|
|
72
|
+
cb();
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
afterStart: function (cb: Function) {
|
|
76
|
+
console.log('afterStart invoked');
|
|
77
|
+
afterStartCount++;
|
|
78
|
+
cb();
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
stop: function (force: any, cb: Function) {
|
|
82
|
+
console.log('stop invoked');
|
|
83
|
+
stopCount++;
|
|
84
|
+
cb();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
app.init({ base: mockBase });
|
|
89
|
+
app.components.__monitor__ = { monitor: null, name: 'mockMonitor', start: () => {}, stop: () => {}, reconnect: () => {} };
|
|
90
|
+
app.load(mockComponent);
|
|
91
|
+
app.start(function (err: Error) {
|
|
92
|
+
should.not.exist(err);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
setTimeout(function () {
|
|
96
|
+
// wait for after start
|
|
97
|
+
app.stop(false);
|
|
98
|
+
|
|
99
|
+
setTimeout(function () {
|
|
100
|
+
// wait for stop
|
|
101
|
+
startCount.should.equal(1);
|
|
102
|
+
afterStartCount.should.equal(1);
|
|
103
|
+
stopCount.should.equal(1);
|
|
104
|
+
done();
|
|
105
|
+
}, WAIT_TIME);
|
|
106
|
+
}, WAIT_TIME);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should access the component with a name by app.components.name after loaded', function () {
|
|
110
|
+
let key1 = 'key1', comp1 = new class implements IComponent { name: 'comp1'; content: 'some thing in comp1'; };
|
|
111
|
+
let comp2 = { name: 'key2', content: 'some thing in comp2' };
|
|
112
|
+
let key3 = 'key3';
|
|
113
|
+
let comp3 = function () {
|
|
114
|
+
return { content: 'some thing in comp3', name: key3 };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
app.init({ base: mockBase });
|
|
118
|
+
app.load(key1, comp1);
|
|
119
|
+
app.load(comp2);
|
|
120
|
+
app.load(comp3);
|
|
121
|
+
|
|
122
|
+
app.components.key1.should.eql(comp1);
|
|
123
|
+
app.components.key2.should.eql(comp2);
|
|
124
|
+
app.components.key3.should.eql(comp3());
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should ignore duplicated components', function () {
|
|
128
|
+
let key = 'key';
|
|
129
|
+
let comp1 = new class implements IComponent { name: 'comp1'; content: 'some thing in comp1'; };
|
|
130
|
+
let comp2 = new class implements IComponent { name: 'comp2'; content: 'some thing in comp2'; };
|
|
131
|
+
|
|
132
|
+
app.init({ base: mockBase });
|
|
133
|
+
app.load(key, comp1);
|
|
134
|
+
app.load(key, comp2);
|
|
135
|
+
|
|
136
|
+
app.components[key].should.equal(comp1);
|
|
137
|
+
app.components[key].should.not.equal(comp2);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('#filter', function () {
|
|
142
|
+
it('should add before filter and could fetch it later', function () {
|
|
143
|
+
let filters = [
|
|
144
|
+
function () { console.error('filter1'); },
|
|
145
|
+
function () { }
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
app.init({ base: mockBase });
|
|
149
|
+
|
|
150
|
+
let i, l;
|
|
151
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
152
|
+
app.before(filters[i]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let filters2 = app.get('__befores__');
|
|
156
|
+
should.exist(filters2);
|
|
157
|
+
filters2.length.should.equal(filters.length);
|
|
158
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
159
|
+
filters2[i].should.equal(filters[i]);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should add after filter and could fetch it later', function () {
|
|
164
|
+
let filters = [
|
|
165
|
+
function () { console.error('filter1'); },
|
|
166
|
+
function () { }
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
app.init({ base: mockBase });
|
|
170
|
+
|
|
171
|
+
let i, l;
|
|
172
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
173
|
+
app.after(filters[i]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let filters2 = app.get('__afters__');
|
|
177
|
+
should.exist(filters2);
|
|
178
|
+
filters2.length.should.equal(filters.length);
|
|
179
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
180
|
+
filters2[i].should.equal(filters[i]);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('should add filter and could fetch it from before and after filter later', function () {
|
|
185
|
+
let filters = [
|
|
186
|
+
function () { console.error('filter1'); },
|
|
187
|
+
function () { }
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
app.init({ base: mockBase });
|
|
191
|
+
|
|
192
|
+
let i, l;
|
|
193
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
194
|
+
app.before(filters[i]);
|
|
195
|
+
app.after(filters[i]);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let filters2 = app.get('__befores__');
|
|
199
|
+
should.exist(filters2);
|
|
200
|
+
filters2.length.should.equal(filters.length);
|
|
201
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
202
|
+
filters2[i].should.equal(filters[i]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let filters3 = app.get('__afters__');
|
|
206
|
+
should.exist(filters3);
|
|
207
|
+
filters3.length.should.equal(filters.length);
|
|
208
|
+
for (i = 0, l = filters3.length; i < l; i++) {
|
|
209
|
+
filters2[i].should.equal(filters[i]);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('#globalFilter', function () {
|
|
215
|
+
it('should add before global filter and could fetch it later', function () {
|
|
216
|
+
let filters = [
|
|
217
|
+
function () { console.error('global filter1'); },
|
|
218
|
+
function () { }
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
app.init({ base: mockBase });
|
|
222
|
+
|
|
223
|
+
let i, l;
|
|
224
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
225
|
+
app.globalBefore(filters[i]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let filters2 = app.get('__globalBefores__');
|
|
229
|
+
should.exist(filters2);
|
|
230
|
+
filters2.length.should.equal(filters.length);
|
|
231
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
232
|
+
filters2[i].should.equal(filters[i]);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should add after global filter and could fetch it later', function () {
|
|
237
|
+
let filters = [
|
|
238
|
+
function () { console.error('filter1'); },
|
|
239
|
+
function () { }
|
|
240
|
+
];
|
|
241
|
+
|
|
242
|
+
app.init({ base: mockBase });
|
|
243
|
+
|
|
244
|
+
let i, l;
|
|
245
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
246
|
+
app.globalAfter(filters[i]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let filters2 = app.get('__globalAfters__');
|
|
250
|
+
should.exist(filters2);
|
|
251
|
+
filters2.length.should.equal(filters.length);
|
|
252
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
253
|
+
filters2[i].should.equal(filters[i]);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('should add filter and could fetch it from before and after filter later', function () {
|
|
258
|
+
let filters = [
|
|
259
|
+
function () { console.error('filter1'); },
|
|
260
|
+
function () { }
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
app.init({ base: mockBase });
|
|
264
|
+
|
|
265
|
+
let i, l;
|
|
266
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
|
267
|
+
app.globalBefore(filters[i]);
|
|
268
|
+
app.globalAfter(filters[i]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let filters2 = app.get('__globalBefores__');
|
|
272
|
+
should.exist(filters2);
|
|
273
|
+
filters2.length.should.equal(filters.length);
|
|
274
|
+
for (i = 0, l = filters2.length; i < l; i++) {
|
|
275
|
+
filters2[i].should.equal(filters[i]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let filters3 = app.get('__globalAfters__');
|
|
279
|
+
should.exist(filters3);
|
|
280
|
+
filters3.length.should.equal(filters.length);
|
|
281
|
+
for (i = 0, l = filters3.length; i < l; i++) {
|
|
282
|
+
filters2[i].should.equal(filters[i]);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('#configure', function () {
|
|
288
|
+
it('should execute the code block wtih the right environment', function () {
|
|
289
|
+
let proCount = 0, devCount = 0;
|
|
290
|
+
let proEnv = 'production', devEnv = 'development', serverType = 'server';
|
|
291
|
+
|
|
292
|
+
app.init({ base: mockBase });
|
|
293
|
+
app.set('serverType', serverType);
|
|
294
|
+
app.set('env', proEnv);
|
|
295
|
+
|
|
296
|
+
app.configure(proEnv, serverType, function () {
|
|
297
|
+
proCount++;
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
app.configure(devEnv, serverType, function () {
|
|
301
|
+
devCount++;
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
app.set('env', devEnv);
|
|
305
|
+
|
|
306
|
+
app.configure(proEnv, serverType, function () {
|
|
307
|
+
proCount++;
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
app.configure(devEnv, serverType, function () {
|
|
311
|
+
devCount++;
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
proCount.should.equal(1);
|
|
315
|
+
devCount.should.equal(1);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should execute the code block wtih the right server', function () {
|
|
319
|
+
let server1Count = 0, server2Count = 0;
|
|
320
|
+
let proEnv = 'production', serverType1 = 'server1', serverType2 = 'server2';
|
|
321
|
+
|
|
322
|
+
app.init({ base: mockBase });
|
|
323
|
+
app.set('serverType', serverType1);
|
|
324
|
+
app.set('env', proEnv);
|
|
325
|
+
|
|
326
|
+
app.configure(proEnv, serverType1, function () {
|
|
327
|
+
server1Count++;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
app.configure(proEnv, serverType2, function () {
|
|
331
|
+
server2Count++;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
app.set('serverType', serverType2);
|
|
335
|
+
|
|
336
|
+
app.configure(proEnv, serverType1, function () {
|
|
337
|
+
server1Count++;
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
app.configure(proEnv, serverType2, function () {
|
|
341
|
+
server2Count++;
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
server1Count.should.equal(1);
|
|
345
|
+
server2Count.should.equal(1);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe('#route', function () {
|
|
350
|
+
it('should add route record and could fetch it later', function () {
|
|
351
|
+
let type1 = 'area', type2 = 'connector';
|
|
352
|
+
let func1 = function () { console.log('func1'); };
|
|
353
|
+
let func2 = function () { console.log('func2'); };
|
|
354
|
+
|
|
355
|
+
app.init({ base: mockBase });
|
|
356
|
+
|
|
357
|
+
app.route(type1, func1);
|
|
358
|
+
app.route(type2, func2);
|
|
359
|
+
|
|
360
|
+
let routes = app.get('__routes__');
|
|
361
|
+
should.exist(routes);
|
|
362
|
+
func1.should.equal(routes[type1]);
|
|
363
|
+
func2.should.equal(routes[type2]);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('#transaction', function () {
|
|
368
|
+
it('should execute all conditions and handlers', function () {
|
|
369
|
+
let conditions = {
|
|
370
|
+
test1: function (cb: Function) {
|
|
371
|
+
console.log('condition1');
|
|
372
|
+
cb();
|
|
373
|
+
},
|
|
374
|
+
test2: function (cb: Function) {
|
|
375
|
+
console.log('condition2');
|
|
376
|
+
cb();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
let flag = 1;
|
|
380
|
+
let handlers = {
|
|
381
|
+
do1: function (cb: Function) {
|
|
382
|
+
console.log('handler1');
|
|
383
|
+
cb();
|
|
384
|
+
},
|
|
385
|
+
do2: function (cb: Function) {
|
|
386
|
+
console.log('handler2');
|
|
387
|
+
if (flag < 3) {
|
|
388
|
+
flag++;
|
|
389
|
+
cb(new Error('error'));
|
|
390
|
+
} else {
|
|
391
|
+
cb();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
app.transaction('test', conditions, handlers, 5);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('shoud execute conditions with error and do not execute handlers', function () {
|
|
399
|
+
let conditions = {
|
|
400
|
+
test1: function (cb: Function) {
|
|
401
|
+
console.log('condition1');
|
|
402
|
+
cb();
|
|
403
|
+
},
|
|
404
|
+
test2: function (cb: Function) {
|
|
405
|
+
console.log('condition2');
|
|
406
|
+
cb(new Error('error'));
|
|
407
|
+
},
|
|
408
|
+
test3: function (cb: Function) {
|
|
409
|
+
console.log('condition3');
|
|
410
|
+
cb();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
let handlers = {
|
|
414
|
+
do1: function (cb: Function) {
|
|
415
|
+
console.log('handler1');
|
|
416
|
+
cb();
|
|
417
|
+
},
|
|
418
|
+
do2: function (cb: Function) {
|
|
419
|
+
console.log('handler2');
|
|
420
|
+
cb();
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
app.transaction('test', conditions, handlers);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe('#add and remove servers', function () {
|
|
428
|
+
it('should add servers and emit event and fetch the new server info by get methods', function (done: Mocha.Done) {
|
|
429
|
+
let newServers = [
|
|
430
|
+
{ id: 'connector-server-1', serverType: 'connecctor', host: '127.0.0.1', port: 1234, clientPort: 3000, frontend: true },
|
|
431
|
+
{ id: 'area-server-1', serverType: 'area', host: '127.0.0.1', port: 2234 }
|
|
432
|
+
];
|
|
433
|
+
app.init({ base: mockBase });
|
|
434
|
+
app.event.on(events.ADD_SERVERS, function (servers: Array<{ [key: string]: any }>) {
|
|
435
|
+
// check event args
|
|
436
|
+
newServers.should.eql(servers);
|
|
437
|
+
|
|
438
|
+
// check servers
|
|
439
|
+
let curServers = app.getServers();
|
|
440
|
+
should.exist(curServers);
|
|
441
|
+
let item, i, l;
|
|
442
|
+
for (i = 0, l = newServers.length; i < l; i++) {
|
|
443
|
+
item = newServers[i];
|
|
444
|
+
item.should.eql(curServers[item.id]);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// check get server by id
|
|
448
|
+
for (i = 0, l = newServers.length; i < l; i++) {
|
|
449
|
+
item = newServers[i];
|
|
450
|
+
item.should.eql(app.getServerById(item.id));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// check server types
|
|
454
|
+
let types = [];
|
|
455
|
+
for (i = 0, l = newServers.length; i < l; i++) {
|
|
456
|
+
item = newServers[i];
|
|
457
|
+
if (types.indexOf(item.serverType) < 0) {
|
|
458
|
+
types.push(item.serverType);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
let types2 = app.getServerTypes();
|
|
462
|
+
types.length.should.equal(types2.length);
|
|
463
|
+
for (i = 0, l = types.length; i < l; i++) {
|
|
464
|
+
types2.should.containEql(types[i]);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// check server type list
|
|
468
|
+
let slist;
|
|
469
|
+
for (i = 0, l = newServers.length; i < l; i++) {
|
|
470
|
+
item = newServers[i];
|
|
471
|
+
slist = app.getServersByType(item.serverType);
|
|
472
|
+
should.exist(slist);
|
|
473
|
+
contains(slist, item).should.be.true;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
done();
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
app.addServers(newServers);
|
|
480
|
+
app.event.removeAllListeners()
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('should remove server info and emit event', function (done: Mocha.Done) {
|
|
484
|
+
let newServers = [
|
|
485
|
+
{ id: 'connector-server-1', serverType: 'connecctor', host: '127.0.0.1', port: 1234, clientPort: 3000, frontend: true },
|
|
486
|
+
{ id: 'area-server-1', serverType: 'area', host: '127.0.0.1', port: 2234 },
|
|
487
|
+
{ id: 'path-server-1', serverType: 'path', host: '127.0.0.1', port: 2235 }
|
|
488
|
+
];
|
|
489
|
+
let destServers = [
|
|
490
|
+
{ id: 'connector-server-1', serverType: 'connecctor', host: '127.0.0.1', port: 1234, clientPort: 3000, frontend: true },
|
|
491
|
+
{ id: 'path-server-1', serverType: 'path', host: '127.0.0.1', port: 2235 }
|
|
492
|
+
];
|
|
493
|
+
let delIds = ['area-server-1'];
|
|
494
|
+
let addCount = 0;
|
|
495
|
+
let delCount = 0;
|
|
496
|
+
|
|
497
|
+
app.init({ base: mockBase });
|
|
498
|
+
app.event.on(events.ADD_SERVERS, function (servers: Array<{ [key: string]: any }>) {
|
|
499
|
+
// check event args
|
|
500
|
+
newServers.should.eql(servers);
|
|
501
|
+
addCount++;
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
app.event.on(events.REMOVE_SERVERS, function (ids: Array<string>) {
|
|
505
|
+
delIds.should.eql(ids);
|
|
506
|
+
|
|
507
|
+
// check servers
|
|
508
|
+
let curServers = app.getServers();
|
|
509
|
+
should.exist(curServers);
|
|
510
|
+
let item, i, l;
|
|
511
|
+
for (i = 0, l = destServers.length; i < l; i++) {
|
|
512
|
+
item = destServers[i];
|
|
513
|
+
item.should.eql(curServers[item.id]);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// check get server by id
|
|
517
|
+
for (i = 0, l = destServers.length; i < l; i++) {
|
|
518
|
+
item = destServers[i];
|
|
519
|
+
item.should.eql(app.getServerById(item.id));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// check server types
|
|
523
|
+
// NOTICE: server types would not clear when remove server from app
|
|
524
|
+
let types = [];
|
|
525
|
+
for (i = 0, l = newServers.length; i < l; i++) {
|
|
526
|
+
item = newServers[i];
|
|
527
|
+
if (types.indexOf(item.serverType) < 0) {
|
|
528
|
+
types.push(item.serverType);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
let types2 = app.getServerTypes();
|
|
532
|
+
types.length.should.equal(types2.length);
|
|
533
|
+
for (i = 0, l = types.length; i < l; i++) {
|
|
534
|
+
types2.should.containEql(types[i]);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// check server type list
|
|
538
|
+
let slist;
|
|
539
|
+
for (i = 0, l = destServers.length; i < l; i++) {
|
|
540
|
+
item = destServers[i];
|
|
541
|
+
slist = app.getServersByType(item.serverType);
|
|
542
|
+
should.exist(slist);
|
|
543
|
+
contains(slist, item).should.be.true;
|
|
544
|
+
}
|
|
545
|
+
app.event.removeAllListeners()
|
|
546
|
+
done();
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
app.addServers(newServers);
|
|
550
|
+
app.removeServers(delIds);
|
|
551
|
+
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
describe('#beforeStopHook', function () {
|
|
556
|
+
it('should be called before application stopped.', function (done: Mocha.Done) {
|
|
557
|
+
if(require('os').platform() === 'linux') {
|
|
558
|
+
done();
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
let count = 0;
|
|
562
|
+
this.timeout(8888)
|
|
563
|
+
app.init({ base: mockBase });
|
|
564
|
+
app.components.__monitor__ = { monitor: null, name: 'mockMonitor', start: () => {}, stop: () => {}, reconnect: () => {} };
|
|
565
|
+
app.beforeStopHook(function () {
|
|
566
|
+
count++;
|
|
567
|
+
});
|
|
568
|
+
app.start(function (err: Error) {
|
|
569
|
+
should.not.exist(err);
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
setTimeout(function () {
|
|
573
|
+
// wait for after start
|
|
574
|
+
app.stop(false);
|
|
575
|
+
|
|
576
|
+
setTimeout(function () {
|
|
577
|
+
// wait for stop
|
|
578
|
+
count.should.equal(1);
|
|
579
|
+
done();
|
|
580
|
+
}, WAIT_TIME);
|
|
581
|
+
}, WAIT_TIME);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
describe('#use', function () {
|
|
585
|
+
it('should exist plugin component and event', function (done: Mocha.Done) {
|
|
586
|
+
let plugin = {
|
|
587
|
+
name: 'mock-plugin',
|
|
588
|
+
components: [MockPlugin],
|
|
589
|
+
events: [MockEvent]
|
|
590
|
+
};
|
|
591
|
+
let opts = {};
|
|
592
|
+
app.use(plugin, opts);
|
|
593
|
+
should.exist(app.event.listeners('bind_session'));
|
|
594
|
+
should.exist(app.components.mockPlugin);
|
|
595
|
+
done();
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
let contains = function (slist: Array<{ [key: string]: any }>, sinfo: { [key: string]: any }) {
|
|
601
|
+
for (let i = 0, l = slist.length; i < l; i++) {
|
|
602
|
+
if (slist[i].id === sinfo.id) {
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return false;
|
|
607
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as should from 'should';
|
|
2
|
+
// import { describe, it } from "mocha-typescript"
|
|
3
|
+
let serialFilter = require('../../../lib/filters/handler/serial').SerialFilter;
|
|
4
|
+
let FilterService = require('../../../lib/common/service/filterService').FilterService;
|
|
5
|
+
let util = require('util');
|
|
6
|
+
|
|
7
|
+
let mockSession: { key: string, __serialTask__?: any } = {
|
|
8
|
+
key: '123'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
let WAIT_TIME = 100;
|
|
12
|
+
describe('#serialFilter', function () {
|
|
13
|
+
it('should do before filter ok', function (done: Mocha.Done) {
|
|
14
|
+
let service = new FilterService();
|
|
15
|
+
let filter = new serialFilter();
|
|
16
|
+
service.before(filter);
|
|
17
|
+
|
|
18
|
+
service.beforeFilter(null, {}, mockSession, function () {
|
|
19
|
+
should.exist(mockSession);
|
|
20
|
+
|
|
21
|
+
should.exist(mockSession.__serialTask__);
|
|
22
|
+
done();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should do after filter by doing before filter ok', function (done: Mocha.Done) {
|
|
27
|
+
let service = new FilterService();
|
|
28
|
+
let filter = new serialFilter();
|
|
29
|
+
let _session: { key: string, __serialTask__?: any };
|
|
30
|
+
service.before(filter);
|
|
31
|
+
|
|
32
|
+
service.afterFilter(null, null, {}, mockSession, {}, function () {
|
|
33
|
+
should.exist(mockSession);
|
|
34
|
+
should.exist(mockSession.__serialTask__);
|
|
35
|
+
_session = mockSession;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
service.after(filter);
|
|
39
|
+
|
|
40
|
+
service.afterFilter(null, null, {}, mockSession, {}, function () {
|
|
41
|
+
should.exist(mockSession);
|
|
42
|
+
should.strictEqual(mockSession, _session);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
setTimeout(done, WAIT_TIME);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as should from 'should';
|
|
2
|
+
// import { describe, it } from "mocha-typescript"
|
|
3
|
+
let serialFilter = require('../../../lib/filters/handler/time').TimeFilter;
|
|
4
|
+
let FilterService = require('../../../lib/common/service/filterService').FilterService;
|
|
5
|
+
let util = require('util');
|
|
6
|
+
let mockSession: { key: string, __startTime__?: any } = {
|
|
7
|
+
key: '123'
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
let WAIT_TIME = 100;
|
|
11
|
+
describe('#timeFilter', function () {
|
|
12
|
+
it('should do before filter ok', function (done: Mocha.Done) {
|
|
13
|
+
let service = new FilterService();
|
|
14
|
+
let filter = new serialFilter();
|
|
15
|
+
service.before(filter);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
service.beforeFilter(null, mockSession, mockSession, function () {
|
|
19
|
+
should.exist(mockSession);
|
|
20
|
+
|
|
21
|
+
should.exist(mockSession.__startTime__);
|
|
22
|
+
done();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should do after filter by doing before filter ok', function (done: Mocha.Done) {
|
|
27
|
+
let service = new FilterService();
|
|
28
|
+
let filter = new serialFilter();
|
|
29
|
+
let _session: { key: string, __startTime__?: any };
|
|
30
|
+
service.before(filter);
|
|
31
|
+
|
|
32
|
+
service.afterFilter(null, {}, {}, mockSession, {}, function () {
|
|
33
|
+
should.exist(mockSession);
|
|
34
|
+
should.exist(mockSession.__startTime__);
|
|
35
|
+
_session = mockSession;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
service.after(filter);
|
|
39
|
+
|
|
40
|
+
service.afterFilter(null, { route: 'hello' }, {}, mockSession, {}, function () {
|
|
41
|
+
should.exist(mockSession);
|
|
42
|
+
should.strictEqual(mockSession, _session);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
setTimeout(done, WAIT_TIME);
|
|
46
|
+
});
|
|
47
|
+
});
|