diff --git a/web-chat/package.json b/web-chat/package.json index 9dec918..b1649fe 100644 --- a/web-chat/package.json +++ b/web-chat/package.json @@ -31,7 +31,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "test:unit": "react-scripts test", + "test:unit": "exit 0", "fix": "run-s fix:*", "test": "run-s build test:*", "test:lint": "eslint src --ext .ts --ext .tsx", diff --git a/web-chat/src/WakuMock.test.ts b/web-chat/src/WakuMock.test.ts deleted file mode 100644 index 81d87d0..0000000 --- a/web-chat/src/WakuMock.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import WakuMock, { Message } from "./WakuMock"; - -test("Messages are emitted", async () => { - const wakuMock = await WakuMock.create(); - - let message: Message; - wakuMock.on("message", (msg) => { - message = msg; - }); - - await new Promise((resolve) => setTimeout(resolve, 2000)); - // @ts-ignore - expect(message.message).toBeDefined(); -}); - -test("Messages are sent", async () => { - const wakuMock = await WakuMock.create(); - - const text = "This is a message."; - - let message: Message; - wakuMock.on("message", (msg) => { - message = msg; - }); - - await wakuMock.send(text); - - // @ts-ignore - expect(message.message).toEqual(text); -}); diff --git a/web-chat/src/WakuMock.ts b/web-chat/src/WakuMock.ts deleted file mode 100644 index d887d88..0000000 --- a/web-chat/src/WakuMock.ts +++ /dev/null @@ -1,69 +0,0 @@ -class EventEmitter { - public callbacks: { [key: string]: Array<(data: T) => void> }; - - constructor() { - this.callbacks = {}; - } - - on(event: string, cb: (data: T) => void) { - if (!this.callbacks[event]) this.callbacks[event] = []; - this.callbacks[event].push(cb); - } - - emit(event: string, data: T) { - let cbs = this.callbacks[event]; - if (cbs) { - cbs.forEach((cb) => cb(data)); - } - } -} - -export interface Message { - timestamp: Date; - handle: string; - message: string; -} - -export default class WakuMock extends EventEmitter { - index: number; - intervalId?: number | NodeJS.Timeout; - - private constructor() { - super(); - this.index = 0; - } - - public static async create(): Promise { - await new Promise((resolve) => setTimeout(resolve, 500)); - - const wakuMock = new WakuMock(); - wakuMock.startInterval(); - return wakuMock; - } - - public async send(message: string): Promise { - const timestamp = new Date(); - const handle = "me"; - this.emit("message", { - timestamp, - handle, - message, - }); - } - - private startInterval() { - if (this.intervalId === undefined) { - this.intervalId = setInterval(this.emitMessage.bind(this), 1000); - } - } - - private emitMessage() { - const handle = "you"; - const timestamp = new Date(); - this.emit("message", { - timestamp, - handle, - message: `This is message #${this.index++}.`, - }); - } -}