21 lines
1.0 KiB
TypeScript
21 lines
1.0 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { shouldInlineCss } from "../src/inline-css.ts";
|
|
|
|
test("production CSS inlining uses a configurable UTF-8 byte budget", () => {
|
|
expect(shouldInlineCss("x".repeat(4096), undefined)).toBe(true);
|
|
expect(shouldInlineCss("x".repeat(4097), undefined)).toBe(false);
|
|
expect(shouldInlineCss("x".repeat(5000), 6000)).toBe(true);
|
|
expect(shouldInlineCss("é".repeat(10), 10)).toBe(false);
|
|
expect(shouldInlineCss("", 0)).toBe(false);
|
|
for (const value of [-1, NaN, Infinity, 1.5]) expect(() => shouldInlineCss("", value)).toThrow();
|
|
});
|
|
|
|
test("relative asset URLs stay external so their base does not change", () => {
|
|
for (const url of ['./font.woff2', '../font.woff2', 'font.woff2', '#mask']) {
|
|
expect(shouldInlineCss(`a{background:url("${url}")}`, undefined)).toBe(false);
|
|
}
|
|
for (const url of ['/font.woff2', 'https://cdn.example/font.woff2', 'data:image/svg+xml;base64,AAAA']) {
|
|
expect(shouldInlineCss(`a{background:url('${url}')}`, undefined)).toBe(true);
|
|
}
|
|
});
|