This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiff.js
48 lines (45 loc) · 1.66 KB
/
diff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const imgur = require('imgur');
const BlinkDiff = require('blink-diff');
const util = require('util');
imgur.setClientId(process.env.IMGUR_CLIENT_ID);
const IMAGES = Object.keys(require("./screenshotPages.json"));
Promise.all(IMAGES.map(slug => {
const diff = new BlinkDiff({
imageAPath: `screenshot-before-${slug}.png`,
imageBPath: `screenshot-after-${slug}.png`,
thresholdType: BlinkDiff.THRESHOLD_PERCENT,
threshold: 0.01, // 1% threshold
imageOutputPath: `screenshot-diff-${slug}.png`
});
return new Promise((resolve, reject) => {
diff.run((err, result) => {
if (err) {
reject(err);
} else {
console.log(diff.hasPassed(result.code) ? 'Passed' : 'Failed');
console.log('Found ' + result.differences + ' differences.');
resolve(result);
}
});
});
})).then(() => {
const urls = {};
IMAGES.forEach(slug => urls[slug] = {before: '', after: '', diff: ''});
return Promise.all(IMAGES.map(slug => {
return Promise.all(['before', 'after', 'diff'].map(type => {
return imgur.uploadFile(`screenshot-${type}-${slug}.png`)
.then(res => {
urls[slug][type] = res.data.link;
});
}));
})).then(() => {
const output = `| Type | Before | After | Diff |
|------|--------|-------|------|
${Object.keys(urls).map(type => `| ${type} | ${urls[type].before} | ${urls[type].after} | ${urls[type].diff}`).join('\n')}
`;
// TODO post to github
console.log(output);
});
}, err => {
console.error(`ERROR! ${err}`);
});