Files
socket.io/test/node.ts
KC Erb 6abfa1fa4c feat: add autoUnref option
With autoUnref set to true (default: false), the Socket.IO client will
allow the program to exit if there is no other active timer/socket in
the event system.

```js
const socket = io({
  autoUnref: true
});
```

Note: this option only applies to Node.js clients.

Related: https://github.com/socketio/socket.io-client/issues/1446
2021-03-10 12:16:12 +01:00

34 lines
989 B
TypeScript

const path = require("path");
const { exec } = require("child_process");
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.ts"), done);
});
it("should stop once the timer is triggered (even when trying to reconnect)", (done) => {
exec(fixture("unref-during-reconnection.ts"), done);
});
it("should stop once the timer is triggered (polling)", (done) => {
exec(fixture("unref-polling-only.ts"), done);
});
it("should stop once the timer is triggered (websocket)", (done) => {
exec(fixture("unref-websocket-only.ts"), done);
});
it("should not stop with autoUnref set to false", (done) => {
const process = exec(fixture("no-unref.ts"), () => {
done(new Error("should not happen"));
});
setTimeout(() => {
process.kill();
done();
}, 1000);
});
});