diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-03-20 21:50:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-21 05:50:41 +0800 |
commit | ff72eaa3c3e0d93cc4f5b111ede223e1a0ebef48 (patch) | |
tree | b31cd84203773b700069d45d83ec1ffd6b101640 /test/mocha/reduce.js | |
parent | 0a1c9b34cea8bf740c70d5457ef9e3bd37778607 (diff) | |
download | tracifyjs-ff72eaa3c3e0d93cc4f5b111ede223e1a0ebef48.tar.gz tracifyjs-ff72eaa3c3e0d93cc4f5b111ede223e1a0ebef48.zip |
improve `--reduce-test` (#3742)
- ignore difference in error messages
- improve readability on trailing whitespace differences
- improve performance & quality via `console.log()` insertions
Diffstat (limited to 'test/mocha/reduce.js')
-rw-r--r-- | test/mocha/reduce.js | 69 |
1 files changed, 50 insertions, 19 deletions
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js index a8ab67b3..fb3989dc 100644 --- a/test/mocha/reduce.js +++ b/test/mocha/reduce.js @@ -53,8 +53,8 @@ describe("test/reduce.js", function() { }); if (result.error) throw result.error; assert.strictEqual(result.code, [ - "// Can't reproduce test failure with minify options provided:", - "// {", + "// Can't reproduce test failure", + "// minify options: {", '// "toplevel": true', "// }", ].join("\n")); @@ -70,8 +70,8 @@ describe("test/reduce.js", function() { }); if (result.error) throw result.error; assert.strictEqual(result.code, [ - "// Can't reproduce test failure with minify options provided:", - "// {", + "// Can't reproduce test failure", + "// minify options: {", '// "compress": {', '// "toplevel": true', "// }", @@ -89,8 +89,8 @@ describe("test/reduce.js", function() { }); if (result.error) throw result.error; assert.strictEqual(result.code, [ - "// Can't reproduce test failure with minify options provided:", - "// {", + "// Can't reproduce test failure", + "// minify options: {", '// "mangle": {', '// "toplevel": true', "// }", @@ -101,11 +101,8 @@ describe("test/reduce.js", function() { var result = reduce_test("throw 0 / 0;"); if (result.error) throw result.error; assert.strictEqual(result.code, [ - "// Can't reproduce test failure with minify options provided:", - "// {", - '// "compress": {},', - '// "mangle": false', - "// }", + "// Can't reproduce test failure", + "// minify options: {}", ].join("\n")); }); it("Should print correct output for irreducible test case", function() { @@ -121,6 +118,7 @@ describe("test/reduce.js", function() { }); if (result.error) throw result.error; assert.strictEqual(result.code, [ + "// (beautified)", "console.log(function f(a) {", " return f.length;", "}());", @@ -169,6 +167,7 @@ describe("test/reduce.js", function() { }); if (result.error) throw result.error; assert.strictEqual(result.code, [ + "// (beautified)", code, "// output: 0.8", "// 1.6", @@ -189,11 +188,41 @@ describe("test/reduce.js", function() { it("Should reduce infinite loops with reasonable performance", function() { if (semver.satisfies(process.version, "0.10")) return; this.timeout(120000); + var result = reduce_test("while (/9/.test(1 - .8));", { + 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."), [ + "// (beautified)", + "while (/9/.test(1 - .8)) {}", + "// output: Error: Script execution timed out.", + "// minify: ", + "// options: {", + '// "compress": {', + '// "unsafe_math": true', + "// },", + '// "mangle": false', + "// }", + ].join("\n")); + }); + it("Should ignore difference in Error.message", function() { + var result = reduce_test("null[function() {\n}];"); + if (result.error) throw result.error; + assert.strictEqual(result.code, (semver.satisfies(process.version, "0.10") ? [ + "// Can't reproduce test failure", + "// minify options: {}", + ] : [ + "// No differences except in error message", + "// minify options: {}", + ]).join("\n")); + }); + it("Should report trailing whitespace difference in stringified format", function() { var code = [ - "var a = 9007199254740992, b = 1;", - "", - "while (a++ + (1 - b) < a) {", - " 0;", + "for (var a in (1 - .8).toString()) {", + " console.log();", "}", ].join("\n"); var result = reduce_test(code, { @@ -203,14 +232,16 @@ describe("test/reduce.js", function() { mangle: false, }); if (result.error) throw result.error; - assert.strictEqual(result.code.replace(/ timed out after [0-9]+ms/, " timed out."), [ + assert.strictEqual(result.code, [ + "// (beautified)", code, - "// output: ", - "// minify: Error: Script execution timed out.", + "// (stringified)", + '// output: "\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n"', + '// minify: "\\n\\n\\n"', "// options: {", '// "compress": {', '// "unsafe_math": true', - "// },", + '// },', '// "mangle": false', "// }", ].join("\n")); |