import "@halsp/testing"; import "../src"; import { Request, Startup } from "@halsp/core"; import { HttpMethods } from "@halsp/http"; import path from "path"; describe("dir", () => { it("should list dir files when listDir = true", async () => { { const result = await new Startup() .useHttp() .setContext(new Request().setMethod(HttpMethods.get)) .useStatic({ dir: "test/static", listDir: true, }) .test(); expect(result.status).toBe(200); const html = result.body as string; expect( html.includes(`Files within ${path.sep}`), ).toBeTruthy(); } { const result = await new Startup() .useHttp() .setContext(new Request().setMethod(HttpMethods.get)) .useStatic({ dir: "test/static", }) .test(); expect(result.status).toBe(404); } }); it("should list children dir with folder ..", async () => { const result = await new Startup() .useHttp() .setContext(new Request().setMethod(HttpMethods.get).setPath("dir")) .useStatic({ dir: "test/static", listDir: true, }) .test(); expect(result.status).toBe(200); const html = result.body as string; console.log("html", html); expect( html.includes(`Files within dir${path.sep}`), ).toBeTruthy(); expect( html.includes( `📂${path.sep}dir${path.sep}`, ), ).toBeTruthy(); expect( html.includes(`..`), ).toBeTruthy(); expect( html.includes( `index.html`, ), ).toBeTruthy(); }); it("should list dir with prefix", async () => { const result = await new Startup() .useHttp() .setContext( new Request().setMethod(HttpMethods.get).setPath("static/dir"), ) .useStatic({ dir: "test/static", listDir: true, prefix: "static", }) .test(); expect(result.status).toBe(200); const html = result.body as string; expect( html.includes(`Files within dir${path.sep}`), ).toBeTruthy(); expect( html.includes( `📂${path.sep}dir${path.sep}`, ), ).toBeTruthy(); expect( html.includes(`..`), ).toBeTruthy(); expect( html.includes( `index.html`, ), ).toBeTruthy(); }); });