forked from atomiks/tippyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-reporter.js
50 lines (43 loc) · 1.19 KB
/
image-reporter.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
49
50
const {red, bold} = require('colorette');
const fs = require('fs');
const poster = require('poster');
// https://api.anonymousfiles.io/
class ImageReporter {
constructor(globalConfig, options) {
this._globalConfig = globalConfig;
this._options = options;
}
onTestResult(test, testResult, aggregateResults) {
if (process.env.CI !== 'true') {
return;
}
if (
testResult.numFailingTests &&
testResult.failureMessage.match(/different from snapshot/)
) {
const files = fs.readdirSync(
'./test/functional/__image_snapshots__/__diff_output__/'
);
files.forEach(async (value) => {
const file = `./test/functional/__image_snapshots__/__diff_output__/${value}`;
poster.post(
file,
{
uploadUrl: 'https://api.anonymousfiles.io/',
fileId: 'file',
fileContentType: 'image/png',
},
(err, data) => {
if (err) {
throw err;
}
console.log(
red(bold(`Uploaded image diff file to ${JSON.parse(data).url}`))
);
}
);
});
}
}
}
module.exports = ImageReporter;