This commit is contained in:
Mateusz Gruszczyński
2026-09-17 13:11:37 +02:00
parent 86a6fa1f2f
commit eede4e88e6
10 changed files with 145 additions and 20 deletions
+32
View File
@@ -0,0 +1,32 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
const connectionStateSource = await readFile(new URL("../static/js/connection-state.js", import.meta.url), "utf8");
const connectionState = await import(`data:text/javascript;base64,${Buffer.from(connectionStateSource).toString("base64")}`);
const {
CONNECTION_ERROR_AFTER_RECONNECT_ATTEMPTS,
reconnectStatus,
} = connectionState;
test("temporary reconnects remain reconnecting", () => {
for (let attempt = 0; attempt < CONNECTION_ERROR_AFTER_RECONNECT_ATTEMPTS; attempt += 1) {
assert.equal(reconnectStatus(attempt, true), "reconnecting");
}
});
test("persistent reconnect failures become an error while online", () => {
assert.equal(reconnectStatus(CONNECTION_ERROR_AFTER_RECONNECT_ATTEMPTS, true), "error");
assert.equal(reconnectStatus(CONNECTION_ERROR_AFTER_RECONNECT_ATTEMPTS + 10, true), "error");
});
test("offline devices stay in reconnecting state instead of a hard error", () => {
assert.equal(reconnectStatus(CONNECTION_ERROR_AFTER_RECONNECT_ATTEMPTS + 10, false), "reconnecting");
});
test("frontend exceptions do not overwrite the connection indicator", async () => {
const editorSource = await readFile(new URL("../static/js/note-editor.js", import.meta.url), "utf8");
assert.doesNotMatch(editorSource, /setStatus\([^\n]*Application error/);
assert.match(editorSource, /window\.addEventListener\("error", \(\) => notifyFrontendError\(\)\)/);
assert.match(editorSource, /window\.addEventListener\("unhandledrejection", \(\) => notifyFrontendError\(\)\)/);
});