(
run: (context: {
readonly handler: (request: Request) => Promise<Response>
readonly root: string
readonly outsideFile: string
}) => Promise<void>,
options: Omit<Parameters<typeof HttpStaticServer.make>[0], "root"> = {}
)
| 31 | ) |
| 32 | |
| 33 | const withStaticFiles = async ( |
| 34 | run: (context: { |
| 35 | readonly handler: (request: Request) => Promise<Response> |
| 36 | readonly root: string |
| 37 | readonly outsideFile: string |
| 38 | }) => Promise<void>, |
| 39 | options: Omit<Parameters<typeof HttpStaticServer.make>[0], "root"> = {} |
| 40 | ) => { |
| 41 | const temporaryRoot = await mkdtemp(NodePath.join(tmpdir(), "effect-http-static-server-")) |
| 42 | const root = NodePath.join(temporaryRoot, "root") |
| 43 | const outsideFile = NodePath.join(temporaryRoot, NodePath.basename(fixturesOutsideFile)) |
| 44 | |
| 45 | await Promise.all([ |
| 46 | cp(fixturesRoot, root, { recursive: true }), |
| 47 | copyFile(fixturesOutsideFile, outsideFile) |
| 48 | ]) |
| 49 | |
| 50 | const { handler, dispose } = makeHandler(root, options) |
| 51 | try { |
| 52 | await run({ handler, root, outsideFile }) |
| 53 | } finally { |
| 54 | await dispose() |
| 55 | await rm(temporaryRoot, { recursive: true, force: true }) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | describe("HttpStaticServer", () => { |
| 60 | it("serves files with expected content type and body", async () => { |
no test coverage detected