mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-13 15:08:39 +00:00
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:
@@ -20,18 +20,12 @@ defaults: &defaults
|
|||||||
- node_modules
|
- node_modules
|
||||||
|
|
||||||
- run:
|
- run:
|
||||||
name: Verify screenshots and generate diff
|
name: Verify screenshots and generate diffs and new screenshots
|
||||||
command: node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB --verify --diff
|
command: node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB --verify --diff --new
|
||||||
- run:
|
|
||||||
name: Generate new screenshots
|
|
||||||
when: always
|
|
||||||
command: |
|
|
||||||
rm -rf test/screenshotter/images/*
|
|
||||||
node dockers/Screenshotter/screenshotter.js --seleniumIP localhost -b $CIRCLE_JOB
|
|
||||||
|
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: test/screenshotter/images
|
path: test/screenshotter/new
|
||||||
destination: image
|
destination: new
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: test/screenshotter/diff
|
path: test/screenshotter/diff
|
||||||
destination: diff
|
destination: diff
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,12 +1,14 @@
|
|||||||
build
|
build
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
debug.log
|
||||||
last.png
|
last.png
|
||||||
diff.png
|
diff.png
|
||||||
/.npm-install.stamp
|
/.npm-install.stamp
|
||||||
/dist/
|
/dist/
|
||||||
/test/screenshotter/tex/
|
/test/screenshotter/tex/
|
||||||
/test/screenshotter/diff/
|
/test/screenshotter/diff/
|
||||||
|
/test/screenshotter/new/
|
||||||
/test/symgroups.tex
|
/test/symgroups.tex
|
||||||
/test/symgroups.aux
|
/test/symgroups.aux
|
||||||
/test/symgroups.log
|
/test/symgroups.log
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
const childProcess = require("child_process");
|
const childProcess = require("child_process");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const mkdirp = require("mkdirp");
|
||||||
const jspngopt = require("jspngopt");
|
const jspngopt = require("jspngopt");
|
||||||
const net = require("net");
|
const net = require("net");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
@@ -20,6 +21,8 @@ const dstDir = path.normalize(
|
|||||||
path.join(__dirname, "..", "..", "test", "screenshotter", "images"));
|
path.join(__dirname, "..", "..", "test", "screenshotter", "images"));
|
||||||
const diffDir = path.normalize(
|
const diffDir = path.normalize(
|
||||||
path.join(__dirname, "..", "..", "test", "screenshotter", "diff"));
|
path.join(__dirname, "..", "..", "test", "screenshotter", "diff"));
|
||||||
|
const newDir = path.normalize(
|
||||||
|
path.join(__dirname, "..", "..", "test", "screenshotter", "new"));
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Process command line arguments
|
// Process command line arguments
|
||||||
@@ -80,6 +83,10 @@ const opts = require("nomnom")
|
|||||||
flag: true,
|
flag: true,
|
||||||
help: "With `--verify`, produce image diffs when match fails",
|
help: "With `--verify`, produce image diffs when match fails",
|
||||||
})
|
})
|
||||||
|
.option("new", {
|
||||||
|
flag: true,
|
||||||
|
help: "With `--verify`, generate new screenshots when match fails",
|
||||||
|
})
|
||||||
.option("attempts", {
|
.option("attempts", {
|
||||||
help: "Retry this many times before reporting failure",
|
help: "Retry this many times before reporting failure",
|
||||||
"default": 5,
|
"default": 5,
|
||||||
@@ -448,8 +455,8 @@ function takeScreenshot(key) {
|
|||||||
console.error("FAIL! " + key);
|
console.error("FAIL! " + key);
|
||||||
listOfFailed.push(key);
|
listOfFailed.push(key);
|
||||||
exitStatus = 3;
|
exitStatus = 3;
|
||||||
if (opts.diff) {
|
if (opts.diff || opts.new) {
|
||||||
return saveScreenshotDiff(key, buf);
|
return saveFailedScreenshot(key, buf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("error " + key);
|
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 filenamePrefix = key + "-" + opts.browser;
|
||||||
|
const outputDir = opts.new ? newDir : diffDir;
|
||||||
const baseFile = path.join(dstDir, filenamePrefix + ".png");
|
const baseFile = path.join(dstDir, filenamePrefix + ".png");
|
||||||
const diffFile = path.join(diffDir, filenamePrefix + "-diff.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)
|
let promise = promisify(mkdirp, outputDir)
|
||||||
.then(null, function() { }) /* Ignore EEXIST error (XXX & others) */
|
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return promisify(fs.writeFile, bufFile, buf);
|
return promisify(fs.writeFile, bufFile, buf);
|
||||||
|
});
|
||||||
|
if (opts.diff) {
|
||||||
|
promise = promise.then(function() {
|
||||||
|
return promisify(mkdirp, diffDir);
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return execFile("convert", [
|
return execFile("convert", [
|
||||||
@@ -494,17 +505,27 @@ function takeScreenshot(key) {
|
|||||||
// corners
|
// corners
|
||||||
diffFile, // output file name
|
diffFile, // output file name
|
||||||
]);
|
]);
|
||||||
})
|
});
|
||||||
.then(function() {
|
}
|
||||||
|
if (!opts.new) {
|
||||||
|
promise = promise.then(function() {
|
||||||
return promisify(fs.unlink, bufFile);
|
return promisify(fs.unlink, bufFile);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
function oneDone() {
|
function oneDone() {
|
||||||
if (--countdown === 0) {
|
if (--countdown === 0) {
|
||||||
if (listOfFailed.length) {
|
if (listOfFailed.length) {
|
||||||
console.error("Failed: " + listOfFailed.join(" "));
|
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.
|
// devServer.close(cb) will take too long.
|
||||||
process.exit(exitStatus);
|
process.exit(exitStatus);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user