james.cryer
7 years ago
13 changed files with 2428 additions and 89 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,15 @@
|
||||
FROM node:8 |
||||
|
||||
RUN apt-get update \ |
||||
&& apt-get install -qq libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++ |
||||
|
||||
RUN mkdir -p /opt/node/js \ |
||||
&& cd /opt/node \ |
||||
&& npm install canvas color-convert |
||||
|
||||
WORKDIR /opt/node/js |
||||
COPY . /opt/node/js |
||||
|
||||
RUN npm install |
||||
|
||||
CMD ["npm", "run", "test"] |
After Width: | Height: | Size: 90 KiB |
@ -0,0 +1,13 @@
|
||||
const resemble = require('../resemble'); |
||||
|
||||
module.exports = async function(image1, image2) { |
||||
return new Promise(function(resolve, reject) { |
||||
resemble(image1).compareTo(image2).onComplete(function(data) { |
||||
if (data.error) { |
||||
reject(data.error); |
||||
} else { |
||||
resolve(data); |
||||
} |
||||
}); |
||||
}); |
||||
}; |
@ -0,0 +1,33 @@
|
||||
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); |
||||
}); |
||||
|
||||
test('throws when failed', async () => { |
||||
const promise = compareImages( |
||||
fs.readFileSync('./demoassets/People.jpg'), |
||||
'bogus data' |
||||
); |
||||
await expect(promise).rejects.toMatch('Image load error.'); |
||||
}); |
||||
}); |
@ -0,0 +1,89 @@
|
||||
const resemble = require('../resemble'); |
||||
const fs = require('fs'); |
||||
|
||||
describe('resemble', () => { |
||||
test('base64', () => { |
||||
const people_src = |
||||
'data:image/jpeg;base64,' + |
||||
fs.readFileSync('./demoassets/People.jpg', 'base64'); |
||||
const people2_src = |
||||
'data:image/jpeg;base64,' + |
||||
fs.readFileSync('./demoassets/People2.jpg', 'base64'); |
||||
|
||||
return new Promise(function(resolve, reject) { |
||||
resemble(people_src).compareTo(people2_src).onComplete(function(data) { |
||||
// console.info('Reached oncomplete for base64_string');
|
||||
expect(data.diffBounds.bottom).toEqual(431); |
||||
expect(data.diffBounds.left).toEqual(22); |
||||
expect(data.diffBounds.right).toEqual(450); |
||||
expect(data.diffBounds.top).toEqual(58); |
||||
expect(data.dimensionDifference.height).toEqual(0); |
||||
expect(data.dimensionDifference.width).toEqual(0); |
||||
expect(data.isSameDimensions).toBe(true); |
||||
expect(data.misMatchPercentage).toEqual('8.66'); |
||||
resolve(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
test('files', () => { |
||||
return new Promise(function(resolve, reject) { |
||||
resemble('./demoassets/People.jpg') |
||||
.compareTo('./demoassets/People2.jpg') |
||||
.onComplete(function(data) { |
||||
// console.info('Reached oncomplete for request_success');
|
||||
expect(data.diffBounds).toEqual( |
||||
expect.objectContaining({ |
||||
bottom: expect.any(Number), |
||||
left: expect.any(Number), |
||||
top: expect.any(Number), |
||||
right: expect.any(Number) |
||||
}) |
||||
); |
||||
|
||||
expect(data.diffBounds.bottom).toEqual(431); |
||||
expect(data.diffBounds.left).toEqual(22); |
||||
expect(data.diffBounds.right).toEqual(450); |
||||
expect(data.diffBounds.top).toEqual(58); |
||||
expect(data.dimensionDifference.height).toEqual(0); |
||||
expect(data.dimensionDifference.width).toEqual(0); |
||||
expect(data.isSameDimensions).toBe(true); |
||||
expect(data.misMatchPercentage).toEqual('8.66'); |
||||
resolve(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
test('file not found', () => { |
||||
return new Promise(function(resolve, reject) { |
||||
resemble('../demoassets/People.jpg') |
||||
.compareTo('../demoassets/404-image.jpg') |
||||
.onComplete(function(data) { |
||||
// console.info('Reached oncomplete for request_404');
|
||||
// console.log(data);
|
||||
expect(data.error).toEqual('Image load error.'); |
||||
resolve(); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
test('node buffers', () => { |
||||
const people = fs.readFileSync('./demoassets/People.jpg'); |
||||
const people2 = fs.readFileSync('./demoassets/People2.jpg'); |
||||
|
||||
return new Promise(function(resolve, reject) { |
||||
resemble(people).compareTo(people2).onComplete(function(data) { |
||||
// console.info('Reached oncomplete for base64_string');
|
||||
expect(data.diffBounds.bottom).toEqual(431); |
||||
expect(data.diffBounds.left).toEqual(22); |
||||
expect(data.diffBounds.right).toEqual(450); |
||||
expect(data.diffBounds.top).toEqual(58); |
||||
expect(data.dimensionDifference.height).toEqual(0); |
||||
expect(data.dimensionDifference.width).toEqual(0); |
||||
expect(data.isSameDimensions).toBe(true); |
||||
expect(data.misMatchPercentage).toEqual('8.66'); |
||||
resolve(); |
||||
}); |
||||
}); |
||||
}); |
||||
}); |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue