aboutsummaryrefslogtreecommitdiff
path: root/test/mocha/reduce.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-02-17 15:35:07 +0000
committerGitHub <noreply@github.com>2020-02-17 15:35:07 +0000
commit53517db3e40e9a2b2a6cc64b0dd7dcef0305ec1e (patch)
tree1e9e4cc8aa519f8a569b1628dee6924393dd6814 /test/mocha/reduce.js
parentc13caf487614d15cdc7d984fc5b4c558e728f0cf (diff)
downloadtracifyjs-53517db3e40e9a2b2a6cc64b0dd7dcef0305ec1e.tar.gz
tracifyjs-53517db3e40e9a2b2a6cc64b0dd7dcef0305ec1e.zip
speed up `--reduce-test` (#3726)
- avoid pathological test case branches via adaptive time-out - use initial test case elapsed time to adjust maximum time-out - index output cache using hash instead of raw source
Diffstat (limited to 'test/mocha/reduce.js')
-rw-r--r--test/mocha/reduce.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index f55c278d..c7d5a7de 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -2,6 +2,7 @@ var assert = require("assert");
var exec = require("child_process").exec;
var fs = require("fs");
var reduce_test = require("../reduce");
+var semver = require("semver");
function read(path) {
return fs.readFileSync(path, "utf8");
@@ -43,7 +44,6 @@ describe("test/reduce.js", function() {
"// {",
'// "toplevel": true',
"// }",
- "",
].join("\n"));
});
it("Should handle test result of NaN", function() {
@@ -55,7 +55,6 @@ describe("test/reduce.js", function() {
'// "compress": {},',
'// "mangle": false',
"// }",
- "",
].join("\n"));
});
it("Should print correct output for irreducible test case", function() {
@@ -136,4 +135,33 @@ describe("test/reduce.js", function() {
"// }",
].join("\n"));
});
+ it("Should reduce infinite loops with reasonable performance", function() {
+ if (semver.satisfies(process.version, "0.10")) return;
+ this.timeout(120000);
+ var code = [
+ "var a = 9007199254740992, b = 1;",
+ "",
+ "while (a++ + (1 - b) < a) {",
+ " 0;",
+ "}",
+ ].join("\n");
+ var result = reduce_test(code, {
+ compress: {
+ unsafe_math: true,
+ },
+ mangle: false,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code.replace(/ timed out after [0-9]+ms/, " timed out."), [
+ code,
+ "// output: ",
+ "// minify: Error: Script execution timed out.",
+ "// options: {",
+ '// "compress": {',
+ '// "unsafe_math": true',
+ "// },",
+ '// "mangle": false',
+ "// }",
+ ].join("\n"));
+ });
});