Picture analyzer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
1.1 KiB

const compareImages = require('../compareImages');
const fs = require('fs');
describe('compareImages', () => {
test('works with buffers', async () => {
const data = await compareImages(
fs.readFileSync('./demoassets/People.jpg'),
fs.readFileSync('./demoassets/People2.jpg')
);
expect(data.isSameDimensions).toBe(true);
expect(data.misMatchPercentage).toEqual('8.66');
const buffer = data.getBuffer();
expect(buffer).toBeInstanceOf(Buffer);
expect(buffer.length).toBe(91876);
const comparison = fs.readFileSync(
'./nodejs-tests/PeopleComparedToPeople2.png'
);
expect(buffer.equals(comparison)).toBe(true);
const buffer2 = data.getBuffer(true);
const comparison2 = fs.readFileSync(
'./nodejs-tests/PeopleComparedToPeople2WithOriginal.png'
);
expect(buffer2.equals(comparison2)).toBe(true);
});
test('throws when failed', async () => {
const promise = compareImages(
fs.readFileSync('./demoassets/People.jpg'),
'bogus data'
);
await expect(promise).rejects.toMatch('Image load error.');
});
});