-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from happo/dynamic-drift
Apply drift for lcs algorithm dynamically (based on image height)
- Loading branch information
Showing
9 changed files
with
75 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:10 | ||
working_directory: ~/repo | ||
steps: | ||
- checkout | ||
- run: yarn install | ||
- run: yarn test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const crypto = require('crypto'); | ||
const childProcess = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const Jimp = require('jimp'); | ||
|
||
const imageDiff = require('../'); | ||
|
||
function hashFunction(data) { | ||
return crypto | ||
.createHash('md5') | ||
.update(data) | ||
.digest('hex'); | ||
} | ||
|
||
const snapshots = childProcess | ||
.execSync('ls snapshots', { encoding: 'utf-8' }) | ||
.split(/\n/) | ||
.filter(Boolean); | ||
|
||
jest.setTimeout(60000); | ||
|
||
describe('snapshot tests', () => { | ||
snapshots.forEach(snapshot => { | ||
it(snapshot, async () => { | ||
console.log('Starting', snapshot); | ||
const [image1, image2] = await Promise.all([ | ||
Jimp.read(path.resolve('snapshots', snapshot, 'before.png')), | ||
Jimp.read(path.resolve('snapshots', snapshot, 'after.png')), | ||
]); | ||
console.log('Images ready', snapshot); | ||
const diffImage = imageDiff(image1.bitmap, image2.bitmap, { | ||
hashFunction, | ||
}); | ||
|
||
console.log('Created diff image', snapshot); | ||
const pathToDiff = path.resolve('snapshots', snapshot, 'diff.png'); | ||
|
||
if (!fs.existsSync(pathToDiff)) { | ||
console.log( | ||
`No previous diff image for ${snapshot} found -- saving diff.png.`, | ||
); | ||
const newDiffImage = await new Jimp(diffImage); | ||
await newDiffImage.write(pathToDiff); | ||
} | ||
const expectedDiffImage = (await Jimp.read(pathToDiff)).bitmap; | ||
const diffHash = hashFunction(diffImage.data); | ||
const expectedHash = hashFunction(expectedDiffImage.data); | ||
if (diffHash !== expectedHash) { | ||
console.log( | ||
`Diff image did not match existing diff image. Remove this image and run again to re-generate:\n${pathToDiff}`, | ||
); | ||
} | ||
expect(diffHash).toEqual(expectedHash); | ||
}); | ||
}); | ||
}); |
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