| 1 | // # `mime.for` |
| 2 | // Retrieves the 'Content-Type' header to use given a file extension. |
| 3 | test("for", () => { |
| 4 | // accepts extension as string |
| 5 | assert.equal(mime.for("txt"), "text/plain"); |
| 6 | // accepts |
| 7 | assert.equal(mime.for(".xml"), "application/xml"); |
| 8 | // accepts file path |
| 9 | assert.equal(mime.for("filename.xml"), "application/xml"); |
| 10 | assert.equal(mime.for("a.directory/.xml"), "application/xml"); |
| 11 | // accepts absolute file path |
| 12 | assert.equal(mime.for("/path/to/filename.xml"), "application/xml"); |
| 13 | assert.equal(mime.for("C:\\path\\to\\filename.xml"), "application/xml"); |
| 14 | |
| 15 | // rss is special-cased |
| 16 | assert.equal(mime.for("rss.xml"), "application/rss+xml"); |
| 17 | |
| 18 | // supports modern innovations |
| 19 | assert.equal(mime.for(".avif"), "image/avif"); |
| 20 | assert.equal(mime.for(".jxl"), "image/jxl"); |
| 21 | |
| 22 | // fallback |
| 23 | assert.equal(mime.for(".unknown"), "application/octet-stream"); |
| 24 | }); |
| 25 | |
| 26 | import assert from "node:assert"; |
| 27 | import { test } from "vitest"; |
| 28 | import * as mime from "./mime.ts"; |