-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsome.test.js
More file actions
83 lines (71 loc) · 1.83 KB
/
some.test.js
File metadata and controls
83 lines (71 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const aconnector = require("./index.js");
const ConnectorServer = aconnector.ConnectorServer;
const ConnectorClient = aconnector.ConnectorClient;
let Serv, Cl, key = "key";
it("Create Server", () => {
Serv = new ConnectorServer(key, {
mul([a, b]) {
return a * b;
},
add([a, b]) {
return a + b;
},
err() {
throw "__SOME_ERROR__";
},
nativeErr() {
throw new TypeError("Div by zero");
}
});
});
it("Create Client", () => {
Cl = new ConnectorClient(key);
});
let port = 1234;
it("Launch Server", async () => {
Serv.launch(port);
});
it("Connect Client", async () => {
await Cl.connect(port, "localhost");
});
it("Add 5 + 10", async () => {
let res = await Cl.add([5, 10]);
if (res != 15)
throw new Error(`Expect 15 got ${res}`);
});
it("Mul 5 * 10", async () => {
let res = await Cl.mul([5, 10]);
if (res != 5 * 10)
throw new Error(`Expect ${5 * 10} got ${res}`);
});
it("Catch error", async () => {
let gotErr = false;
try {
let res = await Cl.err();
} catch (err) {
gotErr = true;
}
if (!gotErr)
throw new Error("Didnt catch an error");
});
it("Catch native error", async () => {
let gotErr = false;
try {
let res = await Cl.nativeErr();
} catch (err) {
if (err.code == "__INTERNAL_SERVER_ERROR__")
gotErr = true;
}
if (!gotErr)
throw new Error("Didnt catch an error");
});
it("Create wrong pass client", () => {
Cl = new ConnectorClient("wrong");
});
it("Connect wrong pass client", async () => {
Cl.on("error", (code) => {
if(code != "__WRONG_PASSCODE__")
throw new Error("Not right error, catched", code);
});
let result = await Cl.connect(port, "localhost");
});