Fix terminal freezing self and whole app when internet is disconnected (#5870)

- Remove uses to navigator.onLine as not needed and because that value
  cannot be trusted (see several bug reports on chromium)

- Fix infinite loop when socket is not connected in flush

- Add some simple tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-07-25 08:34:54 +03:00
1 parent 2a141767df
commit f7f41cab79
2 files changed
+46 -15

No files matched your search

@@ -0,0 +1,37 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { WebSocketEvents } from "../websocket-api";
import { WebSocketApi } from "../websocket-api";
class TestWebSocketApi extends WebSocketApi<WebSocketEvents> {
flush(): void {
super.flush();
}
}
describe("WebsocketApi tests", () => {
let api: TestWebSocketApi;
beforeEach(() => {
api = new TestWebSocketApi({});
});
describe("before connection", () => {
it("does not hang when flush is called", () => {
api.flush();
});
describe("when a message has been sent", () => {
beforeEach(() => {
api.send("a command");
});
it("does not hang when flush is called", () => {
api.flush();
});
});
});
});