docs: document media caps and tidy web tests

This commit is contained in:
Peter Steinberger
2025-11-25 23:43:57 +01:00
parent e0425ad3e1
commit d924b7d283
6 changed files with 55 additions and 49 deletions

View File

@@ -423,7 +423,7 @@ describe("provider-web", () => {
sendMedia,
});
expect(sendMedia).toHaveBeenCalled();
expect(sendMedia).toHaveBeenCalledTimes(1);
expect(reply).toHaveBeenCalledWith("hi");
fetchMock.mockRestore();
});
@@ -501,42 +501,42 @@ describe("provider-web", () => {
fetchMock.mockRestore();
});
it(
"compresses common formats to jpeg under the cap",
{ timeout: 15_000 },
async () => {
const formats = [
{
name: "png",
mime: "image/png",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.png({ compressionLevel: 0 })
.toBuffer(),
},
{
name: "jpeg",
mime: "image/jpeg",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.jpeg({ quality: 100, chromaSubsampling: "4:4:4" })
.toBuffer(),
},
{
name: "webp",
mime: "image/webp",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.webp({ quality: 100 })
.toBuffer(),
},
] as const;
it(
"compresses common formats to jpeg under the cap",
{ timeout: 15_000 },
async () => {
const formats = [
{
name: "png",
mime: "image/png",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.png({ compressionLevel: 0 })
.toBuffer(),
},
{
name: "jpeg",
mime: "image/jpeg",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.jpeg({ quality: 100, chromaSubsampling: "4:4:4" })
.toBuffer(),
},
{
name: "webp",
mime: "image/webp",
make: (buf: Buffer, opts: { width: number; height: number }) =>
sharp(buf, {
raw: { width: opts.width, height: opts.height, channels: 3 },
})
.webp({ quality: 100 })
.toBuffer(),
},
] as const;
for (const fmt of formats) {
// Force a small cap to ensure compression is exercised for every format.