Skip to content

Instantly share code, notes, and snippets.

@griffinmyers
Created June 26, 2017 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griffinmyers/4f3719aaed297dd4fbb0d97779e6675b to your computer and use it in GitHub Desktop.
Save griffinmyers/4f3719aaed297dd4fbb0d97779e6675b to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const imageDiff = require('image-diff');
const testCases = fs.readdirSync(path.join('/', 'visual-diff', 'results'));
const expectations = fs.readdirSync(path.join(__dirname, 'expectations'));
const localBasePath = path.join('test', 'visual-diff');
const dockerBasePath = path.join('/', 'visual-diff');
const expectedExtension = '.png';
describe('expecation has result', function() {
expectations.forEach(function(expectation) {
if (expectation.endsWith(expectedExtension)) {
it(expectation, function() {
if (testCases.indexOf(expectation) === -1) {
expect('No result exists for expectation ' + expectation).toBeNull();
}
});
}
});
});
describe('result matches expectation', function() {
testCases.forEach(function(testCase) {
if (testCase.endsWith(expectedExtension)) {
const testPath = path.join(dockerBasePath, 'results', testCase);
const expectationPath = path.join(localBasePath, 'expectations', testCase);
const diffPath = path.join(dockerBasePath, 'diff', testCase);
it(testCase, function(done) {
fs.access(path.join(__dirname, 'expectations', testCase), fs.R_OK, function(err) {
if (err) {
expect('No expectation exists for ' + testCase).toBeNull();
done();
return;
}
imageDiff.getFullResult({
actualImage: testPath,
expectedImage: expectationPath,
diffImage: diffPath,
shadow: true
}, function(err, result) {
expect(err).toBeNull();
expect(result.percentage).toBeLessThan(0.01);
done();
});
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment