diff --git a/test/networking/messageGenerators.spec.ts b/test/networking/messageGenerators.spec.ts index dd5dde6..43ad449 100644 --- a/test/networking/messageGenerators.spec.ts +++ b/test/networking/messageGenerators.spec.ts @@ -1,4 +1,5 @@ import { expect } from "chai"; +import { FileData } from "../../src/interfaces"; import { fileChangeEventToMsg, fileRemovalEventToMsg, @@ -30,4 +31,31 @@ describe("messageGenerators", () => { expect(requestFilenames).to.exist; }); }); + + describe("addLeadingSlash", () => { + it("should add a leading slash if a file in a folder is sent", () => { + const msg = fileRemovalEventToMsg({ path: "sub/test.js" }); + const result = (msg?.params as FileData).filename; + + if (result && result.hasOwnProperty("filename")) expect(result).to.eq("/sub/test.js"); + }); + }); + + describe("addLeadingSlash", () => { + it("should not add a leading slash if a file in the root folder is sent", () => { + const msg = fileRemovalEventToMsg({ path: "test.js" }); + const result = (msg?.params as FileData).filename; + + if (result && result.hasOwnProperty("filename")) expect(result).to.eq("test.js"); + }); + }); + + describe("addLeadingSlash", () => { + it("should return with one leading slash if a file in a folder is sent and file already is prefixed", () => { + const msg = fileRemovalEventToMsg({ path: "/sub/test.js" }); + const result = (msg?.params as FileData).filename; + + if (result && result.hasOwnProperty("filename")) expect(result).to.eq("/sub/test.js"); + }); + }); }); diff --git a/test/networking/messageTracker.spec.ts b/test/networking/messageTracker.spec.ts index 4074027..c1dcd57 100644 --- a/test/networking/messageTracker.spec.ts +++ b/test/networking/messageTracker.spec.ts @@ -1,8 +1,35 @@ import { expect } from "chai"; import { messageTracker } from "../../src/networking/messageTracker"; +function* range(start: number, end: number) { + for (let i = start; i <= end; i++) { + yield i; + } +} + describe("messageTracker", () => { it("should exist", () => { expect(messageTracker).to.exist; }); + + it("should return entered value at index", () => { + messageTracker.push({ jsonrpc: "2.0", id: 0, result: "testvalue0" }); + const msg = messageTracker.get(0); + + expect(msg?.result).to.eq("testvalue0"); + }); + + it("should throw away values after entering more than it's max amount", () => { + for (const i of range(0, 200)) { + messageTracker.push({ jsonrpc: "2.0", id: i, result: `testvalue${i}` }); + } + + const msg0 = messageTracker.get(0); + const msg1 = messageTracker.get(1); + const msg200 = messageTracker.get(200); + + expect(msg0).to.eq(undefined); + expect(msg1?.result).to.eq("testvalue1"); + expect(msg200?.result).to.eq("testvalue200"); + }); });