import { needsProcessing, MAX_DIMENSION } from '../../src/imageProcessing'; // The whole of the skip/process policy, kept pure so the backfill's // idempotency can be reasoned about without a filesystem. The backfill is // lossy and irreversible, so being wrong here is expensive. describe('needsProcessing', () => { it('processes anything carrying EXIF, however small', () => { expect(needsProcessing({ width: 10, height: 10, exif: Buffer.from('x') })).toBe(true); }); it('processes an oversized image even with no EXIF', () => { expect(needsProcessing({ width: MAX_DIMENSION + 1, height: 100 })).toBe(true); }); it('processes an image oversized on either axis', () => { expect(needsProcessing({ width: 100, height: MAX_DIMENSION + 1 })).toBe(true); }); // The idempotency property the backfill depends on: a file already stripped // and already within bounds is left alone, so a second run cannot put it // through another lossy pass. it('leaves a stripped, in-bounds image alone', () => { expect(needsProcessing({ width: MAX_DIMENSION, height: MAX_DIMENSION })).toBe(false); }); // Unknown dimensions mean sharp could not read it as an image. Processing is // the safe answer: the alternative is skipping a file we understand least. it('processes an image whose dimensions could not be read', () => { expect(needsProcessing({})).toBe(true); }); });