Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. const fs = require('fs');
  2. const path = require('path');
  3.  
  4. const imageDiff = require('image-diff');
  5.  
  6. const testCases = fs.readdirSync(path.join('/', 'visual-diff', 'results'));
  7. const expectations = fs.readdirSync(path.join(__dirname, 'expectations'));
  8.  
  9. const localBasePath = path.join('test', 'visual-diff');
  10. const dockerBasePath = path.join('/', 'visual-diff');
  11.  
  12. const expectedExtension = '.png';
  13.  
  14. describe('expecation has result', function() {
  15.  
  16. expectations.forEach(function(expectation) {
  17. if (expectation.endsWith(expectedExtension)) {
  18. it(expectation, function() {
  19. if (testCases.indexOf(expectation) === -1) {
  20. expect('No result exists for expectation ' + expectation).toBeNull();
  21. }
  22. });
  23. }
  24. });
  25.  
  26. });
  27.  
  28. describe('result matches expectation', function() {
  29.  
  30. testCases.forEach(function(testCase) {
  31. if (testCase.endsWith(expectedExtension)) {
  32. const testPath = path.join(dockerBasePath, 'results', testCase);
  33. const expectationPath = path.join(localBasePath, 'expectations', testCase);
  34. const diffPath = path.join(dockerBasePath, 'diff', testCase);
  35.  
  36. it(testCase, function(done) {
  37. fs.access(path.join(__dirname, 'expectations', testCase), fs.R_OK, function(err) {
  38. if (err) {
  39. expect('No expectation exists for ' + testCase).toBeNull();
  40. done();
  41. return;
  42. }
  43.  
  44. imageDiff.getFullResult({
  45. actualImage: testPath,
  46. expectedImage: expectationPath,
  47. diffImage: diffPath,
  48. shadow: true
  49. }, function(err, result) {
  50. expect(err).toBeNull();
  51. expect(result.percentage).toBeLessThan(0.01);
  52. done();
  53. });
  54. });
  55.  
  56. });
  57. }
  58. });
  59.  
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement