From 2db1a141ab16911cf10de885a619be7b2b97b28b Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 5 Mar 2021 17:11:05 +0000 Subject: [PATCH] speed up `compress` tests (#4737) --- test/compress.js | 27 ++++++++++++++++----------- test/reduce.js | 13 ++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/test/compress.js b/test/compress.js index b4dbaba6..8531d6ad 100644 --- a/test/compress.js +++ b/test/compress.js @@ -10,33 +10,38 @@ var sandbox = require("./sandbox"); var semver = require("semver"); var U = require("./node"); -var file = process.argv[2]; +var batch = 50; var dir = path.resolve(path.dirname(module.filename), "compress"); -if (file) { +if (process.argv.length > 3) { + var file = process.argv[2]; + var start = process.argv[3] | 0; var minify_options = require("./ufuzz/options.json").map(JSON.stringify); - log("--- {file}", { file: file }); var tests = parse_test(path.resolve(dir, file)); - process.exit(Object.keys(tests).filter(function(name) { + process.exit(Object.keys(tests).slice(start, start + batch).filter(function(name) { return !test_case(tests[name]); }).length); } else { - var files = fs.readdirSync(dir).filter(function(name) { + var files = process.argv.length == 3 ? [ process.argv[2] ] : fs.readdirSync(dir).filter(function(name) { return /\.js$/i.test(name); }); var failures = 0; var failed_files = Object.create(null); - (function next() { - var file = files.shift(); - if (file) { - child_process.spawn(process.argv[0], [ process.argv[1], file ], { + (function next(file, start, length) { + if (start < length) { + child_process.spawn(process.argv[0], [ process.argv[1], file, start, batch ], { stdio: [ "ignore", 1, 2 ] }).on("exit", function(code) { if (code) { failures += code; - failed_files[file] = code; + failed_files[file] = true; } - next(); + next(file, start + batch, length); }); + } else if (file = files.shift()) { + log("--- {file}", { file: file }); + start = 0; + length = Object.keys(parse_test(path.resolve(dir, file))).length; + next(file, start, length); } else if (failures) { console.error(); console.error("!!! Failed " + failures + " test case(s)."); diff --git a/test/reduce.js b/test/reduce.js index b7f5c030..6f413789 100644 --- a/test/reduce.js +++ b/test/reduce.js @@ -137,6 +137,12 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) if (parent instanceof U.AST_ExportDefault) return; if (parent instanceof U.AST_ExportForeign) return; if (parent instanceof U.AST_ExportReferences) return; + // preserve sole definition of an export statement + if (node instanceof U.AST_VarDef + && parent.definitions.length == 1 + && tt.parent(1) instanceof U.AST_ExportDeclaration) { + return; + } // preserve for (var xxx; ...) if (parent instanceof U.AST_For && parent.init === node && node instanceof U.AST_Definitions) return node; // preserve for (xxx in/of ...) @@ -460,13 +466,6 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options) return List.skip; } - // preserve sole definition of an export statement - if (node instanceof U.AST_VarDef - && parent.definitions.length == 1 - && tt.parent(1) instanceof U.AST_ExportDeclaration) { - return node; - } - // remove this node unless its the sole element of a (transient) sequence if (!(parent instanceof U.AST_Sequence) || parent.expressions.length > 1) { node.start._permute++; -- 2.34.1