mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 06:19:21 +00:00
Port the MIME mappings reported by fix2015 in #1836 to both render file servers. Co-authored-by: vitalii.semianchuk <fix20152@gmail.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { createFileServer } from "./fileServer.js";
|
|
|
|
describe("file server media responses", () => {
|
|
it.each([
|
|
["avif", "image/avif"],
|
|
["flac", "audio/flac"],
|
|
["M4A", "audio/mp4"],
|
|
["mov", "video/quicktime"],
|
|
["ico", "image/vnd.microsoft.icon"],
|
|
])("serves .%s with its content type and unchanged bytes", async (ext, type) => {
|
|
const projectDir = mkdtempSync(join(tmpdir(), "hf-engine-media-type-"));
|
|
const bytes = new Uint8Array([0, 255, 128, 64, 32]);
|
|
try {
|
|
writeFileSync(join(projectDir, `asset.${ext}`), bytes);
|
|
const server = await createFileServer({ projectDir });
|
|
try {
|
|
const response = await fetch(`${server.url}/asset.${ext}`);
|
|
expect(response.status).toBe(200);
|
|
expect(response.headers.get("content-type")).toBe(type);
|
|
expect(new Uint8Array(await response.arrayBuffer())).toEqual(bytes);
|
|
} finally {
|
|
server.close();
|
|
}
|
|
} finally {
|
|
rmSync(projectDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|