From: Alex Lam S.L Date: Tue, 7 Mar 2017 11:25:12 +0000 (+0800) Subject: include benchmark.js in test suite (#1564) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=65c848cc6f13cb5ae3bc1c0fb5fbb320ed2d0200;p=UglifyJS.git include benchmark.js in test suite (#1564) - report file sizes and overall run time - exit with non-zero code upon error --- diff --git a/test/benchmark.js b/test/benchmark.js index dc176a88..c150e5cf 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -24,26 +24,57 @@ var results = {}; var remaining = 2 * urls.length; function done() { if (!--remaining) { + var failures = []; urls.forEach(function(url) { + var info = results[url]; console.log(); console.log(url); - console.log(results[url].time); - console.log("SHA1:", results[url].sha1); + console.log(info.log); + var elapsed = 0; + info.log.replace(/: ([0-9]+\.[0-9]{3})s/g, function(match, time) { + elapsed += parseFloat(time); + }); + console.log("Run-time:", elapsed.toFixed(3), "s"); + console.log("Original:", info.input, "bytes"); + console.log("Uglified:", info.output, "bytes"); + console.log("SHA1 sum:", info.sha1); + if (info.code) { + failures.push(url); + } }); + if (failures.length) { + console.error("Benchmark failed:"); + failures.forEach(function(url) { + console.error(url); + }); + process.exit(1); + } } } urls.forEach(function(url) { - results[url] = { time: "" }; + results[url] = { + input: 0, + output: 0, + log: "" + }; require(url.slice(0, url.indexOf(":"))).get(url, function(res) { var uglifyjs = fork("bin/uglifyjs", args, { silent: true }); - res.pipe(uglifyjs.stdin); - uglifyjs.stdout.pipe(createHash("sha1")).on("data", function(data) { + res.on("data", function(data) { + results[url].input += data.length; + }).pipe(uglifyjs.stdin); + uglifyjs.stdout.on("data", function(data) { + results[url].output += data.length; + }).pipe(createHash("sha1")).on("data", function(data) { results[url].sha1 = data.toString("hex"); done(); }); uglifyjs.stderr.setEncoding("utf8"); uglifyjs.stderr.on("data", function(data) { - results[url].time += data; - }).on("end", done) + results[url].log += data; + }); + uglifyjs.on("exit", function(code) { + results[url].code = code; + done(); + }); }); }); diff --git a/test/mocha/benchmark.js b/test/mocha/benchmark.js new file mode 100644 index 00000000..c2c7c02c --- /dev/null +++ b/test/mocha/benchmark.js @@ -0,0 +1,24 @@ +var assert = require("assert"); +var exec = require("child_process").exec; + +describe("test/benchmark.js", function() { + this.timeout(120000); + var command = '"' + process.argv[0] + '" test/benchmark.js '; + [ + "-b", + "-b bracketize", + "-m", + "-mc passes=3", + "-mc passes=3,toplevel", + "-mc passes=3,unsafe", + "-mc keep_fargs=false,passes=3", + "-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto", + ].forEach(function(args) { + it("Should pass with options " + args, function(done) { + exec(command + args, function(err) { + if (err) throw err; + done(); + }); + }); + }); +});