29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import sharp from 'sharp';
|
|
|
|
describe('Category icon normalization (sharp 128x128 pipeline)', () => {
|
|
it('produces a 128x128 PNG from a larger source', async () => {
|
|
const big = await sharp({
|
|
create: { width: 500, height: 500, channels: 3, background: { r: 100, g: 50, b: 200 } },
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
const out = await sharp(big).resize(128, 128, { fit: 'cover' }).png().toBuffer();
|
|
const meta = await sharp(out).metadata();
|
|
expect(meta.width).toBe(128);
|
|
expect(meta.height).toBe(128);
|
|
expect(meta.format).toBe('png');
|
|
});
|
|
|
|
it('produces a 128x128 PNG even when the source is smaller than 128', async () => {
|
|
const tiny = await sharp({
|
|
create: { width: 16, height: 16, channels: 3, background: { r: 0, g: 255, b: 0 } },
|
|
})
|
|
.png()
|
|
.toBuffer();
|
|
const out = await sharp(tiny).resize(128, 128, { fit: 'cover' }).png().toBuffer();
|
|
const meta = await sharp(out).metadata();
|
|
expect(meta.width).toBe(128);
|
|
expect(meta.height).toBe(128);
|
|
});
|
|
});
|