diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-05 17:11:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-06 01:11:05 +0800 |
commit | 2db1a141ab16911cf10de885a619be7b2b97b28b (patch) | |
tree | a6643ea9d00b07e5b245302a418bf487607b3fab /test | |
parent | dd30ed6a9bf108f05b103eef81d84f91ae4c6322 (diff) | |
download | tracifyjs-2db1a141ab16911cf10de885a619be7b2b97b28b.tar.gz tracifyjs-2db1a141ab16911cf10de885a619be7b2b97b28b.zip |
speed up `compress` tests (#4737)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress.js | 27 | ||||
-rw-r--r-- | 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++; |