Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ overrides:
undici@>=7 <7.30.1: 7.30.1
fast-uri@>=3 <3.1.9: 3.1.9
fast-uri@>=4 <4.2.3: 4.2.3
glob@>=9 <14.0.2: 14.0.2
minimatch@<11.0.1: 11.0.1
35 changes: 35 additions & 0 deletions tests/static-dependency.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import Fastify from "fastify";
import staticFiles from "@fastify/static";
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, join, resolve, sep } from "node:path";

describe("static file dependency compatibility", () => {
let root: string;
const app = Fastify();

beforeAll(async () => {
root = await mkdtemp(join(tmpdir(), "cove-static-"));
await mkdir(join(root, "assets"));
await writeFile(join(root, "assets", "sample.txt"), "static fixture");
await app.register(staticFiles, { root, wildcard: true });
});

afterAll(async () => {
await app.close();
if (!root) return;
if (
!resolve(root).startsWith(resolve(tmpdir()) + sep) ||
!basename(root).startsWith("cove-static-")
)
throw new Error("Refusing to remove an unexpected fixture path");
await rm(root, { recursive: true, force: true });
});

it("serves a nested asset through Fastify", async () => {
const response = await app.inject({ method: "GET", url: "/assets/sample.txt" });
expect(response.statusCode).toBe(200);
expect(response.body).toBe("static fixture");
});
});
Loading