From 7b1295bb02853c20806c101c05d6ef099aae4b76 Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Mon, 31 Mar 2025 15:15:22 +0200 Subject: [PATCH] unit tests part 5 --- broker.test.ts | 8 +++++--- broker.ts | 20 +++++--------------- package.json | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/broker.test.ts b/broker.test.ts index 084d2c7..a7e5c27 100644 --- a/broker.test.ts +++ b/broker.test.ts @@ -1,9 +1,11 @@ import { html } from "./broker"; import { test, beforeAll, afterAll } from "@jest/globals"; +/*jest.useFakeTimers(); + beforeAll(() => { jest.spyOn(console, "log").mockImplementation(() => {}); -}); +});*/ test("Generate HTML for hexagram", () => { expect(html("Hexagram No. 45 ䷬\nGathering Together [Massing]\n萃 (cuì)")) @@ -20,6 +22,6 @@ test("Generate HTML for images", () => { .toBe("

Images:

Over the earth, the lake:
The image of Gathering Together.
Thus the superior man renews his weapons
In order to meet the unforseen.

"); }); -afterAll(() => { +/*afterAll(() => { (console.log as jest.Mock).mockRestore(); -}); +});*/ diff --git a/broker.ts b/broker.ts index 0c63e4f..57aa4fa 100644 --- a/broker.ts +++ b/broker.ts @@ -94,7 +94,7 @@ async function sendEmail(content: string) { //Calculate the time for the next execution of the main process, depending on configuration. //Returns the time of the next process loop. function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date { - /*const currentDate = new Date(); + const currentDate = new Date(); // Splitte die Uhrzeit in Stunden und Minuten const [hours, minutes] = timeOfDay.split(':').map(Number); @@ -110,11 +110,6 @@ function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date { // Berechne das Datum für den nächsten Ausführungszeitpunkt unter Berücksichtigung von X Tagen currentDate.setDate(currentDate.getDate() + daysInterval); - return currentDate;*/ - - //TODO: JUST FOR DEBUGGING!!! - const currentDate = new Date(); - currentDate.setMinutes(currentDate.getMinutes() + 2); return currentDate; } @@ -125,7 +120,7 @@ function scheduleNextRun(nextRunDate: Date) { if (timeUntilNextRun > 0) { setTimeout(() => { - console.log('Prozess wird ausgeführt!'); + console.log('Next iteration of Process was scheduled!'); //run the main process executeCommand(); @@ -185,7 +180,7 @@ function parse(input: string): Node { function render(node: Node): string { if (node == undefined) { - console.log("...finished...") + console.log("Rendering of nodes finished!") return ""; } @@ -197,19 +192,18 @@ function render(node: Node): string { switch (node.type) { case "Root": return render(node.child!); + case "Hexagram": node.value = node.value?.replace("

", "

"); node.value = node.value?.replace("

", "

"); node.value = node.value?.replace("
", " - "); outputHTML = "

" + node.value + "

"; outputHTML = outputHTML + render(node.child!); - return outputHTML; case "Images": - outputHTML = "

" + node.value + "

"; //EXTRA closing div + outputHTML = "

" + node.value + "

"; //EXTRA closing div (was opened at beginning of hexagram) outputHTML = outputHTML + render(node.child!); - return outputHTML; case "ChangingLines" : @@ -218,16 +212,12 @@ function render(node: Node): string { //outputHTML = "

" + node.value + "


"; outputHTML = "

" + node.value + "


"; outputHTML = outputHTML + render(node.child!); - return outputHTML; default: outputHTML = "

" + node.value + "

"; outputHTML = outputHTML + render(node.child!); - return outputHTML; } - - } \ No newline at end of file diff --git a/package.json b/package.json index 6175a03..3bb34c3 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "broker.js", "scripts": { - "test": "jest" + "test": "jest --runInBand --detectOpenHandles --force-exit" }, "keywords": [], "author": "",