diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-02-14 02:47:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-14 02:47:20 +0000 |
commit | f01f580d6c2312ba556a37144f6fef227bd89f77 (patch) | |
tree | 5233c2783b3c0a927bfb3dd4a10afd786df13641 /test/mocha/reduce.js | |
parent | c01ff7628868a14338aa1193da2ada011c7ad832 (diff) | |
download | tracifyjs-f01f580d6c2312ba556a37144f6fef227bd89f77.tar.gz tracifyjs-f01f580d6c2312ba556a37144f6fef227bd89f77.zip |
improve `--reduce-test` (#3719)
- cover missing cases when eliminating unreferenced labels
- format multi-line outputs correctly
Diffstat (limited to 'test/mocha/reduce.js')
-rw-r--r-- | test/mocha/reduce.js | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js index 0e21666c..f55c278d 100644 --- a/test/mocha/reduce.js +++ b/test/mocha/reduce.js @@ -8,9 +8,9 @@ function read(path) { } describe("test/reduce.js", function() { + this.timeout(60000); it("Should reduce test case", function() { - this.timeout(60000); - var result = reduce_test(read("test/input/reduce/input.js"), { + var result = reduce_test(read("test/input/reduce/unsafe_math.js"), { compress: { unsafe_math: true, }, @@ -19,7 +19,16 @@ describe("test/reduce.js", function() { verbose: false, }); if (result.error) throw result.error; - assert.strictEqual(result.code, read("test/input/reduce/output.js")); + assert.strictEqual(result.code, read("test/input/reduce/unsafe_math.reduced.js")); + }); + it("Should eliminate unreferenced labels", function() { + var result = reduce_test(read("test/input/reduce/label.js"), { + mangle: false, + }, { + verbose: false, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, read("test/input/reduce/label.reduced.js")); }); it("Should handle test cases with --toplevel", function() { var result = reduce_test([ @@ -31,7 +40,9 @@ describe("test/reduce.js", function() { if (result.error) throw result.error; assert.strictEqual(result.code, [ "// Can't reproduce test failure with minify options provided:", - '// {"toplevel":true}', + "// {", + '// "toplevel": true', + "// }", "", ].join("\n")); }); @@ -40,7 +51,10 @@ describe("test/reduce.js", function() { if (result.error) throw result.error; assert.strictEqual(result.code, [ "// Can't reproduce test failure with minify options provided:", - '// {"compress":{},"mangle":false}', + "// {", + '// "compress": {},', + '// "mangle": false', + "// }", "", ].join("\n")); }); @@ -61,8 +75,15 @@ describe("test/reduce.js", function() { " return f.length;", "}());", "// output: 1", + "// ", "// minify: 0", - '// options: {"compress":{"keep_fargs":false},"mangle":false}', + "// ", + "// options: {", + '// "compress": {', + '// "keep_fargs": false', + "// },", + '// "mangle": false', + "// }", ].join("\n")); }); it("Should fail when invalid option is supplied", function() { @@ -81,4 +102,38 @@ describe("test/reduce.js", function() { assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Name expected"); }); + it("Should format multi-line output correctly", function() { + var code = [ + "var a = 0;", + "", + "for (var b in [ 1, 2, 3 ]) {", + " a = +a + 1 - .2;", + " console.log(a);", + "}", + ].join("\n"); + var result = reduce_test(code, { + compress: { + unsafe_math: true, + }, + mangle: false, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + code, + "// output: 0.8", + "// 1.6", + "// 2.4", + "// ", + "// minify: 0.8", + "// 1.6", + "// 2.4000000000000004", + "// ", + "// options: {", + '// "compress": {', + '// "unsafe_math": true', + "// },", + '// "mangle": false', + "// }", + ].join("\n")); + }); }); |