Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(test/server): supertest-based tests no longer working
Elian Doran59663ed6960d
diff --git a/apps/server/src/routes/login.spec.ts b/apps/server/src/routes/login.spec.tsindex 1c3f2bc466..31abf725d4 100644--- a/apps/server/src/routes/login.spec.ts+++ b/apps/server/src/routes/login.spec.ts@@ -1,8 +1,9 @@import { beforeAll, describe, expect, it } from "vitest";import supertest from "supertest";import { initializeTranslations } from "../services/i18n.js";-import type { Application, Request, Response, NextFunction } from "express";+import type { Application } from "express";import dayjs from "dayjs";+import buildApp from "../app.js";let app: Application;@@ -10,7 +11,7 @@ describe("Login Route test", () => {beforeAll(async () => {initializeTranslations();- app = (await import("../app.js")).default;+ app = await buildApp();});it("should return the login page, when using a GET request", async () => {@@ -60,7 +61,7 @@ describe("Login Route test", () => {expect(actualExpiresDate).to.not.eql("Invalid Date");- // ignore the seconds in the comparison, just to avoid flakiness in tests,+ // ignore the seconds in the comparison, just to avoid flakiness in tests,// if for some reason execution is slow between calculation of expected and actualexpect(actualExpiresDate.slice(0,23)).toBe(expectedExpiresDate.slice(0,23))@@ -90,4 +91,4 @@ describe("Login Route test", () => {// TODO: actually identify what is causing this and fix the flakiness-});\ No newline at end of file+});diff --git a/apps/server/src/share/routes.spec.ts b/apps/server/src/share/routes.spec.tsindex ba2af2b816..de2f50fcc5 100644--- a/apps/server/src/share/routes.spec.ts+++ b/apps/server/src/share/routes.spec.ts@@ -3,6 +3,7 @@ import supertest from "supertest";import { initializeTranslations } from "../services/i18n.js";import type { Application, Request, Response, NextFunction } from "express";import { safeExtractMessageAndStackFromError } from "../services/utils.js";+import buildApp from "../app.js";let app: Application;@@ -11,7 +12,7 @@ describe("Share API test", () => {beforeAll(async () => {initializeTranslations();- app = (await import("../app.js")).default;+ app = await buildApp();app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {const [ errMessage ] = safeExtractMessageAndStackFromError(err);if (errMessage.includes("Cannot set headers after they are sent to the client")) {