@schukai/monster 3.2.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,107 +0,0 @@
1
- import {expect} from "chai"
2
- import {WebSocketDatasource} from "../../../../../application/source/data/datasource/websocket.mjs";
3
- import {initWebSocket} from "../../../util/websocket.mjs";
4
-
5
- const testUrl = "wss://ws.postman-echo.com/raw"
6
-
7
- // const g = getGlobal();
8
- // g['WebSocket'] = WS;
9
-
10
-
11
- describe('Websocket', function () {
12
-
13
- let ds = undefined
14
-
15
- before(function (done) {
16
- initWebSocket().then(() => {
17
- done()
18
- }).catch((e) => {
19
- done(e)
20
- })
21
- });
22
-
23
- afterEach(function (done) {
24
- if (ds) {
25
- ds.close()
26
- }
27
-
28
- // without this, the node test will hang
29
- for (const sym of Object.getOwnPropertySymbols(ds)) {
30
- if (sym.toString() ==='Symbol(connection)') {
31
- if(ds[sym]?.socket?.['terminate']) {
32
- ds[sym]?.socket?.['terminate']()
33
- }
34
- }
35
- }
36
-
37
- done()
38
- });
39
-
40
- it('should get clone', function () {
41
-
42
- ds = new WebSocketDatasource(testUrl)
43
- const clone = ds.getClone()
44
-
45
- expect(clone).to.be.an.instanceof(WebSocketDatasource)
46
-
47
-
48
- })
49
-
50
- it('should connect', function (done) {
51
- ds = new WebSocketDatasource({
52
- url: testUrl,
53
- reconnect: {
54
- enabled: false
55
- }
56
- });
57
- ds.connect()
58
- setTimeout(() => {
59
- expect(ds.isConnected()).to.be.true;
60
- done();
61
- }, 500);
62
-
63
-
64
- })
65
-
66
- it('should send message', function (done) {
67
- ds = new WebSocketDatasource({
68
- url: testUrl,
69
- reconnect: {
70
- enabled: false
71
- }
72
- });
73
- ds.connect()
74
-
75
- ds.set({
76
- data: {
77
- message: "Hello World"
78
- }
79
- })
80
-
81
- setTimeout(() => {
82
-
83
- ds.write().then(() => {
84
-
85
- ds.set({})
86
- expect(ds.get()).to.be.deep.equal({});
87
-
88
-
89
- setTimeout(() => {
90
-
91
- expect(ds.get()).to.be.deep.equal({
92
- data: {
93
- message: "Hello World"
94
- }
95
- });
96
- done();
97
- }, 1000);
98
- }).catch((err) => {
99
- done(new Error(err));
100
- })
101
- },
102
- 500)
103
-
104
-
105
- }).timeout(10000);
106
-
107
- });