diff --git a/.circleci/config.yml b/.circleci/config.yml index a4c01892..6bb43626 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.gitignore b/.gitignore index 484c68f9..d556e39f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/dockers/Screenshotter/screenshotter.js b/dockers/Screenshotter/screenshotter.js index 5fb6dcb3..7017d57e 100644 --- a/dockers/Screenshotter/screenshotter.js +++ b/dockers/Screenshotter/screenshotter.js @@ -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,10 +505,14 @@ 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() { @@ -505,6 +520,12 @@ function takeScreenshot(key) { 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); }