41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
/**
|
|
* Guard test: verifies the package surface does not rely on
|
|
* `Math.random()` or `Date.now()` directly in its runtime code.
|
|
*
|
|
* MIME detection is a pure function of its inputs — no time-based or
|
|
* random-based side effects should be needed.
|
|
*/
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import {
|
|
detectFromMagicBytes,
|
|
formatContentType,
|
|
getMimeEntry,
|
|
parseContentType,
|
|
} from "../src/index.js";
|
|
|
|
describe("no disallowed side-effects", () => {
|
|
it("parseContentType is deterministic", { timeout: 5000 }, () => {
|
|
const a = parseContentType("text/html; charset=utf-8");
|
|
const b = parseContentType("text/html; charset=utf-8");
|
|
expect(a).toEqual(b);
|
|
});
|
|
|
|
it("formatContentType is deterministic", { timeout: 5000 }, () => {
|
|
const parsed = parseContentType("text/plain; charset=utf-8");
|
|
expect(formatContentType(parsed)).toBe(formatContentType(parsed));
|
|
});
|
|
|
|
it("detectFromMagicBytes is deterministic", { timeout: 5000 }, () => {
|
|
const png = new Uint8Array([
|
|
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
|
|
]);
|
|
const r1 = detectFromMagicBytes(png);
|
|
const r2 = detectFromMagicBytes(png);
|
|
expect(r1).toEqual(r2);
|
|
});
|
|
|
|
it("getMimeEntry is deterministic", { timeout: 5000 }, () => {
|
|
expect(getMimeEntry("image/png")).toEqual(getMimeEntry("image/png"));
|
|
});
|
|
});
|