diff --git a/deno/server.test.ts b/deno/server.test.ts index bbffeb9..efdfe84 100644 --- a/deno/server.test.ts +++ b/deno/server.test.ts @@ -2,7 +2,6 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { TcpServer } from "./server.ts"; - test("testServer", () => { const server = new TcpServer({ port: 0 }, {}); server.start(); diff --git a/mqttPacket/connect.test.ts b/mqttPacket/connect.test.ts index 7087141..dbb3ed9 100644 --- a/mqttPacket/connect.test.ts +++ b/mqttPacket/connect.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { type ConnectPacket, decode, encode } from "./mod.ts"; test("encode Connect with ClientId", () => { @@ -171,7 +171,10 @@ test("encode Connect with username and password", () => { }); test("decode Connect with username and password", () => { - assert.deepStrictEqual(decode(Uint8Array.from(encodedConnect)), decodedConnect); + assert.deepStrictEqual( + decode(Uint8Array.from(encodedConnect)), + decodedConnect, + ); }); const decodedConnectWithWill = Object.assign({}, decodedConnect); diff --git a/mqttPacket/decoder.test.ts b/mqttPacket/decoder.test.ts index 6066271..84192db 100644 --- a/mqttPacket/decoder.test.ts +++ b/mqttPacket/decoder.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { Decoder } from "./decoder.ts"; const utf8encoder = new TextEncoder(); diff --git a/mqttPacket/disconnect.test.ts b/mqttPacket/disconnect.test.ts index 82abaaa..fd06b95 100644 --- a/mqttPacket/disconnect.test.ts +++ b/mqttPacket/disconnect.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Disconnect", () => { diff --git a/mqttPacket/length.test.ts b/mqttPacket/length.test.ts index a92dbba..14f20e1 100644 --- a/mqttPacket/length.test.ts +++ b/mqttPacket/length.test.ts @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decodeLength as decode, encodeLength as encode } from "./length.ts"; test("encodeLength", function encodeLength() { diff --git a/mqttPacket/pingreq.test.ts b/mqttPacket/pingreq.test.ts index 4f59260..9f57528 100644 --- a/mqttPacket/pingreq.test.ts +++ b/mqttPacket/pingreq.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Pingreq", () => { diff --git a/mqttPacket/pingres.test.ts b/mqttPacket/pingres.test.ts index b6d12df..37970e4 100644 --- a/mqttPacket/pingres.test.ts +++ b/mqttPacket/pingres.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Pingres", () => { diff --git a/mqttPacket/puback.test.ts b/mqttPacket/puback.test.ts index 73fd493..330fa15 100644 --- a/mqttPacket/puback.test.ts +++ b/mqttPacket/puback.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Puback", () => { @@ -41,7 +41,11 @@ test("decode Puback ", () => { }); test("decodeShortPubackPackets", () => { - assert.throws(() => decode(Uint8Array.from([0x40])), Error, "decoding failed"); + assert.throws( + () => decode(Uint8Array.from([0x40])), + Error, + "decoding failed", + ); assert.throws(() => decode(Uint8Array.from([0x40, 2])), Error, "too short"); assert.throws( () => decode(Uint8Array.from([0x40, 3, 0, 0, 0])), diff --git a/mqttPacket/pubcomp.test.ts b/mqttPacket/pubcomp.test.ts index 7692ff4..09bd17d 100644 --- a/mqttPacket/pubcomp.test.ts +++ b/mqttPacket/pubcomp.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Pubcomp", () => { @@ -41,7 +41,11 @@ test("decode Pubcomp ", () => { }); test("decodeShortPubcompPackets", () => { - assert.throws(() => decode(Uint8Array.from([0x70])), Error, "decoding failed"); + assert.throws( + () => decode(Uint8Array.from([0x70])), + Error, + "decoding failed", + ); assert.throws(() => decode(Uint8Array.from([0x70, 2])), Error, "too short"); assert.throws( () => decode(Uint8Array.from([0x70, 3, 0, 0, 0])), diff --git a/mqttPacket/publish.test.ts b/mqttPacket/publish.test.ts index d0c4317..7e80122 100644 --- a/mqttPacket/publish.test.ts +++ b/mqttPacket/publish.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; // const utf8Decoder = new TextDecoder(); diff --git a/mqttPacket/pubrec.test.ts b/mqttPacket/pubrec.test.ts index f3f4a9f..cd47970 100644 --- a/mqttPacket/pubrec.test.ts +++ b/mqttPacket/pubrec.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Pubrec", () => { @@ -41,7 +41,11 @@ test("decode Pubrec ", () => { }); test("decodeShortPubrecPackets", () => { - assert.throws(() => decode(Uint8Array.from([0x50])), Error, "decoding failed"); + assert.throws( + () => decode(Uint8Array.from([0x50])), + Error, + "decoding failed", + ); assert.throws(() => decode(Uint8Array.from([0x50, 2])), Error, "too short"); assert.throws( () => decode(Uint8Array.from([0x50, 3, 0, 0, 0])), diff --git a/mqttPacket/pubrel.test.ts b/mqttPacket/pubrel.test.ts index b910d28..150f5fe 100644 --- a/mqttPacket/pubrel.test.ts +++ b/mqttPacket/pubrel.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Pubrel", () => { @@ -41,7 +41,11 @@ test("decode Pubrel ", () => { }); test("decodeShortPubrelPackets", () => { - assert.throws(() => decode(Uint8Array.from([0x60])), Error, "decoding failed"); + assert.throws( + () => decode(Uint8Array.from([0x60])), + Error, + "decoding failed", + ); assert.throws(() => decode(Uint8Array.from([0x60, 2])), Error, "too short"); assert.throws( () => decode(Uint8Array.from([0x60, 3, 0, 0, 0])), diff --git a/mqttPacket/subscribe.test.ts b/mqttPacket/subscribe.test.ts index 436606f..bcb8304 100644 --- a/mqttPacket/subscribe.test.ts +++ b/mqttPacket/subscribe.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Subscribe", () => { diff --git a/mqttPacket/unsuback.test.ts b/mqttPacket/unsuback.test.ts index b108ab7..1010b09 100644 --- a/mqttPacket/unsuback.test.ts +++ b/mqttPacket/unsuback.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Puback", () => { @@ -41,7 +41,11 @@ test("decode Puback ", () => { }); test("decodeShortPubackPackets", () => { - assert.throws(() => decode(Uint8Array.from([0xb0])), Error, "decoding failed"); + assert.throws( + () => decode(Uint8Array.from([0xb0])), + Error, + "decoding failed", + ); assert.throws(() => decode(Uint8Array.from([0xb0, 2])), Error, "too short"); assert.throws( () => decode(Uint8Array.from([0xb0, 3, 0, 0, 0])), diff --git a/mqttPacket/unsubscribe.test.ts b/mqttPacket/unsubscribe.test.ts index 633f13e..2de8912 100644 --- a/mqttPacket/unsubscribe.test.ts +++ b/mqttPacket/unsubscribe.test.ts @@ -1,7 +1,7 @@ import { PacketType } from "./PacketType.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; -; + import { decode, encode } from "./mod.ts"; test("encode Unsubscribe", () => { diff --git a/persistence/memory/memoryPersistence.test.ts b/persistence/memory/memoryPersistence.test.ts index 0d5a708..cdebd24 100644 --- a/persistence/memory/memoryPersistence.test.ts +++ b/persistence/memory/memoryPersistence.test.ts @@ -89,7 +89,11 @@ test("many packets should work", async () => { const seen = new Set(); function handler(packet: PublishPacket): void { - assert.deepStrictEqual(seen.has(packet.id), false, `Not seen ${packet.id} before`); + assert.deepStrictEqual( + seen.has(packet.id), + false, + `Not seen ${packet.id} before`, + ); seen.add(packet.id); } @@ -105,7 +109,11 @@ test("many packets should work", async () => { persistence.publish(topic, makePacket(i)); } await delay(10); - assert.deepStrictEqual(seen.size, numMessages, `received all ${numMessages} messages`); + assert.deepStrictEqual( + seen.size, + numMessages, + `received all ${numMessages} messages`, + ); }); test("unsubscribe should work", () => { @@ -121,7 +129,11 @@ test("unsubscribe should work", () => { const seen = new Set(); function handler(packet: PublishPacket): void { - assert.deepStrictEqual(seen.has(packet.id), false, `Not seen ${packet.id} before`); + assert.deepStrictEqual( + seen.has(packet.id), + false, + `Not seen ${packet.id} before`, + ); seen.add(packet.id); } diff --git a/server/test/handleConnect.test.ts b/server/test/handleConnect.test.ts index 97c2f1b..942f575 100644 --- a/server/test/handleConnect.test.ts +++ b/server/test/handleConnect.test.ts @@ -52,13 +52,25 @@ test("Authentication with valid username and password works", async () => { const { reader, mqttConn } = startServer(); mqttConn.send(connectPacket); const { value: connack } = await reader.next(); - assert.deepStrictEqual(connack.type, PacketType.connack, "Expect Connack packet"); + assert.deepStrictEqual( + connack.type, + PacketType.connack, + "Expect Connack packet", + ); if (connack.type === PacketType.connack) { - assert.deepStrictEqual(connack.returnCode, AuthenticationResult.ok, "Expected OK"); + assert.deepStrictEqual( + connack.returnCode, + AuthenticationResult.ok, + "Expected OK", + ); } mqttConn.send(disconnectPacket); await nextTick(); - assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed"); + assert.deepStrictEqual( + mqttConn.isClosed, + true, + "Expected connection to be closed", + ); }); test("Authentication with invalid username fails", async () => { @@ -67,7 +79,11 @@ test("Authentication with invalid username fails", async () => { const { reader, mqttConn } = startServer(); mqttConn.send(newPacket); const { value: connack } = await reader.next(); - assert.deepStrictEqual(connack.type, PacketType.connack, "Expected Connack packet"); + assert.deepStrictEqual( + connack.type, + PacketType.connack, + "Expected Connack packet", + ); if (connack.type === PacketType.connack) { assert.deepStrictEqual( connack.returnCode, @@ -76,7 +92,11 @@ test("Authentication with invalid username fails", async () => { ); } await nextTick(); - assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed"); + assert.deepStrictEqual( + mqttConn.isClosed, + true, + "Expected connection to be closed", + ); }); test("Authentication with invalid password fails", async () => { @@ -85,7 +105,11 @@ test("Authentication with invalid password fails", async () => { const { reader, mqttConn } = startServer(); mqttConn.send(newPacket); const { value: connack } = await reader.next(); - assert.deepStrictEqual(connack.type, PacketType.connack, "Expected Connack packet"); + assert.deepStrictEqual( + connack.type, + PacketType.connack, + "Expected Connack packet", + ); if (connack.type === PacketType.connack) { assert.deepStrictEqual( connack.returnCode, @@ -94,5 +118,9 @@ test("Authentication with invalid password fails", async () => { ); } await nextTick(); - assert.deepStrictEqual(mqttConn.isClosed, true, "Expected connection to be closed"); + assert.deepStrictEqual( + mqttConn.isClosed, + true, + "Expected connection to be closed", + ); }); diff --git a/timer/timer.test.ts b/timer/timer.test.ts index 0a4de21..397aa35 100644 --- a/timer/timer.test.ts +++ b/timer/timer.test.ts @@ -2,7 +2,6 @@ import { Timer } from "./timer.ts"; import assert from "node:assert/strict"; import { test } from "node:test"; - function delay(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/trie/trie.test.ts b/trie/trie.test.ts index 5a23f07..3349788 100644 --- a/trie/trie.test.ts +++ b/trie/trie.test.ts @@ -4,10 +4,10 @@ import { Trie } from "./trie.ts"; type Data = Array<[string, number]>; type Matches = Array<[string, number[]]>; -type MatchResult = Array; - -const includesAll = (arr:MatchResult, values:MatchResult) => values.every(v => arr.includes(v)); +type MatchResult = Array; +const includesAll = (arr: MatchResult, values: MatchResult) => + values.every((v) => arr.includes(v)); function doTest(data: Data, matches: Matches) { const root = new Trie(); @@ -16,7 +16,7 @@ function doTest(data: Data, matches: Matches) { } for (const [match, result] of matches) { - assert.ok(includesAll(root.match(match),result), `${match} found`) + assert.ok(includesAll(root.match(match), result), `${match} found`); } } @@ -123,9 +123,9 @@ test("Removal works", () => { const root = new Trie(); root.add("foo/bar", 1); root.add("foo/bar", 2); - assert.ok(includesAll(root.match("foo/bar"), [1, 2]), 'two items found'); + assert.ok(includesAll(root.match("foo/bar"), [1, 2]), "two items found"); root.remove("foo/bar", 2); - assert.ok(includesAll(root.match("foo/bar"), [1]), 'one item found'); + assert.ok(includesAll(root.match("foo/bar"), [1]), "one item found"); root.remove("foo/bar", 1); assert.deepStrictEqual(root.match("foo/bar").length, 0, "no items left"); }); @@ -138,10 +138,10 @@ test("Removal of object values works", () => { const c2: ComplexValue = { a: 2, b: 4, c: 6 }; root.add("foo/bar", c1); root.add("foo/bar", c2); - assert.ok(includesAll(root.match("foo/bar"), [c1, c2]), 'two items found'); + assert.ok(includesAll(root.match("foo/bar"), [c1, c2]), "two items found"); root.remove("foo/bar", c2); - assert.ok(includesAll(root.match("foo/bar"), [c1]), 'one item found'); + assert.ok(includesAll(root.match("foo/bar"), [c1]), "one item found"); root.remove("foo/bar", { a: 1, b: 2, c: 3 }); - assert.ok(includesAll(root.match("foo/bar"), []), 'empty array'); + assert.ok(includesAll(root.match("foo/bar"), []), "empty array"); assert.deepStrictEqual(root.match("foo/bar").length, 0, "matches left"); });