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