diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-02-07 02:41:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 02:41:07 +0000 |
commit | 44499a6643e1aeec260a9b4ddbbebf4f0b3837cc (patch) | |
tree | 8babe8a6c82331ec7f452cfe6ffd291c5bc4d615 /test/mocha | |
parent | 470a7d4df186dd263d22eb1bd7c2ef220e142d16 (diff) | |
download | tracifyjs-44499a6643e1aeec260a9b4ddbbebf4f0b3837cc.tar.gz tracifyjs-44499a6643e1aeec260a9b4ddbbebf4f0b3837cc.zip |
fix corner cases in `test/reduce` (#3709)
Diffstat (limited to 'test/mocha')
-rw-r--r-- | test/mocha/reduce.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js new file mode 100644 index 00000000..99fc7947 --- /dev/null +++ b/test/mocha/reduce.js @@ -0,0 +1,60 @@ +var assert = require("assert"); +var exec = require("child_process").exec; +var reduce_test = require("../reduce"); + +describe("test/reduce.js", function() { + it("Should handle test cases with --toplevel", function() { + var result = reduce_test([ + "var Infinity = 42;", + "console.log(Infinity);", + ].join("\n"), { + toplevel: true, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "// Can't reproduce test failure with minify options provided:", + '// {"toplevel":true}', + "", + ].join("\n")); + }); + it("Should handle test result of NaN", 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}', + "", + ].join("\n")); + }); + it("Should print correct output for irreducible test case", function() { + var result = reduce_test([ + "console.log(function f(a) {", + " return f.length;", + "}());", + ].join("\n"), { + compress: { + keep_fargs: false, + }, + mangle: false, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "console.log(function f(a) {", + " return f.length;", + "}());", + "// output: 1", + "// minify: 0", + '// options: {"compress":{"keep_fargs":false},"mangle":false}', + ].join("\n")); + }); + it("Should fail when invalid option is supplied", function() { + var result = reduce_test("", { + compress: { + unsafe_regex: true, + }, + }); + var err = result.error; + assert.ok(err instanceof Error); + assert.strictEqual(err.stack.split(/\n/)[0], "DefaultsError: `unsafe_regex` is not a supported option"); + }); +}); |