Fix screenshotter race conditions (#1643)

* Fix screenshotter race conditions

* Update screenshotter.js

* Update screenshotter.js
This commit is contained in:
ylemkimon
2018-08-21 13:04:05 +09:00
committed by GitHub
parent 41a43974ce
commit cb89a9e5d0

View File

@@ -475,24 +475,30 @@ function takeScreenshot(key) {
const bufFile = path.join(outputDir, filenamePrefix + ".png"); const bufFile = path.join(outputDir, filenamePrefix + ".png");
let promise = fs.ensureDir(outputDir) let promise = fs.ensureDir(outputDir)
.then(fs.writeFile(bufFile, buf)); .then(function() {
return fs.writeFile(bufFile, buf);
});
if (opts.diff) { if (opts.diff) {
promise = promise.then(fs.ensureDir(diffDir)) promise = promise.then(fs.ensureDir(diffDir))
.then(execFile("convert", [ .then(function() {
"-fill", "white", return execFile("convert", [
// First image: saved screenshot in red "-fill", "white",
"(", baseFile, "-colorize", "100,0,0", ")", // First image: saved screenshot in red
// Second image: new screenshot in green "(", baseFile, "-colorize", "100,0,0", ")",
"(", bufFile, "-colorize", "0,80,0", ")", // Second image: new screenshot in green
// Composite them "(", bufFile, "-colorize", "0,80,0", ")",
"-compose", "darken", "-composite", // Composite them
"-trim", // remove everything with the same color as the "-compose", "darken", "-composite",
// corners "-trim", // remove everything with the same color as
diffFile, // output file name // the corners
])); diffFile, // output file name
]);
});
} }
if (!opts.new) { if (!opts.new) {
promise = promise.then(fs.unlink(bufFile)); promise = promise.then(function() {
return fs.unlink(bufFile);
});
} }
return promise; return promise;
} }