-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7395 from cjcenizal/feature/compare-screenshots-u…
…tility Add screenshot-comparison utility, to protect against visual regressions during CSS refactors.
- Loading branch information
Showing
12 changed files
with
74 additions
and
24 deletions.
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 characters
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 characters
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 characters
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const imageDiff = require('image-diff'); | ||
const mkdirp = require('mkdirp'); | ||
|
||
function compareScreenshots() { | ||
const SCREENSHOTS_DIR = 'test/screenshots'; | ||
const BASELINE_SCREENSHOTS_DIR = path.resolve(SCREENSHOTS_DIR, 'baseline'); | ||
const DIFF_SCREENSHOTS_DIR = path.resolve(SCREENSHOTS_DIR, 'diff'); | ||
const SESSION_SCREENSHOTS_DIR = path.resolve(SCREENSHOTS_DIR, 'session'); | ||
|
||
// We don't need to create the baseline dir because it's committed. | ||
mkdirp.sync(DIFF_SCREENSHOTS_DIR); | ||
mkdirp.sync(SESSION_SCREENSHOTS_DIR); | ||
|
||
fs.readdir(SESSION_SCREENSHOTS_DIR, (readDirError, files) => { | ||
const screenshots = files.filter(file => file.indexOf('.png') !== -1); | ||
|
||
screenshots.forEach(screenshot => { | ||
const sessionImagePath = path.resolve(SESSION_SCREENSHOTS_DIR, screenshot); | ||
const baselineImagePath = path.resolve(BASELINE_SCREENSHOTS_DIR, screenshot); | ||
const diffImagePath = path.resolve(DIFF_SCREENSHOTS_DIR, screenshot); | ||
|
||
imageDiff.getFullResult({ | ||
actualImage: sessionImagePath, | ||
expectedImage: baselineImagePath, | ||
diffImage: diffImagePath, | ||
shadow: true, | ||
}, (comparisonError, result) => { | ||
if (comparisonError) { | ||
throw comparisonError; | ||
} | ||
|
||
const change = result.percentage; | ||
const changePercentage = (change * 100).toFixed(2); | ||
console.log(`${screenshot} has changed by ${changePercentage}%`); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
compareScreenshots(); |