Repository navigation
Expand file tree
/
Copy pathnode.js
More file actions
53 lines (46 loc) · 1.49 KB
/
Copy pathnode.js
File metadata and controls
53 lines (46 loc) · 1.49 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
const path = require("path");
const { exec } = require("child_process");
const { Socket } = require("../");
const { repeat } = require("./util");
describe("node.js", () => {
describe("autoRef option", () => {
const fixture = filename =>
process.execPath + " " + path.join(__dirname, "fixtures", filename);
it("should stop once the timer is triggered", done => {
exec(fixture("unref.js"), done);
});
it("should stop once the timer is triggered (polling)", done => {
exec(fixture("unref-polling-only.js"), done);
});
it("should stop once the timer is triggered (websocket)", done => {
exec(fixture("unref-websocket-only.js"), done);
});
it("should not stop with autoUnref set to false", done => {
const process = exec(fixture("no-unref.js"), () => {
done(new Error("should not happen"));
});
setTimeout(() => {
process.kill();
done();
}, 1000);
});
});
it("should merge binary packets according to maxPayload value", done => {
const socket = new Socket({ transports: ["polling"] });
socket.on("open", () => {
socket.send(Buffer.allocUnsafe(72));
socket.send(Buffer.allocUnsafe(20));
socket.send(repeat("a", 20));
socket.send(Buffer.allocUnsafe(20));
socket.send(Buffer.allocUnsafe(72));
let count = 0;
socket.on("message", () => {
count++;
if (count === 5) {
socket.close();
done();
}
});
});
});
});