Created
June 26, 2017 23:16
Revisions
-
Will Myers created this gist
Jun 26, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ 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(); }); }); }); } }); });