Add regenerate option to the screenshotter (#1220)

* Add regenerate option to the screenshotter

Save new screenshot when match fails

* Ignore Chrome debug log file

* CircleCI: Generate only failed screenshots

* CircleCI Test

* Revert "CircleCI Test"

This reverts commit 5d3afb2602f32470eeba7767748faba177ba933e.

* Rename `regenerate` to `new`

* Add ` /test/screenshotter/new/` to .gitignore
This commit is contained in:
ylemkimon
2018-05-21 21:06:50 +09:00
committed by Erik Demaine
parent 34cf5c2f81
commit 74e84e72d2
3 changed files with 35 additions and 18 deletions

View File

@@ -20,18 +20,12 @@ defaults: &defaults
- node_modules
- run:
name: Verify screenshots and generate diff
command: node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB --verify --diff
- run:
name: Generate new screenshots
when: always
command: |
rm -rf test/screenshotter/images/*
node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB
name: Verify screenshots and generate diffs and new screenshots
command: node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB --verify --diff --new
- store_artifacts:
path: test/screenshotter/images
destination: image
path: test/screenshotter/new
destination: new
- store_artifacts:
path: test/screenshotter/diff
destination: diff

2
.gitignore vendored
View File

@@ -1,12 +1,14 @@
build
node_modules
npm-debug.log
debug.log
last.png
diff.png
/.npm-install.stamp
/dist/
/test/screenshotter/tex/
/test/screenshotter/diff/
/test/screenshotter/new/
/test/symgroups.tex
/test/symgroups.aux
/test/symgroups.log

View File

@@ -3,6 +3,7 @@
const childProcess = require("child_process");
const fs = require("fs");
const mkdirp = require("mkdirp");
const jspngopt = require("jspngopt");
const net = require("net");
const os = require("os");
@@ -20,6 +21,8 @@ const dstDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "images"));
const diffDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "diff"));
const newDir = path.normalize(
path.join(__dirname, "..", "..", "test", "screenshotter", "new"));
//////////////////////////////////////////////////////////////////////
// Process command line arguments
@@ -80,6 +83,10 @@ const opts = require("nomnom")
flag: true,
help: "With `--verify`, produce image diffs when match fails",
})
.option("new", {
flag: true,
help: "With `--verify`, generate new screenshots when match fails",
})
.option("attempts", {
help: "Retry this many times before reporting failure",
"default": 5,
@@ -448,8 +455,8 @@ function takeScreenshot(key) {
console.error("FAIL! " + key);
listOfFailed.push(key);
exitStatus = 3;
if (opts.diff) {
return saveScreenshotDiff(key, buf);
if (opts.diff || opts.new) {
return saveFailedScreenshot(key, buf);
}
} else {
console.log("error " + key);
@@ -470,16 +477,20 @@ function takeScreenshot(key) {
}
}
function saveScreenshotDiff(key, buf) {
function saveFailedScreenshot(key, buf) {
const filenamePrefix = key + "-" + opts.browser;
const outputDir = opts.new ? newDir : diffDir;
const baseFile = path.join(dstDir, filenamePrefix + ".png");
const diffFile = path.join(diffDir, filenamePrefix + "-diff.png");
const bufFile = path.join(diffDir, filenamePrefix + "-fail.png");
const bufFile = path.join(outputDir, filenamePrefix + ".png");
return promisify(fs.mkdir, diffDir)
.then(null, function() { }) /* Ignore EEXIST error (XXX & others) */
let promise = promisify(mkdirp, outputDir)
.then(function() {
return promisify(fs.writeFile, bufFile, buf);
});
if (opts.diff) {
promise = promise.then(function() {
return promisify(mkdirp, diffDir);
})
.then(function() {
return execFile("convert", [
@@ -494,17 +505,27 @@ function takeScreenshot(key) {
// corners
diffFile, // output file name
]);
})
.then(function() {
});
}
if (!opts.new) {
promise = promise.then(function() {
return promisify(fs.unlink, bufFile);
});
}
return promise;
}
function oneDone() {
if (--countdown === 0) {
if (listOfFailed.length) {
console.error("Failed: " + listOfFailed.join(" "));
}
if (opts.diff) {
console.log("Diffs have been generated in: " + diffDir);
}
if (opts.new) {
console.log("New screenshots have been generated in: " + newDir);
}
// devServer.close(cb) will take too long.
process.exit(exitStatus);
}